gcc命令objdump⽤法----反汇编
gcc命令objdump⽤法
gcc命令之 objdump
---------------objdump是⽤查看⽬标⽂件或者可执⾏的⽬标⽂件的构成的GCC⼯具----------
以下3条命令⾜够那些喜欢探索⽬标⽂件与源代码之间的丝丝的关系的朋友。
objdump -x obj 以某种分类信息的形式把⽬标⽂件的数据组织(被分为⼏⼤块)输出 <;可查到该⽂件的所有动态库>  objdump -t obj 输出⽬标⽂件的符号表()
objdump -h obj 输出⽬标⽂件的所有段概括()
objdump -j .text/.data -S obj 输出指定段的信息,⼤概就是反汇编源代码把
objdump -S obj C语⾔与汇编语⾔同时显⽰
以下为⽹上摘录⽂章。
关于nm -s的显⽰请⾃⼰man nm查看
objdump命令的man⼿册
objdump - 显⽰⼆进制⽂件信息
objdump
[-a] [-b bfdname |
--target=bfdname] [-C] [--debugging]
[-d] [-D]
[--disassemble-zeroes]
[-EB|-EL|--endian={big|little}] [-f]
[-h] [-i|--info]
[-j section | --section=section]
[-l] [-m machine ] [--prefix-addresses]
[-r] [-R]
[-s|--full-contents] [-S|--source]
[--[no-]show-raw-insn] [--stabs] [-t]
[-T] [-x]
[--start-address=address] [--stop-address=address]
[--adjust-vma=offset] [--version] [--help]
<
-a 显⽰档案库的成员信息,与 ar tv 类似
objdump -a libpcap.a
和 ar -tv libpcap.a 显⽰结果⽐较⽐较
显然这个选项没有什么意思。
-
-adjust-vma=offset
When dumping information, first add offset to all
the section addresses. This is useful if the sec-
tion addresses do not correspond to the symbol
table, which can happen when putting sections at
particular addresses when using a format which can
not represent section addresses, such as a.out.
-b bfdname
--target=bfdname
指定⽬标码格式。这不是必须的,objdump能⾃动识别许多格式,
⽐如:objdump -b oasys -m vax -h fu.o
显⽰fu.o的头部摘要信息,明确指出该⽂件是Vax系统下⽤Oasys
编译器⽣成的⽬标⽂件。objdump -i将给出这⾥可以指定的
⽬标码格式列表
--demangle
-C 将底层的符号名解码成⽤户级名字,除了去掉所有开头
的下划线之外,还使得C++函数名以可理解的⽅式显⽰出来。
--debugging
显⽰调试信息。企图解析保存在⽂件中的调试信息并以C语⾔
的语法显⽰出来。仅仅⽀持某些类型的调试信息。
--disassemble
-d 反汇编那些应该还有指令机器码的section
-
-disassemble-all
-D 与 -d 类似,但反汇编所有section
--prefix-addresses
反汇编的时候,显⽰每⼀⾏的完整地址。这是⼀种⽐较⽼的反汇编格式。    显⽰效果并不理想,但可能会⽤到其中的某些显⽰,⾃⼰可以对⽐。
--disassemble-zeroes
⼀般反汇编输出将省略⼤块的零,该选项使得这些零块也被反汇编。
-EB
-EL
--endian={big|little}
这个选项将影响反汇编出来的指令。
little-endian就是我们当年在dos下玩汇编的时候常说的⾼位在⾼地址,    x86都是这种。
--file-headers
-f 显⽰objfile中每个⽂件的整体头部摘要信息。
--section-headers
--headers
-h 显⽰⽬标⽂件各个section的头部摘要信息。
--help 简短的帮助信息。
--info
-i 显⽰对于 -b 或者 -m 选项可⽤的架构和⽬标格式列表。
--section=name
-j name 仅仅显⽰指定section的信息
-l ⽤⽂件名和⾏号标注相应的⽬标代码,仅仅和-d、-D或者-r⼀起使⽤
使⽤-ld和使⽤-d的区别不是很⼤,在源码级调试的时候有⽤,要求
编译时使⽤了-g之类的调试编译选项。
--architecture=machine
-m machine
指定反汇编⽬标⽂件时使⽤的架构,当待反汇编⽂件本⾝没有描述
架构信息的时候(⽐如S-records),这个选项很有⽤。可以⽤-i选项
列出这⾥能够指定的架构
--reloc
-r 显⽰⽂件的重定位⼊⼝。如果和-d或者-D⼀起使⽤,重定位部分以反汇  编后的格式显⽰出来。
--dynamic-reloc
-R 显⽰⽂件的动态重定位⼊⼝,仅仅对于动态⽬标⽂件有意义,⽐如某些  共享库。
-
-full-contents
-s 显⽰指定section的完整内容。
objdump --section=.text -s inet.o | more
--source
-S 尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,  效果⽐较明显。隐含了-d参数。
--show-raw-insn
反汇编的时候,显⽰每条汇编指令对应的机器码,除⾮指定了
--prefix-addresses,这将是缺省选项。
--no-show-raw-insn
反汇编时,不显⽰汇编指令的机器码,这是指定 --prefix-addresses    选项时的缺省设置。
--stabs
Display the contents of the .stab, .stab.index, and
.l sections from an ELF file. This is only
useful on systems (such as Solaris 2.0) in which
.stab debugging symbol-table entries are carried in
an ELF section. In most other file formats, debug-
ging symbol-table entries are interleaved with
linkage symbols, and are visible in the --syms output.
--start-address=address
从指定地址开始显⽰数据,该选项影响-d、-r和-s选项的输出。
--stop-address=address
显⽰数据直到指定地址为⽌,该选项影响-d、-r和-s选项的输出。
-
-syms
-t 显⽰⽂件的符号表⼊⼝。类似于nm -s提供的信息
--dynamic-syms
-T 显⽰⽂件的动态符号表⼊⼝,仅仅对动态⽬标⽂件有意义,⽐如某些  共享库。它显⽰的信息类似于 nm -D|--dynamic 显⽰的信息。
--version 版本信息
objdump --version
--all-headers
-x 显⽰所有可⽤的头信息,包括符号表、重定位⼊⼝。-x 等价于
-a -f -h -r -t 同时指定。
objdump -x inet.o
参看 nm(1)
★ objdump应⽤举例(待增加)
/*
g++ -g -Wstrict-prototypes -Wall -Wunused -o objtest objtest.c */
#include
#include
int main ( int argc, char * argv[] )
{
execl( "/bin/sh", "/bin/sh", "-i", 0 );
return 0;
}
g++ -g -Wstrict-prototypes -Wall -Wunused -o objtest objtest.c objdump -j .text -Sl objtest | more
/
main(查)
08048750:
main():
/home/scz/src/objtest.c:7
*/
#include
#include
int main ( int argc, char * argv[] )
{
8048750:      55                      pushl %ebp
8048751:      89 e5                  movl  %esp,%ebp
/
home/scz/src/objtest.c:8
execl( "/bin/sh", "/bin/sh", "-i", 0 );
8048753:      6a 00                  pushl $0x0
8048755:      68 d0 87 04 08          pushl $0x80487d0 804875a:      68 d3 87 04 08          pushl $0x80487d3 804875f:      68 d3 87 04 08          pushl $0x80487d3 8048764:      e8 db fe ff ff          call  8048644 <_init+0x40> 8048769:      83 c4 10                addl  $0x10,%esp
/home/scz/src/objtest.c:9
return 0;
804876c:      31 c0                  xorl  %eax,%eax
804876e:      eb 04                  jmp    8048774
8048770:      31 c0                  xorl  %eax,%eax
8048772:      eb 00                  jmp    8048774
/home/scz/src/objtest.c:10
}汇编table指令什么意思
8048774:      c9                      leave
8048775:      c3                      ret
8048776:      90                      nop
如果说上⾯还不够清楚,可以⽤下⾯的命令辅助⼀下:
objdump -j .text -Sl objtest --prefix-addresses | more objdump -j .text -Dl objtest | more
⽤以上不同的命令去试会得到惊喜!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。