diff --git a/src/rpcclient/rpcclient/ios/processes.py b/src/rpcclient/rpcclient/ios/processes.py index a0fddb93..2c5c3cb5 100644 --- a/src/rpcclient/rpcclient/ios/processes.py +++ b/src/rpcclient/rpcclient/ios/processes.py @@ -1,12 +1,18 @@ +import logging +from datetime import datetime, timedelta from typing import Optional from rpcclient.darwin.processes import DarwinProcesses from rpcclient.exceptions import LaunchError +from rpcclient.structs.consts import SIGKILL + +logger = logging.getLogger(__name__) class IosProcesses(DarwinProcesses): - def launch(self, bundle_id: str, unlock_device: bool = True, disable_aslr: bool = False, + def launch(self, bundle_id: str, kill_exists: bool = True, timeout: float = 1, unlock_device: bool = True, + disable_aslr: bool = False, wait_for_debugger: bool = False, stdout: Optional[str] = None, stderr: Optional[str] = None) -> int: """ launch process using BackBoardService @@ -26,12 +32,21 @@ def launch(self, bundle_id: str, unlock_device: bool = True, disable_aslr: bool options[sym.BKSOpenApplicationOptionKeyDebuggingOptions[0].py()] = debug_options bkssystem_service = self._client.objc_get_class('BKSSystemService').new().objc_symbol + pid = bkssystem_service.pidForApplication_(self._client.cf(bundle_id)).c_int32 + if pid != -1 and kill_exists: + logger.info(f'Kill existing process {pid}') + self.kill(pid, SIGKILL) + bkssystem_service.openApplication_options_clientPort_withResult_(self._client.cf(bundle_id), self._client.cf(options), bkssystem_service.createClientPort(), self._client.get_dummy_block()) - pid = bkssystem_service.pidForApplication_(self._client.cf(bundle_id)).c_int32 + start_time = datetime.now() + timeout = timedelta(seconds=timeout) + while datetime.now() - start_time < timeout: + pid = bkssystem_service.pidForApplication_(self._client.cf(bundle_id)).c_int32 + if pid == -1: raise LaunchError() return pid