mirror of
https://github.com/frida/frida-python
synced 2026-06-08 14:16:17 +00:00
Get args from manpages for auto-generated tracer
This commit is contained in:
+27
-2
@@ -5,6 +5,7 @@ import fnmatch
|
||||
import time
|
||||
import re
|
||||
import binascii
|
||||
import subprocess
|
||||
|
||||
from frida.core import ModuleFunction
|
||||
|
||||
@@ -308,6 +309,30 @@ class Repository(object):
|
||||
self._on_update_callback(function, handler, source)
|
||||
|
||||
def _create_stub_handler(self, function):
|
||||
args = ""
|
||||
argc = 0
|
||||
varargs = False
|
||||
try:
|
||||
output = subprocess.check_output(["man", "-P", "col -b", "2", function.name], stderr=subprocess.DEVNULL)
|
||||
match = re.search(r"^SYNOPSIS(?:.|\n)*?((?:^.+$\n)* {5}" + function.name + r"\(.*\n(^.+$\n)*)(?:.|\n)*^DESCRIPTION", output.decode(), re.MULTILINE)
|
||||
if match:
|
||||
decl = match.group(1)
|
||||
for argm in re.finditer(r"([^* ]*)\s*(,|\))", decl):
|
||||
arg = argm.group(1)
|
||||
if arg == '...':
|
||||
args += '+ ", ..."'
|
||||
varargs = True
|
||||
continue
|
||||
|
||||
args += '%(pre)s%(arg)s=" + args[%(argc)s]' % {"arg": arg, "argc": argc, "pre": '"' if argc == 0 else '+ ", '}
|
||||
argc += 1
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
if args == "":
|
||||
args = '""'
|
||||
|
||||
return """\
|
||||
/*
|
||||
* Auto-generated by Frida. Please modify to match the signature of %(name)s.
|
||||
@@ -332,7 +357,7 @@ class Repository(object):
|
||||
* use "this" which is an object for keeping state local to an invocation.
|
||||
*/
|
||||
onEnter: function onEnter(log, args, state) {
|
||||
log("%(name)s()");
|
||||
log("%(name)s(" + %(args)s + ")");
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -348,7 +373,7 @@ class Repository(object):
|
||||
onLeave: function onLeave(log, retval, state) {
|
||||
}
|
||||
}
|
||||
""" % { 'name': function.name }
|
||||
""" % { "name": function.name, "args": args }
|
||||
|
||||
class MemoryRepository(Repository):
|
||||
def __init__(self):
|
||||
|
||||
Reference in New Issue
Block a user