@@ -5,6 +5,7 @@
55import time
66import re
77import binascii
8+import subprocess
89910from frida.core import ModuleFunction
1011@@ -308,6 +309,31 @@ def _notify_update(self, function, handler, source):
308309self._on_update_callback(function, handler, source)
309310310311def _create_stub_handler(self, function):
312+args = ""
313+argc = 0
314+varargs = False
315+try:
316+with open(os.devnull, 'w') as devnull:
317+output = subprocess.check_output(["man", "-P", "col -b", "2", function.name], stderr=devnull)
318+match = re.search(r"^SYNOPSIS(?:.|\n)*?((?:^.+$\n)* {5}" + function.name + r"\(.*\n(^.+$\n)*)(?:.|\n)*^DESCRIPTION", output.decode(), re.MULTILINE)
319+if match:
320+decl = match.group(1)
321+for argm in re.finditer(r"([^* ]*)\s*(,|\))", decl):
322+arg = argm.group(1)
323+if arg == '...':
324+args += '+ ", ..."'
325+varargs = True
326+continue
327+328+args += '%(pre)s%(arg)s=" + args[%(argc)s]' % {"arg": arg, "argc": argc, "pre": '"' if argc == 0 else '+ ", '}
329+argc += 1
330+331+except (subprocess.CalledProcessError, OSError): # WindowError or FileNotFoundError
332+pass
333+334+if args == "":
335+args = '""'
336+311337return """\
312338/*
313339 * Auto-generated by Frida. Please modify to match the signature of %(name)s.
@@ -332,7 +358,7 @@ def _create_stub_handler(self, function):
332358 * use "this" which is an object for keeping state local to an invocation.
333359 */
334360 onEnter: function onEnter(log, args, state) {
335- log("%(name)s()");
361+ log("%(name)s(" + %(args)s + ")");
336362 },
337363338364 /**
@@ -348,7 +374,7 @@ def _create_stub_handler(self, function):
348374 onLeave: function onLeave(log, retval, state) {
349375 }
350376}
351-""" % { 'name': function.name }
377+""" % { "name": function.name, "args": args }
352378353379class MemoryRepository(Repository):
354380def __init__(self):