Search code examples
gdbelf

Alloc memory in debugged process


I am attaching a process with ptrace syscall. It is possible to read/write memory with peek and poke but i want to alloc some memory in the remote process. Is it possible to do this ?


Solution

  • i want to alloc some memory in the remote process. Is it possible to do this ?

    Presumably you want to allocate some memory using process's own malloc . Proof by existence:

    (gdb) start
    (gdb) print malloc(20)
    $1 = 0x820430
    

    So yes, it's possible.

    The details are however quite messy: you'll need to read symbol table for the inferior process in order to find where it's malloc is, then construct a proper call frame and transfer control to mallocs address using correct ABI for your target process, and finally clean all of that up.

    This is at least 10x harder than what you asked for in your other recent questions.