Skip to content

Commit ca0ea53

Browse files
sam-f0sam-f0
authored andcommitted
Fix spawning, only attempt if package not running
1 parent 085b9cc commit ca0ea53

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

binder_trace/binder_trace/generator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,18 @@ def __init__(
5656

5757
def start(self):
5858
"""Start the injector."""
59-
if self.spawn_process:
60-
self.device.spawn([self.process_identifier])
59+
# Frida can behave weirdly if you attempt to spawn a package which is already running
60+
# so first try to attach, and if it fails and spawn option supplied, spawn it.
61+
try:
62+
self.session = self.device.attach(self.process_identifier)
63+
except frida.ProcessNotFoundError:
64+
if self.spawn_process:
65+
self.device.spawn([self.process_identifier])
66+
self.start()
67+
return
68+
else:
69+
raise
6170

62-
self.session = self.device.attach(self.process_identifier)
6371
self.script = self.session.create_script(self.script_content)
6472
self.script.on("message", self._message_handler)
6573

0 commit comments

Comments
 (0)