mirror of https://github.com/pwndbg/pwndbg.git
Add `stepuntilasm` command (#1798)
* Add `stepuntilasm` command This commit adds a `stepuntilasm` command that, given a mnemonic and, optionally, a set of operands, will step until a instruction that matches both is found. Matching is string-based, as the user will likely want to spell out the asm directive they want as text, and interpreting assembly language conventions for all of the platforms pwndbg supports is probably outside the scope of this change. * next.py: small code cleanup * next.py: fix bug introduced in previous commit op.str -> op_str * Update next.py * Update next.py * Update next.py --------- Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>pull/1806/head
parent
e37591b25d
commit
29fea60b21
@ -0,0 +1,45 @@
|
||||
section .text
|
||||
global _start
|
||||
global break_here
|
||||
global stop1
|
||||
global stop2
|
||||
global stop3
|
||||
global stop4
|
||||
_start:
|
||||
break_here:
|
||||
xor rax, rax
|
||||
stop1:
|
||||
nop ; Stop point #1: No operands
|
||||
stop2:
|
||||
xor rax, rax ; Stop point #2: Some simple operands
|
||||
|
||||
lea rax, [some_data]
|
||||
stop3:
|
||||
; Stop point #3: More complex operands.
|
||||
mov qword [rax], 0x20
|
||||
|
||||
call loop
|
||||
lea rax, [some_data]
|
||||
stop4:
|
||||
; Stop point #4: Even more complex operands, after loop.
|
||||
mov dword [rax+4], 0x20
|
||||
|
||||
exit:
|
||||
; Terminate the process by calling sys_exit(0) in Linux.
|
||||
mov rax, 60
|
||||
mov rdi, 0
|
||||
syscall
|
||||
|
||||
|
||||
; Loop subroutine. Loops for a while so we can test whether stepuntilasm can get
|
||||
; to a directive that's sitting after a few iterations of a loop.
|
||||
loop:
|
||||
mov rax, 100
|
||||
loop_iter:
|
||||
sub rax, 1
|
||||
jnz loop_iter
|
||||
|
||||
ret
|
||||
|
||||
section .bss
|
||||
some_data: resq 1
|
||||
@ -0,0 +1,23 @@
|
||||
import gdb
|
||||
|
||||
import pwndbg.gdblib
|
||||
import tests
|
||||
|
||||
STEPUNTILASM_X64_BINARY = tests.binaries.get("stepuntilasm_x64.out")
|
||||
|
||||
|
||||
def test_command_untilasm_x64(start_binary):
|
||||
start_binary(STEPUNTILASM_X64_BINARY)
|
||||
gdb.execute("break break_here")
|
||||
gdb.execute("run")
|
||||
|
||||
run_and_verify("stop1", "nop")
|
||||
run_and_verify("stop2", "xor rax, rax")
|
||||
run_and_verify("stop3", "mov qword ptr [rax], 0x20")
|
||||
run_and_verify("stop4", "mov dword ptr [rax+4], 0x20")
|
||||
|
||||
|
||||
def run_and_verify(stop_label, asm):
|
||||
gdb.execute(f"stepuntilasm {asm}")
|
||||
address = int(gdb.parse_and_eval(f"&{stop_label}"))
|
||||
assert pwndbg.gdblib.regs.pc == address
|
||||
Loading…
Reference in new issue