Modifying other app's database with root in Android - android

How can I read and modify the database of an app that I don't own with root.
I tried copying the file to my app's location like this:
try {
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("su -c cat /data/user/0/com.maxmpz.audioplayer/databases/folders.db > /data/user/0/com.example.me.myapp/folders.db");
} catch (IOException e) {
e.printStackTrace();
}
and:
try {
Runtime.getRuntime().exec("su");
Process p = Runtime.getRuntime().exec("su cp /data/user/0/com.maxmpz.audioplayer/databases/folders.db /data/user/0/com.example.me.myapp/folders.db");
} catch (IOException e) {
e.printStackTrace();
}
But nothing happens (the exception isn't raised).

Related

Android super user access in app to run commands

I want to run tap cmd like over 100 times and by using code below it will call su everytime and delay taps. So is it possible to request su when app first starts then run many commands fast? thanks!
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
String cmd = "/system/bin/input tap 350 370\n";
os.writeBytes(cmd);
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
}
This is the solution:
try {
Process process = Runtime.getRuntime().exec("su");
OutputStream out = process.getOutputStream();
String cmd = "input tap 350 370";
out.write(cmd.getBytes());
out.flush();
out.close();
process.waitFor();
} catch (IOException e) {
} catch (InterruptedException e) {
}
It worked for me

Android shell commands fail to find /data directory

In my application I'm doing:
try {
String[] cmd = {"su", "-c", "\"ls /data/\""}; //to debug, will be cp /src /dest
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.redirectErrorStream(true);
Process process = builder.start();
InputStream is = process.getInputStream();
Log.e("copy", is.toString());
Log.e("copy", convertStreamToString(is));
try {
process.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e1) {
e1.printStackTrace();
}
The app is installed in /system/app/ and running with root permissions.
I see SuperSu's overlay that it's granted permissions for the operation.
With the cp /src /dest in place of ls command above, it doesn't copy, so debugging with ls, I get:
tmp-mksh: ls /data: not found
Why is this, and how can I fix it?
NB: This is the same issue as this question, except that was resolved by adding external write permissions - I should note that both paths in my command are in /data/...

application that execute command in /system

How to create an application that runs a command in /system.
The command that I need to give is: udpxy -p 4022.
This command will start a program that I have in /system.
I do not know which commands use in creating application, which execute this command.
If anyone can help I'll be very grateful.
try {
Process process = Runtime.getRuntime().exec("/system/udpxy -p 4022");
process.waitFor();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
http://developer.android.com/reference/android/os/Process.html

How to delete a system file from an Android App?

I'm using Root Tools and I'm not getting too far with it...
I want to have access to delete files from /system/app and other directories that require root. I would love to do it programmatically through Java, but if I can do it through shell commands, that's OK. Too. My phone is rooted. Here's what I've tried so far.
RootTools.remount("/system", "rw");
try {
RootTools.sendShell("rm /system/app/Videos.apk", -1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (RootToolsException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (TimeoutException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
I've also tried:
public static void sendShell(List<String> cmds) throws Exception {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
for (String tmpCmd : cmds) {
os.writeBytes(tmpCmd+"\n");
}
os.writeBytes("exit\n");
os.flush();
os.close();
process.waitFor();
}
I have no idea what to do from here...
Based on our conversations it looks like you need a different rom as there were issues remounting partitions on your device.
I would bet that flashing a new rom would alleviate this issue and allow RootTools to properly remount /system as rw and allow you to delete your file.

Run android program as root

Is it possible to run my program as root? I know how to run command-line native utils, but how to run Java program as root?
This will work for you:
try {
Process process = Runtime.getRuntime().exec("su");
process.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
You could use this for a command:
exec(new String[] { "su", "-c", COMMAND });
Best wishes,
Tim

Categories

Resources