原文:http://blog.csdn.net/zoomdy/article/details/50563680
- -d:将代码段反汇编
- -S:将代码段反汇编的同时,将反汇编代码和源代码交替显示,编译时需要给出-g,即需要调试信息。
- -C:将C++符号名逆向解析。
- -l:反汇编代码中插入源代码的文件名和行号。
- -j section:仅反汇编指定的section。可以有多个-j参数来选择多个section。
有代码如下:
class Main
{
int a;
public:
Main()
{
a = 0;
}
int getA(void)
{
return this->a;
}
};
$objdump -d a.out # 简单反汇编
08048456 <_ZN4MainC1Ev>:
8048456: 55 push %ebp
8048457: 89 e5 mov %esp,%ebp
8048459: 8b 45 08 mov 0x8(%ebp),%eax
804845c: c7 00 00 00 00 00 movl $0x0,(%eax)
8048462: 5d pop %ebp
8048463: c3 ret
08048464 <_ZN4Main4getAEv>:
8048464: 55 push %ebp
8048465: 89 e5 mov %esp,%ebp
8048467: 8b 45 08 mov 0x8(%ebp),%eax
804846a: 8b 00 mov (%eax),%eax
804846c: 5d pop %ebp
804846d: c3 ret
$objdump -S a.out # 反汇编代码中混入对应的源代码
08048456 <_ZN4MainC1Ev>:
class Main
{
int a;
public:
Main()
8048456: 55 push %ebp
8048457: 89 e5 mov %esp,%ebp
{
a = 0;
8048459: 8b 45 08 mov 0x8(%ebp),%eax
804845c: c7 00 00 00 00 00 movl $0x0,(%eax)
}
8048462: 5d pop %ebp
8048463: c3 ret
08048464 <_ZN4Main4getAEv>:
int getA(void)
8048464: 55 push %ebp
8048465: 89 e5 mov %esp,%ebp
{
return this->a;
8048467: 8b 45 08 mov 0x8(%ebp),%eax
804846a: 8b 00 mov (%eax),%eax
}
804846c: 5d pop %ebp
804846d: c3 ret
$objdump -C -S a.out # C++符号名逆向解析
08048456 <Main::Main()>:
class Main
{
int a;
public:
Main()
8048456: 55 push %ebp
8048457: 89 e5 mov %esp,%ebp
{
a = 0;
8048459: 8b 45 08 mov 0x8(%ebp),%eax
804845c: c7 00 00 00 00 00 movl $0x0,(%eax)
}
8048462: 5d pop %ebp
8048463: c3 ret
08048464 <Main::getA()>:
int getA(void)
8048464: 55 push %ebp
8048465: 89 e5 mov %esp,%ebp
{
return this->a;
8048467: 8b 45 08 mov 0x8(%ebp),%eax
804846a: 8b 00 mov (%eax),%eax
}
804846c: 5d pop %ebp
804846d: c3 ret
objdump -j .text -l -C -S a.out # 打印源文件名和行号
08048456 <Main::Main()>:
_ZN4MainC2Ev():
~/objdump/main.h:5
class Main
{
int a;
public:
Main()
8048456: 55 push %ebp
8048457: 89 e5 mov %esp,%ebp
~/objdump/main.h:7
{
a = 0;
8048459: 8b 45 08 mov 0x8(%ebp),%eax
804845c: c7 00 00 00 00 00 movl $0x0,(%eax)
~/objdump/main.h:8
}
8048462: 5d pop %ebp
8048463: c3 ret
08048464 <Main::getA()>:
_ZN4Main4getAEv():
~/objdump/main.h:10
int getA(void)
8048464: 55 push %ebp
8048465: 89 e5 mov %esp,%ebp
~/objdump/main.h:12
{
return this->a;
8048467: 8b 45 08 mov 0x8(%ebp),%eax
804846a: 8b 00 mov (%eax),%eax
~/objdump/main.h:13
}
804846c: 5d pop %ebp
804846d: c3 ret