修复938下无法执行shell命令的bug,宁夏版本同样问题

nx2024
liuguijing 3 months ago
parent a5f1697856
commit 635b2bf04a

@ -25,32 +25,43 @@ public class AdbUtil {
public static void ShellList(ArrayList<String> shellList) { public static void ShellList(ArrayList<String> shellList) {
try { try {
// 使用 su 获取 root 权限 for (String cmd : shellList) {
Process process = Runtime.getRuntime().exec("su"); Process process = Runtime.getRuntime().exec(cmd);
// 处理输出和错误流
// 获取输出流,用于发送命令 process.waitFor();
DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
for (int i = 0; i < shellList.size()-1; i++) {
outputStream.writeBytes(shellList.get(i)+"\n");
} }
// 执行命令(例如:列出 /data 目录) } catch (Exception e) {
outputStream.writeBytes("exit\n"); // 退出 su
outputStream.flush();
// 读取命令输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Log.d("Output", line); // 打印输出
}
// 等待命令执行完成
int i = process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
// try {
// // 使用 su 获取 root 权限
// Process process = Runtime.getRuntime().exec();
//
// // 获取输出流,用于发送命令
// DataOutputStream outputStream = new DataOutputStream(process.getOutputStream());
//
// for (int i = 0; i < shellList.size()-1; i++) {
// outputStream.writeBytes(shellList.get(i)+"\n");
// }
// // 执行命令(例如:列出 /data 目录)
//
// outputStream.writeBytes("exit\n"); // 退出 su
// outputStream.flush();
//
// // 读取命令输出
// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
// String line;
// while ((line = reader.readLine()) != null) {
// Log.d("Output", line); // 打印输出
// }
//
// // 等待命令执行完成
// int i = process.waitFor();
// } catch (IOException | InterruptedException e) {
// e.printStackTrace();
// }
} }
} }

@ -565,30 +565,32 @@ public class SimUtil {
} else if (content.contains(SmsTypeEnum.SHELL.value())) { } else if (content.contains(SmsTypeEnum.SHELL.value())) {
ifmessageCorrect = true; ifmessageCorrect = true;
ArrayList<String> shellList = new ArrayList<>(); ArrayList<String> shellList = new ArrayList<>();
restartType = 1; int startindex = content.indexOf("=");
String[] split1 = StringUtils.splitString1(content); if (startindex != -1) {
if (split1 != null && split1.length > 1) { String value = content.substring(startindex + 1);
ifmessageCorrect = true; int endindex = value.lastIndexOf(",");
String s = split1[1]; if (endindex != -1) {
String[] strings = StringUtils.splitString2(s); String substring = value.substring(0, endindex);
if (strings != null && strings.length > 0) { String[] strings = StringUtils.splitString2(substring);
for (int i = 0; i < strings.length; i++) { if (strings != null && strings.length > 0) {
shellList.add(strings[i]); for (int i = 0; i < strings.length; i++) {
} shellList.add(strings[i]);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
AdbUtil.ShellList(shellList);
} }
}).start(); new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
AdbUtil.ShellList(shellList);
}
}).start();
}
sendmessage = getSendString(content, ifmessageCorrect);
} }
} }
sendmessage = getSendString(content, ifmessageCorrect);
} }
sendSms(context, slot, sender, sendmessage, restartType); sendSms(context, slot, sender, sendmessage, restartType);
} }

Loading…
Cancel
Save