Permalink
Browse files

Merge pull request #17 from Tyilo/patch-1

Get args from manpages for auto-generated tracer
  • Loading branch information...
2 parents ef8145c + a0bb52f commit daf1a310670588e5672af2205658598be342c2e2 @oleavr oleavr committed Mar 2, 2015
Showing with 28 additions and 2 deletions.
  1. +28 −2 src/frida/tracer.py
View
@@ -5,6 +5,7 @@
import time
import re
import binascii
+import subprocess
from frida.core import ModuleFunction
@@ -308,6 +309,31 @@ def _notify_update(self, function, handler, source):
self._on_update_callback(function, handler, source)
def _create_stub_handler(self, function):
+ args = ""
+ argc = 0
+ varargs = False
+ try:
+ with open(os.devnull, 'w') as devnull:
+ output = subprocess.check_output(["man", "-P", "col -b", "2", function.name], stderr=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, OSError): # WindowError or FileNotFoundError
+ pass
+
+ if args == "":
+ args = '""'
+
return """\
/*
* Auto-generated by Frida. Please modify to match the signature of %(name)s.
@@ -332,7 +358,7 @@ def _create_stub_handler(self, function):
* 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 +374,7 @@ def _create_stub_handler(self, function):
onLeave: function onLeave(log, retval, state) {
}
}
-""" % { 'name': function.name }
+""" % { "name": function.name, "args": args }
class MemoryRepository(Repository):
def __init__(self):

0 comments on commit daf1a31

Please sign in to comment.