diff --git a/pwndbg/commands/start.py b/pwndbg/commands/start.py index 554d02c1b..d923af044 100644 --- a/pwndbg/commands/start.py +++ b/pwndbg/commands/start.py @@ -33,17 +33,21 @@ def start(*a): "start", "_start", "init", - "_init", - pwndbg.elf.entry()] + "_init"] - for address in filter(bool, map(pwndbg.symbol.address, symbols)): - if address: - b = gdb.Breakpoint('*%#x' % address, temporary=True) - gdb.execute(run, from_tty=False, to_string=True) - break + # Try a symbolic breakpoint which GDB will automatically update. + symbols = {s:pwndbg.symbol.address(s) for s in symbols} - else: - entry(*a) + for name, address in symbols.items(): + if not address: + continue + + b = gdb.Breakpoint(name, temporary=True) + gdb.execute(run, from_tty=False, to_string=True) + return + + # Try a breakpoint at the binary entry + entry(*a) @pwndbg.commands.Command diff --git a/pwndbg/memoize.py b/pwndbg/memoize.py index 0011c7abe..896eca61c 100644 --- a/pwndbg/memoize.py +++ b/pwndbg/memoize.py @@ -24,7 +24,7 @@ class memoize(object): self.caches.append(self) functools.update_wrapper(self, func) - def __call__(self, *args): + def __call__(self, *args, **kwargs): how = None if not isinstance(args, collections.Hashable): @@ -38,7 +38,7 @@ class memoize(object): else: how = "Executed" - value = self.func(*args) + value = self.func(*args, **kwargs) self.cache[args] = value if isinstance(value, list): diff --git a/pwndbg/stdio.py b/pwndbg/stdio.py index 26065c7ff..afd42d8cf 100644 --- a/pwndbg/stdio.py +++ b/pwndbg/stdio.py @@ -5,12 +5,18 @@ which prevent output from appearing on-screen inside of certain event handlers. import gdb import io import sys +import pwndbg.compat debug = True def get(fd, mode): file = io.open(1, mode=mode, buffering=0, closefd=False) - return io.TextIOWrapper(file, write_through=True) + + kw = {} + if pwndbg.compat.python3: + kw['write_through']=True + + return io.TextIOWrapper(file, **kw) if debug: sys.stdin = get(0, 'rb') diff --git a/pwndbg/symbol.py b/pwndbg/symbol.py index 7b9fa9358..3d6a6b387 100644 --- a/pwndbg/symbol.py +++ b/pwndbg/symbol.py @@ -17,7 +17,7 @@ import pwndbg.stack import pwndbg.vmmap @pwndbg.memoize.reset_on_objfile -def get(address): +def get(address, gdb_only=False): """ Retrieve the textual name for a symbol """ @@ -32,7 +32,7 @@ def get(address): # This sucks, but there's not a GDB API for this. result = gdb.execute('info symbol %#x' % int(address), to_string=True, from_tty=False) - if result.startswith('No symbol'): + if not gdb_only and result.startswith('No symbol'): address = int(address) exe = pwndbg.elf.exe() if exe: @@ -65,6 +65,7 @@ def address(symbol): result = gdb.execute('info address %s' % symbol, to_string=True, from_tty=False) result = result.split() address = next(r for r in result if r.startswith('0x')) + address = address.rstrip('.') return int(address, 0) except gdb.error: return None