readelf 是一个用于解析和显示 ELF(Executable and Linkable Format)文件信息的工具。ELF 是一种常见的二进制文件格式,广泛用于 Unix 和类 Unix 系统(如 Linux)中的可执行文件、目标文件、共享库和核心转储文件。
- 解析 ELF 文件头部信息,包括文件类型、架构、版本等
- 显示节头表(Section Header Table)信息
- 解析程序头表(Program Header Table)内容
- 展示符号表(Symbol Table)条目
- 支持多种 ELF 文件类型分析
-
克隆仓库:
git clone https://github.com/RainLumosTaipei/readelf.git cd readelf -
编译项目:
make
基本用法:
readelf [选项] <ELF文件>常用选项:
-h:显示 ELF 文件头部信息-l:显示程序头表(段信息)-S:显示节头表-s:显示符号表-d:显示动态节信息-a:显示所有可获得的信息
示例:
# 显示文件头部信息
readelf -h ./a.out
# 显示所有节信息
readelf -S ./libexample.so
# 显示所有信息
readelf -a ./myprogram$ readelf misc/hello.elf
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Position-Independent Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x1040
Start of program headers: 64 (bytes into file)
Start of section headers: 13920 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 13
Size of section headers: 64 (bytes)
Number of section headers: 29
Section header string table index: 28
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 0000000000000318 00000318
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.gnu.proper NOTE 0000000000000338 00000338
0000000000000030 0000000000000000 A 0 0 8
[ 3] .note.gnu.build- NOTE 0000000000000368 00000368
0000000000000024 0000000000000000 A 0 0 4
[ 4] .note.ABI-tag NOTE 000000000000038c 0000038c
0000000000000020 0000000000000000 A 0 0 4
[ 5] .gnu.hash GNU_HASH 00000000000003b0 000003b0
0000000000000024 0000000000000000 A 6 0 8
[ 6] .dynsym DYNSYM 00000000000003d8 000003d8
0000000000000090 0000000000000018 A 7 1 8
[ 7] .dynstr STRTAB 0000000000000468 00000468
0000000000000088 0000000000000000 A 0 0 1
[ 8] .gnu.version GNU_VERSYM 00000000000004f0 000004f0
000000000000000c 0000000000000002 A 6 0 2
[ 9] .gnu.version_r GNU_VERNEED 0000000000000500 00000500
0000000000000030 0000000000000000 A 7 1 8
[10] .rela.dyn RELA 0000000000000530 00000530
00000000000000c0 0000000000000018 A 6 0 8
[11] .init PROGBITS 0000000000001000 00001000
000000000000001b 0000000000000000 AE 0 0 4
[12] .plt PROGBITS 0000000000001020 00001020
0000000000000010 0000000000000010 AE 0 0 16
[13] .plt.got PROGBITS 0000000000001030 00001030
0000000000000010 0000000000000010 AE 0 0 16
[14] .text PROGBITS 0000000000001040 00001040
000000000000010c 0000000000000000 AE 0 0 16
[15] .fini PROGBITS 000000000000114c 0000114c
000000000000000d 0000000000000000 AE 0 0 4
[16] .rodata PROGBITS 0000000000002000 00002000
0000000000000010 0000000000000000 A 0 0 8
[17] .eh_frame_hdr PROGBITS 0000000000002010 00002010
000000000000002c 0000000000000000 A 0 0 4
[18] .eh_frame PROGBITS 0000000000002040 00002040
0000000000000094 0000000000000000 A 0 0 8
[19] .init_array INIT_ARRAY 0000000000003df0 00002df0
0000000000000008 0000000000000008 WA 0 0 8
[20] .fini_array FINI_ARRAY 0000000000003df8 00002df8
0000000000000008 0000000000000008 WA 0 0 8
[21] .dynamic DYNAMIC 0000000000003e00 00002e00
00000000000001c0 0000000000000010 WA 7 0 8
[22] .got PROGBITS 0000000000003fc0 00002fc0
0000000000000040 0000000000000008 WA 0 0 8
[23] .data PROGBITS 0000000000004000 00003000
0000000000000010 0000000000000000 WA 0 0 8
[24] .bss NOBITS 0000000000004010 00003010
0000000000000008 0000000000000000 WA 0 0 1
[25] .comment PROGBITS 0000000000000000 00003010
000000000000002b 0000000000000001 MS 0 0 1
[26] .symtab SYMTAB 0000000000000000 00003040
0000000000000348 0000000000000018 27 18 8
[27] .strtab STRTAB 0000000000000000 00003388
00000000000001cc 0000000000000000 0 0 1
[28] .shstrtab STRTAB 0000000000000000 00003554
000000000000010c 0000000000000000 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
D (mbind), l (large), p (processor specific)
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
PHDR 0x0000000000000040 0x0000000000000040 0x0000000000000040
0x00000000000002d8 0x00000000000002d8 R 0x8
INTERP 0x0000000000000318 0x0000000000000318 0x0000000000000318
0x000000000000001c 0x000000000000001c R 0x1
LOAD 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000000005f0 0x00000000000005f0 R 0x1000
LOAD 0x0000000000001000 0x0000000000001000 0x0000000000001000
0x0000000000000159 0x0000000000000159 R E 0x1000
LOAD 0x0000000000002000 0x0000000000002000 0x0000000000002000
0x00000000000000d4 0x00000000000000d4 R 0x1000
LOAD 0x0000000000002df0 0x0000000000003df0 0x0000000000003df0
0x0000000000000220 0x0000000000000228 RW 0x1000
DYNAMIC 0x0000000000002e00 0x0000000000003e00 0x0000000000003e00
0x00000000000001c0 0x00000000000001c0 RW 0x8
NOTE 0x0000000000000338 0x0000000000000338 0x0000000000000338
0x0000000000000030 0x0000000000000030 R 0x8
NOTE 0x0000000000000368 0x0000000000000368 0x0000000000000368
0x0000000000000044 0x0000000000000044 R 0x4
GNU_PROPERTY 0x0000000000000338 0x0000000000000338 0x0000000000000338
0x0000000000000030 0x0000000000000030 R 0x8
GNU_EH_FRAME 0x0000000000002010 0x0000000000002010 0x0000000000002010
0x000000000000002c 0x000000000000002c R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10
GNU_RELRO 0x0000000000002df0 0x0000000000003df0 0x0000000000003df0
0x0000000000000210 0x0000000000000210 R 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .note.gnu.property .note.gnu.build-id .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn
03 .init .plt .plt.got .text .fini
04 .rodata .eh_frame_hdr .eh_frame
05 .init_array .fini_array .dynamic .got .data .bss
06 .dynamic
07 .note.gnu.property
08 .note.gnu.build-id .note.ABI-tag
09 .note.gnu.property
10 .eh_frame_hdr
11
12 .init_array .fini_array .dynamic .got
Symbol table '.dynsym' contains 6 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main
2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
5: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize
Symbol table '.symtab' contains 35 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 FILE LOCAL DEFAULT ABS Scrt1.o
2: 000000000000038c 32 OBJECT LOCAL DEFAULT 4 __abi_tag
3: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
4: 0000000000001070 0 FUNC LOCAL DEFAULT 14 deregister_tm_clones
5: 00000000000010a0 0 FUNC LOCAL DEFAULT 14 register_tm_clones
6: 00000000000010e0 0 FUNC LOCAL DEFAULT 14 __do_global_dtors_aux
7: 0000000000004010 1 OBJECT LOCAL DEFAULT 24 completed.0
8: 0000000000003df8 0 OBJECT LOCAL DEFAULT 20 __do_global_dtors_aux_fini_array_entry
9: 0000000000001120 0 FUNC LOCAL DEFAULT 14 frame_dummy
10: 0000000000003df0 0 OBJECT LOCAL DEFAULT 19 __frame_dummy_init_array_entry
11: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.cpp
12: 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
13: 00000000000020d0 0 OBJECT LOCAL DEFAULT 18 __FRAME_END__
14: 0000000000000000 0 FILE LOCAL DEFAULT ABS
15: 0000000000003e00 0 OBJECT LOCAL DEFAULT 21 _DYNAMIC
16: 0000000000002010 0 NOTYPE LOCAL DEFAULT 17 __GNU_EH_FRAME_HDR
17: 0000000000003fc0 0 OBJECT LOCAL DEFAULT 22 _GLOBAL_OFFSET_TABLE_
18: 0000000000000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.34
19: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
20: 0000000000004000 0 NOTYPE WEAK DEFAULT 23 data_start
21: 0000000000004010 0 NOTYPE GLOBAL DEFAULT 23 _edata
22: 000000000000114c 0 FUNC GLOBAL HIDDEN 15 _fini
23: 0000000000004000 0 NOTYPE GLOBAL DEFAULT 23 __data_start
24: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
25: 0000000000004008 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
26: 0000000000002000 4 OBJECT GLOBAL DEFAULT 16 _IO_stdin_used
27: 0000000000004018 0 NOTYPE GLOBAL DEFAULT 24 _end
28: 0000000000001040 38 FUNC GLOBAL DEFAULT 14 _start
29: 0000000000004010 0 NOTYPE GLOBAL DEFAULT 24 __bss_start
30: 0000000000001129 35 FUNC GLOBAL DEFAULT 14 main
31: 0000000000004010 0 OBJECT GLOBAL HIDDEN 23 __TMC_END__
32: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
33: 0000000000000000 0 FUNC WEAK DEFAULT UND __cxa_finalize@GLIBC_2.2.5
34: 0000000000001000 0 FUNC GLOBAL HIDDEN 11 _init