工具篇·objdump
objdump 命令是 GNU Binutils 二进制工具集的一员,用于查看目标文件或可执行文件的组成信息,以可读的形式打印二进制文件的内容。objdump [options] obj_file #[]表示可选,obj_file表示目标文件
常用
objdump -T libc.so.6 |grep system
objdump参数
-a, --archive-headers |
操作
1.查看C程序的汇编代码和源代码
gcc -g test.c -o test |
|
objdump -D test | less #objdump -D命令来查看test的汇编代码。 |
2.查看可执行文件中函数调用的地址
可以使用以下命令来查看可执行文件中的函数调用地址:objdump -d -j .plt test
3.查看共享库中函数的地址
可以使用以下命令来查看共享库中函数的地址:objdump -T /lib/libc.so.6
4.查看可执行文件中的符号表
objdump -t test |
可以在符号表中找到sub,add的地址#objdump -t test
test: file format elf64-x86-64
SYMBOL TABLE:
0000000000400238 l d .interp 0000000000000000 .interp
0000000000400254 l d .note.ABI-tag 0000000000000000 .note.ABI-tag
0000000000400274 l d .note.gnu.build-id 0000000000000000 .note.gnu.build-id
0000000000400298 l d .gnu.hash 0000000000000000 .gnu.hash
00000000004002b8 l d .dynsym 0000000000000000 .dynsym
0000000000400318 l d .dynstr 0000000000000000 .dynstr
0000000000400358 l d .gnu.version 0000000000000000 .gnu.version
0000000000400360 l d .gnu.version_r 0000000000000000 .gnu.version_r
0000000000400380 l d .rela.dyn 0000000000000000 .rela.dyn
0000000000400398 l d .rela.plt 0000000000000000 .rela.plt
00000000004003c8 l d .init 0000000000000000 .init
00000000004003f0 l d .plt 0000000000000000 .plt
0000000000400420 l d .plt.got 0000000000000000 .plt.got
0000000000400430 l d .text 0000000000000000 .text
0000000000400634 l d .fini 0000000000000000 .fini
0000000000400640 l d .rodata 0000000000000000 .rodata
0000000000400678 l d .eh_frame_hdr 0000000000000000 .eh_frame_hdr
00000000004006c0 l d .eh_frame 0000000000000000 .eh_frame
0000000000600e10 l d .init_array 0000000000000000 .init_array
0000000000600e18 l d .fini_array 0000000000000000 .fini_array
0000000000600e20 l d .jcr 0000000000000000 .jcr
0000000000600e28 l d .dynamic 0000000000000000 .dynamic
0000000000600ff8 l d .got 0000000000000000 .got
0000000000601000 l d .got.plt 0000000000000000 .got.plt
0000000000601028 l d .data 0000000000000000 .data
000000000060102c l d .bss 0000000000000000 .bss
0000000000000000 l d .comment 0000000000000000 .comment
0000000000000000 l df *ABS* 0000000000000000 crtstuff.c
0000000000600e20 l O .jcr 0000000000000000 __JCR_LIST__
0000000000400460 l F .text 0000000000000000 deregister_tm_clones
0000000000400490 l F .text 0000000000000000 register_tm_clones
00000000004004d0 l F .text 0000000000000000 __do_global_dtors_aux
000000000060102c l O .bss 0000000000000001 completed.6355
0000000000600e18 l O .fini_array 0000000000000000 __do_global_dtors_aux_fini_array_entry
00000000004004f0 l F .text 0000000000000000 frame_dummy
0000000000600e10 l O .init_array 0000000000000000 __frame_dummy_init_array_entry
0000000000000000 l df *ABS* 0000000000000000 test.c
0000000000000000 l df *ABS* 0000000000000000 crtstuff.c
00000000004007f0 l O .eh_frame 0000000000000000 __FRAME_END__
0000000000600e20 l O .jcr 0000000000000000 __JCR_END__
0000000000000000 l df *ABS* 0000000000000000
0000000000600e18 l .init_array 0000000000000000 __init_array_end
0000000000600e28 l O .dynamic 0000000000000000 _DYNAMIC
0000000000600e10 l .init_array 0000000000000000 __init_array_start
0000000000400678 l .eh_frame_hdr 0000000000000000 __GNU_EH_FRAME_HDR
0000000000601000 l O .got.plt 0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000400630 g F .text 0000000000000002 __libc_csu_fini
0000000000601028 w .data 0000000000000000 data_start
000000000040051d g F .text 0000000000000014 add
000000000060102c g .data 0000000000000000 _edata
0000000000400634 g F .fini 0000000000000000 _fini
0000000000000000 F *UND* 0000000000000000 printf@@GLIBC_2.2.5
0000000000000000 F *UND* 0000000000000000 __libc_start_main@@GLIBC_2.2.5
0000000000601028 g .data 0000000000000000 __data_start
0000000000000000 w *UND* 0000000000000000 __gmon_start__
0000000000400648 g O .rodata 0000000000000000 .hidden __dso_handle
0000000000400640 g O .rodata 0000000000000004 _IO_stdin_used
00000000004005c0 g F .text 0000000000000065 __libc_csu_init
0000000000601030 g .bss 0000000000000000 _end
0000000000400430 g F .text 0000000000000000 _start
000000000060102c g .bss 0000000000000000 __bss_start
0000000000400547 g F .text 0000000000000070 main
0000000000601030 g O .data 0000000000000000 .hidden __TMC_END__
0000000000400531 g F .text 0000000000000016 sub
00000000004003c8 g F .init 0000000000000000 _init
5.查看.o文件的信息
objdump -h test.o |
![[Pasted image 20250124143403.png]]
接着可以用nm查看函数和全局变量,静态变量[root@localhost test]# nm test.o
0000000000000000 T add
000000000000002a T main
U printf
0000000000000014 T sub
局部变量不会生成符号,最终是分配在栈内存中,不会在函数外部被引用
