Runtime.exec()可执行库在非根目录下不工作



我有代码:

private static String writeCommandToConsole(Process proc, String command, boolean ignoreError) throws Exception {
byte[] tmpArray = new byte[1024];
proc.getOutputStream().write((command + "n").getBytes());
proc.getOutputStream().flush();
int bytesRead;
if (proc.getErrorStream().available() > 0) {
if ((bytesRead = proc.getErrorStream().read(tmpArray)) > 1) {
Log.e(LOG_TAG, new String(tmpArray, 0, bytesRead));
if (!ignoreError)
throw new Exception(new String(tmpArray, 0, bytesRead));
}
}
if (proc.getInputStream().available() > 0) {
bytesRead = proc.getInputStream().read(tmpArray);
Log.i(LOG_TAG, new String(tmpArray, 0, bytesRead));
}
return new String(tmpArray);
}
public static void Changes(Context con, int fNums, String fNames, int is, boolean bools, String strs) {
final String fNum = String.valueOf(fNums);
final String fName = fNames;
final String i = String.valueOf(is);
final String str = strs;
final String bool = bools ? "true" : "false";
final String path = pathExecutable + " " + fNum + " "" + fName + "" " + i + " " + bool + " "" + str + """;
new Thread(new Runnable() {
@Override
public void run() {
try {
if (isRoot) {
Process proc = Runtime.getRuntime().exec(new String[]{"su"});
writeCommandToConsole(proc, path, true);
} else {
Process proc = Runtime.getRuntime().exec(path);
proc.wait();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}).start();
}

for root工作正常(我的手机是root) ..但对于非根手机,它不起作用(在非根手机中使用并行空间,virtualexposed等)…

只能在有根的虚拟机上工作(vmos,x8, sabdbox等)。我试图使用processBuilder,但有相同的结果。可执行库似乎无法进入目标..

如何编写正确的运行时。执行使其工作在非根电话(使用并行空间或任何克隆没有虚拟机与根包括)?或者是否有任何方法可以在没有su命令的情况下运行可执行的lib ?

解决…我将非根命令更改为

Process proc = Runtime.getRuntime()。exec(新String[]{"sh");writeCommandToConsole(proc, path, true);

在一些虚拟应用程序中运行良好。

相关内容

最新更新