Android Rooted phone give write access to Android/data - android

I am just trying to build a basic app that can write to any file on the phone.
The Galaxy I am using is rooted.
I gave full super user rights with Super-utilisateur app. I am trying using Runtime.getRuntime().exec(su -c touch /data/user/0/com.XXXX/test
But it's not working.
When I do the exact same command in adb shell with the superuser right it does work.
How can I make my very simple app write to any directories on my android phone?
Just to be clear I do not intend to upload that app in the play store, it's just for testing purposes.
The end goal is to write a execute as su a small sh script written in /sdcard/ that moves files around for testing.
Thank you
I was expecting my bash script to run as root with su -c sh /sdcard/test.sh

Related

Can I start an executable in an approved application?

I've noticed that it is possible on Android to change the permissions on a file with chmod, which means we can easily execute anything from an application:
var runtime = Runtime.GetRuntime();
runtime.Exec("chmod 0755 /my/file").WaitFor();
// Then ProcessBuilder to execute it.
Would Google Play Store accept an application that takes advantage of this flaw? I can't find any documentation about it, but I confirm that it works.
Actually, I want to include ffmpeg for tasks that are too slow to be executed using MediaCodec.
(I've also noticed that the Android framework sometimes directly access to a native version of ffmpeg, so maybe I could access it directly from the phone?)
I don't know for sure if it is ok for Google Play.
However i don't think it is security issue. You will exec process with the autorisation of your app.
I hope the following example will help you.
You can try the following command line with your device connect.
adb shell
To have a shell on your devices
Then you can try to look what is inside the files for an app (replace com.your.package by the name of a debbugable apk)
ls /data/data/com.your.package
This command will failde because you have not the good permission.
Now run the following command.
run-as com.your.package
You will now exec your command line with the same permission as your app.
You can now retry the previous ls command. It will work. However it will not work for another package.
So, i think the command you will exec with your code, will be exec with the privilege of your app. So i don't think you can elevate the privilege of you app on a file with this method.

Running su on Android root

Hi so my application runs some commands using the su in android root.
It works fine in JellyBean on the Galaxy Nexus but when I try to run it on the LG Nexus 5 (kitkat), I get an error saying:
su: uid 10069 not allowed to su
I'm not really sure what I'm missing here. I have root access (it runs su fine on the Galaxy Nexus).
Basically the application reads in a command from a TextEdit, strips it, appends the necessary parameters etc. and then calls the script which is put on the phone. I use the ProcessBuilder to build the call for the script.
Any fixes or ideas as to where I should look would be appreciated. Thank you
The issue was SuperSu not being properly installed and granting permission to the application. Once I changed that there were no permissions issues.
If you have problem with rooting to super user.
You can use "run-as" command to access files of your application.
ex: run-as com.your.package
It will drop you to the shell#android:/data/data/com.your.package $
now you can use commands ls
Then it will display the list of file folders
cache
databases
lib
shared_prefs

Run adb pull and push command from inside an application programmatically

I am developing an application in which I have to put as well as get some files from Computer(i.e Windows system) using USB.
I searched the web but didn't get anything helpful. I have an idea about command line so I am able to do this by using commands like
./adb -s emulator-5554 pull /sdcard/juned.jpg c:/user/juned/images/
It will copy juned.jpg file in specified directory of system, but is it possible to run same command programmatically ?
Till now I got one sample application in Android Samples named AdbTest which is available under /root/android-sdks/samples/android-18/legacy/USB/ directory, I have tried to compile that application but it shows nothing.
In that application under xml directory device_filter.xml file is there. In that file
<resources>
<usb-device class="255" subclass="66" protocol="1" />
</resources>
What value should I provide to make it working with my device ?
And is it possible to run adb commands from indide an application programmatically?
Edit
So far I came to know that, adb command can not be executed in non rooted devices, so is there any other way to transfer files using USB ?
Its not possible for Devices which are not rooted
Since to run your command it requires Su permission (Super User) .
Your command will be system/bin/ Su / -command
non rooted device don't have access to system/bin/ Su
you can root your emulator by Installing Superuser.apk
or try How to get root access on Android emulator?

run-as command in android

I am currently developing directly on my device using an ide app called AIDE. But after creating a DB I can't access it to check my data/app are working correctly.
I have managed to get run-as to work using adb with my phone plugged into my laptop, but I'd really like it to work straight off the phone so I can code, test and debug, all whilst on the move.
Using connectbot I can see the run-as command in system/bin/ but it has no executable access.
Any ideas?

How to move apps to sdcard via shell script

I want to write a small tool to move apps to SDcard.
I found the movePackage()-method in Android Open Source and reflect the method. I failed because this method need com.android.PERMISSION.MOVE_PACKAGE which I cannot get. So I want to using shell script to do this for rooted devices.
But I don't actually know what happened in the movePackage()-method. So I can't write the correct script.
Could you please tell what happened inside the Android when a app is moved to SDcard? Can I do this with program?
I'm not sure If I understand you, but on rooted device you can use adb.
For example:
adb push /home/username/Desktop/app.apk /sdcard/app.apk
Also you can do this (for removing):
adb shell rm /sdcard/app.apk
If you want to install:
adb install /home/username/Desktop/app.apk

Categories

Resources