Add support for pulling arguments from gdb.Symbol information about functions

pull/17/head
Zach Riggle 11 years ago
parent ff90b47a7c
commit eab2c4fcd1

@ -52,6 +52,8 @@ def get(instruction):
Otherwise, returns None. Otherwise, returns None.
""" """
n_args_default = 4
if instruction.address != pwndbg.regs.pc: if instruction.address != pwndbg.regs.pc:
return [] return []
@ -67,19 +69,30 @@ def get(instruction):
if not target: if not target:
return [] return []
sym = pwndbg.symbol.get(target) name = pwndbg.symbol.get(target)
if not sym: if not name:
return [] return []
sym = sym.strip().lstrip('_') # _malloc sym = gdb.lookup_symbol(name)
sym = sym.replace('isoc99_', '') # __isoc99_sscanf name = name.strip().lstrip('_') # _malloc
sym = sym.replace('@plt', '') # getpwiod@plt name = name.replace('isoc99_', '') # __isoc99_sscanf
sym = sym.replace('_chk', '') # __printf_chk name = name.replace('@plt', '') # getpwiod@plt
func = pwndbg.functions.functions.get(sym, None) name = name.replace('_chk', '') # __printf_chk
func = pwndbg.functions.functions.get(name, None)
result = [] result = []
args = [] args = []
# Try to extract the data from GDB.
# Note that this is currently broken, pending acceptance of
# my patch: https://sourceware.org/ml/gdb-patches/2015-06/msg00268.html
if sym and sym[0]:
try:
n_args_default = len(sym[0].type.fields())
except TypeError:
pass
# Try to grab the data out of IDA # Try to grab the data out of IDA
if not func and target: if not func and target:
typename = pwndbg.ida.GetType(target) typename = pwndbg.ida.GetType(target)
@ -98,7 +111,7 @@ def get(instruction):
if func: if func:
args = func.args args = func.args
else: else:
args = [pwndbg.functions.Argument('int',0,argname(i)) for i in range(4)] args = [pwndbg.functions.Argument('int',0,argname(i)) for i in range(n_args_default)]
for i,arg in enumerate(args): for i,arg in enumerate(args):
result.append((arg, argument(i))) result.append((arg, argument(i)))

Loading…
Cancel
Save