From 635b2bf04ae3d55b7178968df78cb6535e94c616 Mon Sep 17 00:00:00 2001 From: liuguijing <1440265357@qq.com> Date: Thu, 27 Mar 2025 16:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D938=E4=B8=8B=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=89=A7=E8=A1=8Cshell=E5=91=BD=E4=BB=A4=E7=9A=84bug?= =?UTF-8?q?=EF=BC=8C=E5=AE=81=E5=A4=8F=E7=89=88=E6=9C=AC=E5=90=8C=E6=A0=B7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpmaster/sms/AdbUtil.java | 57 +++++++++++-------- .../com/xypower/mpmaster/sms/SimUtil.java | 44 +++++++------- 2 files changed, 57 insertions(+), 44 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/AdbUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/AdbUtil.java index 4e713818..04ad4648 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/AdbUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/AdbUtil.java @@ -25,32 +25,43 @@ public class AdbUtil { public static void ShellList(ArrayList shellList) { try { - // 使用 su 获取 root 权限 - Process process = Runtime.getRuntime().exec("su"); - - // 获取输出流,用于发送命令 - DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); - - for (int i = 0; i < shellList.size()-1; i++) { - outputStream.writeBytes(shellList.get(i)+"\n"); + for (String cmd : shellList) { + Process process = Runtime.getRuntime().exec(cmd); + // 处理输出和错误流 + process.waitFor(); } - // 执行命令(例如:列出 /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) { + } catch (Exception e) { 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(); +// } } } diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java index fb915cbe..7e2b0a06 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/sms/SimUtil.java @@ -565,30 +565,32 @@ public class SimUtil { } else if (content.contains(SmsTypeEnum.SHELL.value())) { ifmessageCorrect = true; ArrayList shellList = new ArrayList<>(); - restartType = 1; - String[] split1 = StringUtils.splitString1(content); - if (split1 != null && split1.length > 1) { - ifmessageCorrect = true; - String s = split1[1]; - String[] strings = StringUtils.splitString2(s); - if (strings != null && strings.length > 0) { - 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); + int startindex = content.indexOf("="); + if (startindex != -1) { + String value = content.substring(startindex + 1); + int endindex = value.lastIndexOf(","); + if (endindex != -1) { + String substring = value.substring(0, endindex); + String[] strings = StringUtils.splitString2(substring); + if (strings != null && strings.length > 0) { + for (int i = 0; i < strings.length; i++) { + shellList.add(strings[i]); } - }).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); }