Can gdb make a function pointer point to another location?

前端 未结 10 1409
庸人自扰
庸人自扰 2020-12-23 14:47

I\'ll explain:

Let\'s say I\'m interested in replacing the rand() function used by a certain application.

So I attach gdb to this process and ma

10条回答
  •  执笔经年
    2020-12-23 15:10

    For executables you can easily find the address where the function pointer is stored by using objdump. For example:

    objdump -R /bin/bash | grep write
    00000000006db558 R_X86_64_JUMP_SLOT  fwrite
    00000000006db5a0 R_X86_64_JUMP_SLOT  write
    

    Therefore, 0x6db5a0 is the adress of the pointer for write. If you change it, calls to write will be redirected to your chosen function. Loading new libraries in gdb and getting function pointers has been covered in earlier posts. The executable and every library have their own pointers. Replacing affects only the module whose pointer was changed.

    For libraries, you need to find the base address of the library and add it to the address given by objdump. In Linux, /proc//maps gives it out. I don't know whether position-independent executables with address randomization would work. maps-information might be unavailable in such cases.

提交回复
热议问题