diff --git a/src/adb.py b/src/adb.py index 7e7940d..7934c69 100644 --- a/src/adb.py +++ b/src/adb.py @@ -44,12 +44,18 @@ class Device: raise ADBConnectException self.device = self.client.device(f"{host}:{port}") - def _execute_command(self, cmd: str, su: bool = False) -> Optional[str]: - if su: - cmd = cmd.replace("\"", "\\\"") - output = self.device.shell(f"{self.suMethod} \"{cmd}\"") - else: - output = self.device.shell(cmd, timeout=30) + def _execute_command(self, cmd: str, su: bool = False, sh: bool = False) -> Optional[str]: + whoami = self.device.shell("whoami") + final_cmd = cmd + if whoami.strip() != "root" and su: + if self.suMethod == "su -c": + replaced_cmd = cmd.replace("\"", "\\\"") + final_cmd = f"{self.suMethod} \"{replaced_cmd}\"" + else: + final_cmd = f"{self.suMethod} {final_cmd}" + if sh: + final_cmd = f"sh -c '{final_cmd}'" + output = self.device.shell(final_cmd, timeout=30) if not output: return "" return output diff --git a/src/cmd.py b/src/cmd.py index 26c4124..b22b8ec 100644 --- a/src/cmd.py +++ b/src/cmd.py @@ -43,7 +43,7 @@ class NewInteractiveShell: logger.add(lambda msg: print_formatted_text(ANSI(msg), end=""), colorize=True, level="INFO") for device_info in self.config.devices: - device = Device(frida_path=device_info.fridaPath) + device = Device(frida_path=device_info.fridaPath, su_method=device_info.suMethod) device.connect(device_info.host, device_info.port) logger.info(f"Device {device_info.host}:{device_info.port} has connected") self.devices.append(device) diff --git a/src/config.py b/src/config.py index 49a88d7..0bc2a40 100644 --- a/src/config.py +++ b/src/config.py @@ -13,6 +13,7 @@ class Device(BaseModel): port: int agentPort: int fridaPath: str + suMethod: str class Download(BaseModel):