diff --git a/pwndbg/commands/next.py b/pwndbg/commands/next.py index df7849f59..bc3ac992d 100644 --- a/pwndbg/commands/next.py +++ b/pwndbg/commands/next.py @@ -67,9 +67,7 @@ def stepret(): ) @pwndbg.commands.OnlyWhenRunning def nextproginstr(): - """Breaks at the next instruction that belongs to the running program""" - if pwndbg.gdblib.next.break_on_program_code(): - pwndbg.commands.context.context() + pwndbg.gdblib.next.break_on_program_code() parser = argparse.ArgumentParser( diff --git a/pwndbg/gdblib/next.py b/pwndbg/gdblib/next.py index 521c37c76..d5083fb6f 100644 --- a/pwndbg/gdblib/next.py +++ b/pwndbg/gdblib/next.py @@ -129,20 +129,24 @@ def break_on_program_code(): Breaks on next instruction that belongs to process' objfile code. :return: True for success, False when process ended or when pc is at the code. """ - mp = pwndbg.proc.mem_page - start = mp.start - end = mp.end + exe = pwndbg.proc.exe + binary_exec_page_ranges = [ + (p.start, p.end) for p in pwndbg.vmmap.get() if p.objfile == exe and p.execute + ] - if start <= pwndbg.gdblib.regs.pc < end: - print(message.error("The pc is already at the binary objfile code. Not stepping.")) - return False + pc = pwndbg.gdblib.regs.pc + for start, end in binary_exec_page_ranges: + if start <= pc < end: + print(message.error("The pc is already at the binary objfile code. Not stepping.")) + return False while pwndbg.proc.alive: gdb.execute("si", from_tty=False, to_string=False) - addr = pwndbg.gdblib.regs.pc - if start <= addr < end: - return True + pc = pwndbg.gdblib.regs.pc + for start, end in binary_exec_page_ranges: + if start <= pc < end: + return True return False diff --git a/pwndbg/proc.py b/pwndbg/proc.py index 0314ff6f6..1bc6f0212 100644 --- a/pwndbg/proc.py +++ b/pwndbg/proc.py @@ -69,10 +69,6 @@ class module(ModuleType): """ return gdb.current_progspace().filename - @property - def mem_page(self): - return next(p for p in pwndbg.vmmap.get() if p.objfile == self.exe) - def OnlyWhenRunning(self, func): @functools.wraps(func) def wrapper(*a, **kw):