Is there anyway to break on gdb
where $r1
equals to a certain string
I know there is :
break [addr] if ((int)strcmp($r1, "hello")) == 0
But what to set in addr
when I just wanna break when the r1
is "hello"
no matter the address?
Reverse Engineering Stack Exchange is a question and answer site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation. It only takes a minute to sign up.
Sign up to join this communityIs there anyway to break on gdb
where $r1
equals to a certain string
I know there is :
break [addr] if ((int)strcmp($r1, "hello")) == 0
But what to set in addr
when I just wanna break when the r1
is "hello"
no matter the address?
Python api in GDB is very convenient to script such solutions. Although the api is a little "wild", I refer to pwndbg on how to use the api. I wrote the following for x86_64 to break only when the first param matches "pol". Full code here
import gdb
class MyBreakpoint (gdb.Breakpoint):
def stop (self):
rdi = int(gdb.parse_and_eval("$rdi").cast(gdb.lookup_type('uint64_t')))
print("x(%x)" % (rdi)),
result = gdb.selected_inferior().read_memory(rdi, 10)
if b'\x00' in result:
result = bytearray(result).split(b'\x00')[0]
if result == b'pol':
return True
return False
MyBreakpoint("x")