Skip to content

Commit

Permalink
processes: Add kill_exists and refined PID validation in launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
netanelc305 committed Feb 26, 2024
1 parent 38f6433 commit cdb6376
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rpcclient/rpcclient/ios/processes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit cdb6376

Please sign in to comment.