每天学点GDB 5
GDB提供了強(qiáng)大的反匯編能力,本節(jié)就圍繞于該主題而展開。
繼續(xù)以Hello.c為例。
#include <stdlib.h> #include <stdio.h>int main(int argc, char** argv) {printf("hello,world\n");return 0; }編譯生成可執(zhí)行文件
gcc -o hello -g hello.c用gdb載入進(jìn)行調(diào)試
gdb hello反匯編main函數(shù)
disassemble main以下為輸出內(nèi)容
Dump of assembler code for function main:0x080483fc <+0>: push %ebp0x080483fd <+1>: mov %esp,%ebp0x080483ff <+3>: and $0xfffffff0,%esp0x08048402 <+6>: sub $0x10,%esp0x08048405 <+9>: movl $0x80484b0,(%esp)0x0804840c <+16>: call 0x80482d0 <puts@plt>0x08048411 <+21>: mov $0x0,%eax0x08048416 <+26>: leave0x08048417 <+27>: ret End of assembler dump.如果留心的話,可能發(fā)現(xiàn)在main函數(shù)中調(diào)用的printf并沒有在反匯編中出現(xiàn)。原因在于printf其實(shí)使用的是puts。
如果已經(jīng)知道了地址,想反過來查看是否對(duì)應(yīng)為某一個(gè)函數(shù)的話,可以使用info symbol指令
info symbol 0x80482d0輸出為
puts@plt in section .plt說明地址0x80482d0對(duì)應(yīng)于函數(shù)puts
與info symbol相對(duì)的指令為info address,可以通過名稱獲得其地址。繼續(xù)為Puts為例
info addr puts輸出為
Symbol "puts" is at 0x80482d0 in a file compiled without debugging.反匯編的另外一種方法就是使用x,當(dāng)程序執(zhí)行后(注意一定是程序運(yùn)行后,停在斷點(diǎn)處時(shí)),可以使用如下指令
x/3i $pc?
?
總結(jié)
- 上一篇: 那些年我用过的开源软件、框架
- 下一篇: 摘: cmd环境 使用一点知识