每天学点GDB 5
GDB提供了強大的反匯編能力,本節就圍繞于該主題而展開。
繼續以Hello.c為例。
#include <stdlib.h> #include <stdio.h>int main(int argc, char** argv) {printf("hello,world\n");return 0; }編譯生成可執行文件
gcc -o hello -g hello.c用gdb載入進行調試
gdb hello反匯編main函數
disassemble main以下為輸出內容
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.如果留心的話,可能發現在main函數中調用的printf并沒有在反匯編中出現。原因在于printf其實使用的是puts。
如果已經知道了地址,想反過來查看是否對應為某一個函數的話,可以使用info symbol指令
info symbol 0x80482d0輸出為
puts@plt in section .plt說明地址0x80482d0對應于函數puts
與info symbol相對的指令為info address,可以通過名稱獲得其地址。繼續為Puts為例
info addr puts輸出為
Symbol "puts" is at 0x80482d0 in a file compiled without debugging.反匯編的另外一種方法就是使用x,當程序執行后(注意一定是程序運行后,停在斷點處時),可以使用如下指令
x/3i $pc?
?
總結
- 上一篇: 那些年我用过的开源软件、框架
- 下一篇: 摘: cmd环境 使用一点知识