然后连接gdbserver开始调试。之前在《Android ELF文件PLT和GOT》说明了如何寻找某个函数对应的GOT表项,这里不再详细说明。在我的环境下,add函数GOT表项的地址为0x2a001ff4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
(gdb) target remote :11111
Remote debugging using :11111
(gdb) b add
# 在add函数下断点
(gdb) c
Continuing.
Breakpoint 6, 0x40072384
in
add ()
(gdb) p
/x
*0x2a001ff4
$4 = 0x40072385
# GOT表中的内容为add的地址加1
(gdb) p multiply
$5 = {<text variable, no debug info>} 0x4007238c <multiply>
(gdb)
set
*0x2a001ff4=0x4007238d
# 修改为multiply的地址加1
(gdb) c
Continuing.
Program exited normally.
|
然后在gdbserver端的输出如下:
5 + 5 = 10 5 + 5 = 25 Child exited with status 0 GDBserver exiting
可以看到,add函数已经被multiply函数所替代,输出了5 * 5的结果。
至于为何GOT表中存储的是函数的真实地址加1(一开始没注意要加1,修改GOT表项后总是出现段错误),我目前还没有搞清楚原因,还需进一步研究。