Add nextproginstr command (#360)

* Add nextproginstr command

* Fix isort

* Update next.py

* Update next.py

* Update next.py
pull/359/head
Disconnect3d 8 years ago committed by GitHub
parent 6aeffbea24
commit 5811010cc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,8 +10,9 @@ import gdb
import pwndbg.color
import pwndbg.events
import pwndbg.file
import pwndbg.remote
import pwndbg.memoize
import pwndbg.remote
@pwndbg.memoize.reset_on_start
@pwndbg.memoize.reset_on_exit

@ -42,6 +42,14 @@ def nextret(*args):
pwndbg.commands.context.context()
@pwndbg.commands.Command
@pwndbg.commands.OnlyWhenRunning
def nextproginstr(*args):
"""Breaks at the next instruction that belongs to the running program"""
if pwndbg.next.break_on_program_code():
pwndbg.commands.context.context()
@pwndbg.commands.Command
@pwndbg.commands.OnlyWhenRunning
def stepover(*args):

@ -16,6 +16,7 @@ import gdb
import pwndbg.disasm
import pwndbg.regs
from pwndbg.color import red
jumps = set((
capstone.CS_GRP_CALL,
@ -120,6 +121,29 @@ def break_next_ret(address=None):
return ins
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
if start <= pwndbg.regs.pc < end:
print(red('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.regs.pc
if start <= addr < end:
return True
return False
def break_on_next(address=None):
address = address or pwndbg.regs.pc
ins = pwndbg.disasm.one(address)

@ -70,6 +70,10 @@ class module(ModuleType):
auxv = pwndbg.auxv.get()
return auxv['AT_EXECFN']
@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):

Loading…
Cancel
Save