Created
October 19, 2011 00:11
-
-
Save rgov/1297132 to your computer and use it in GitHub Desktop.
call functions in target process with lldb Python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lldb | |
class Executioner(object): | |
typemap = { | |
None: 'void', | |
int: 'int', | |
float: 'float', | |
str: 'char *', | |
} | |
class Function(object): | |
def __init__(self, name): | |
self.name = name | |
self.returns = None | |
def __call__(self, *args): | |
argStrs = [ ] | |
for arg in args: | |
if isinstance(arg, str): | |
argStrs.append('"%s"' % arg.replace('\\', '\\\\').replace('"', '\"')) | |
else: | |
argStrs.append(repr(arg)) | |
expr = '(%s)%s(%s)' % (Executioner.typemap[self.returns], self.name, ', '.join(argStrs)) | |
return lldb.frame.EvaluateExpression(expr) | |
def __init__(self): | |
self._funcs = { } | |
def __getattr__(self, name): | |
fn = Executioner.Function(name) | |
setattr(self, name, fn) | |
return fn | |
lldb.exec = Executioner() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment