Merge pull request #17 from Tyilo/patch-1

Get args from manpages for auto-generated tracer
This commit is contained in:
Ole André Vadla Ravnås
2015-03-02 17:25:21 +01:00
+28 -2
View File
@@ -5,6 +5,7 @@ import fnmatch
import time
import re
import binascii
import subprocess
from frida.core import ModuleFunction
@@ -308,6 +309,31 @@ class Repository(object):
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 @@ 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 +374,7 @@ class Repository(object):
onLeave: function onLeave(log, retval, state) {
}
}
""" % { 'name': function.name }
""" % { "name": function.name, "args": args }
class MemoryRepository(Repository):
def __init__(self):