From cb8aaa6d2fd9ba92983905c432a61dbe6019a899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Thu, 4 Jul 2024 13:22:05 +0200 Subject: [PATCH] Add support for frida-gadget in filesystem tools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Which means the system session is not available. Co-authored-by: Håvard Sørbø --- frida_tools/application.py | 9 +++++++++ frida_tools/ls.py | 2 +- frida_tools/pull.py | 2 +- frida_tools/push.py | 2 +- frida_tools/rm.py | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) 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: