diff --git a/frida_tools/application.py b/frida_tools/application.py index d9413f48..9b9aa739 100644 --- a/frida_tools/application.py +++ b/frida_tools/application.py @@ -601,6 +601,15 @@ def _try_start(self) -> None: self._start() self._started = True + def _pick_worker_pid(self) -> int: + try: + frontmost = self._device.get_frontmost_application() + if frontmost is not None and frontmost.identifier == "re.frida.Gadget": + return frontmost.pid + except: + pass + return 0 + def _attach(self, pid: int) -> None: self._target_pid = pid diff --git a/frida_tools/ls.py b/frida_tools/ls.py index 6bed6a1f..9848bd0f 100644 --- a/frida_tools/ls.py +++ b/frida_tools/ls.py @@ -35,7 +35,7 @@ def _needs_target(self) -> bool: def _start(self) -> None: try: - self._attach(0) + self._attach(self._pick_worker_pid()) data_dir = os.path.dirname(__file__) with codecs.open(os.path.join(data_dir, "fs_agent.js"), "r", "utf-8") as f: diff --git a/frida_tools/pull.py b/frida_tools/pull.py index 47d74d01..e5d9a61b 100644 --- a/frida_tools/pull.py +++ b/frida_tools/pull.py @@ -56,7 +56,7 @@ def _needs_target(self) -> bool: def _start(self) -> None: try: - self._attach(0) + self._attach(self._pick_worker_pid()) data_dir = os.path.dirname(__file__) with codecs.open(os.path.join(data_dir, "fs_agent.js"), "r", "utf-8") as f: diff --git a/frida_tools/push.py b/frida_tools/push.py index cf4b5eaa..26968e47 100644 --- a/frida_tools/push.py +++ b/frida_tools/push.py @@ -45,7 +45,7 @@ def _needs_target(self) -> bool: def _start(self) -> None: try: - self._attach(0) + self._attach(self._pick_worker_pid()) data_dir = os.path.dirname(__file__) with codecs.open(os.path.join(data_dir, "fs_agent.js"), "r", "utf-8") as f: diff --git a/frida_tools/rm.py b/frida_tools/rm.py index 6c18912d..934bc1af 100644 --- a/frida_tools/rm.py +++ b/frida_tools/rm.py @@ -38,7 +38,7 @@ def _needs_target(self) -> bool: def _start(self) -> None: try: - self._attach(0) + self._attach(self._pick_worker_pid()) data_dir = os.path.dirname(__file__) with codecs.open(os.path.join(data_dir, "fs_agent.js"), "r", "utf-8") as f: