Search code examples
cdebugginggdbheap-memoryubuntu-14.04

How to per-write a value in certain heap address?


I am using GDB(peda-gdb) to debug a program, can I write something in a heap address so when the program reach that address It can read it out? I know the address but I do not know how to write something in that address. Thanks.


Solution

  • You can write to the heap using C syntax, with commands that evaluate an expression like print or set var. For example, to write an integer value to a specific location:

    (gdb) set var *(int *)0xYOURADDR = 23