-
Notifications
You must be signed in to change notification settings - Fork 857
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import gdb | ||
import pytest | ||
|
||
import pwndbg.gdblib | ||
import tests | ||
|
||
STEPUNTILASM_X64_BINARY = tests.binaries.get("stepuntilasm_x64.out") | ||
|
||
|
||
@pytest.mark.parametrize("binary", [STEPUNTILASM_X64_BINARY], ids=["x86-64"]) | ||
def test_command_untilasm_x64(start_binary, binary): | ||
""" | ||
Tests the chain for a non-nested linked list | ||
""" | ||
|
||
start_binary(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 |