-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrtrace.py
More file actions
executable file
·64 lines (59 loc) · 2.11 KB
/
strtrace.py
File metadata and controls
executable file
·64 lines (59 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
import frida
import sys
import os
def on_message(message, _):
if message['type'] == 'send':
if message['payload']['type'] == 'finish':
global session
session.detach()
sys.stderr.write("finished tracing\n")
sys.stderr.write("Press Enter to exit...\n")
else:
print(message)
def parse_args():
app_name = None
module_name = None
function_offset = None
spawn = False
if "--app" not in sys.argv or "--func" not in sys.argv:
sys.stderr.write("Usage: %s --app <app_name> --func <module_name>!<function_offset> [--spawn]" % sys.argv[0])
sys.exit(1)
else:
sys.stderr.write(" ".join(sys.argv) + "\n")
for i in range(1, len(sys.argv)):
if sys.argv[i] == "--app":
app_name = sys.argv[i+1]
elif sys.argv[i] == "--func":
module_name, function_offset = sys.argv[i+1].split("!")
elif sys.argv[i] == "--spawn":
spawn = True
return app_name, module_name, eval(function_offset), spawn
def main(app_name, module_name, function_offset, spawn):
global session
args = {"module_name": module_name, "function_offset": function_offset}
device = frida.get_usb_device()
if spawn:
pid = device.spawn([app_name])
session = device.attach(pid)
else:
target_process = device.get_process(app_name)
session = device.attach(target_process.pid)
js_file = os.path.abspath(__file__).replace("strtrace.py", "strtrace.js")
script = session.create_script(open(js_file).read())
script.on('message', on_message)
script.load()
script.post({"type": "args", "data": args})
sys.stderr.write("script loaded, waiting function...\n")
if spawn:
device.resume(pid)
input()
session.detach()
if __name__ == "__main__":
try:
app, module, func_offset, spawn = parse_args()
main(app, module, func_offset, spawn)
except frida.ProcessNotFoundError:
sys.stderr.write("Process %s not found" % app)
except KeyboardInterrupt:
sys.stderr.write("Exiting...")