How to modify memory contents using GDB?

Viewed 173345

I know that we can use several commands to access and read memory: for example, print, p, x...

But how can I change the contents of memory at any specific location (while debugging in GDB)?

5 Answers

One of the most useful things is to change the value of Registers directly.

 0x000000000800088e <+67>:    lea    rdi,[rip+0x118]        # 0x80009ad

To change the value of rdi register:

 set $rdi = 0x8201010

Writing memory:

(gdb) set *0x20001234 = 0xABABABAB

Reading memory:

(gdb) x 0x20001234
0x20001234:     0xabababab
Related