2

我可以轻松地从 adb shell 使用 'rm /data/system/[file]' 但从应用程序这不起作用。

命令“du”、“ls”、“echo”在代码中工作正常,但命令“rm”不起作用。它甚至不适用于 sdcard。

我试过的代码:

1)

String[] cmd = { "/system/bin/sh", "-c", "rm -r /sdcard/1" }; 
    try {

        Process process = Runtime.getRuntime().exec(cmd);//execute command

        //read the output of command
        InputStreamReader reader = new InputStreamReader(process.getInputStream()); 
.....

2) 与 (1) 相同的代码,用“su”代替“/system/bin/sh”

3)

process=Runtime.getRuntime().exec("/system/bin/sh");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("rm -r /sdcard/1\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();

4) 与 (3) 相同的代码,用 'su' 代替 '/system/bin/sh'

4

2 回答 2

0

进入开发者模式启动设置,用.anr文件调试,然后用dex文件编译inertpreteor开始启动rm命令

于 2014-08-13T06:52:22.033 回答
0

您可以删除应用程序字段结构中的文件

我的意思是:/data/data/com.mycompany.myapp

[我不确定你是否可以删除其他地方的文件,因为需要sudo ]

所以,就这样吧:

String cmd="rm -f /data/data/com.mycompany.myapp/myfile.txt";
try
  {
  Runtime.getRuntime().exec(new String[]{"sh","-c",cmd});
  }
  catch(Exception e){}
  • -f强制删除 [可选]
  • 例外{}由您决定
于 2021-03-16T06:04:27.457 回答