Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify char* in GDB while debugging

While I debug with GDB I can print string:

x/s $r0

The output is

IDog123456

I want to change the value so when I print x/s $r0 I will see

ICat45555

I have tried to :

set $r0+1 ={int} 0x43617434 #Cat4
set $r0+5 ={int} 0x35353535 #5555

But it doesn't work , How can I do that without malloc ? only with hex string please?

like image 844
vtable Avatar asked Feb 14 '26 20:02

vtable


1 Answers

Generally, the gdb expression parser operates similar to the current language, so, in the above, when you write:

set $r0+1 ={int} 0x43617434 #Cat4

The left hand side is an integer constant, which can't be assigned to.

Instead, you should write this as you would in C:

set *($r0+1) = (int) 0x43617434

Which should do the job.

Sometime, you might end up needing to cast the pointer of the LHS too, like this:

set *((int *) ($r0+1)) = (int) 0x43617434

But I suspect in your case you'll be OK.

like image 156
Andrew Avatar answered Feb 16 '26 10:02

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!