赞
踩
Linux下ELF文件类型分为以下几种:
1、可重定位文件,例如SimpleSection.o;
2、可执行文件,例如/bin/bash;
3、共享目标文件,例如/lib/libc.so。
在Linux 可重定位文件 ELF结构一文中,我们已经分析了可重定位文件ELF结构。本文分析可执行文件的ELF结构。
首先附上源代码:
SectionMapping.c
- #include <stdlib.h>
-
- int main()
- {
- while(1)
- {
- sleep(1000);
- }
- return 0;
- }
使用命令gcc -static SectionMapping.c -o SectionMapping.elf,静态链接为可执行文件。
接着使用命令readelf -S SectionMapping.elf得到Section Table。如下:
There are 33 section headers, starting at offset 0xc3878:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .note.ABI-tag NOTE 0000000000400190 00000190
0000000000000020 0000000000000000 A 0 0 4
[ 2] .note.gnu.build-i NOTE 00000000004001b0 000001b0
0000000000000024 0000000000000000 A 0 0 4
[ 3] .rela.plt RELA 00000000004001d8 000001d8
0000000000000120 0000000000000018 A 0 5 8
[ 4] .init PROGBITS 00000000004002f8 000002f8
0000000000000018 0000000000000000 AX 0 0 4
[ 5] .plt PROGBITS 0000000000400310 00000310
00000000000000c0 0000000000000000 AX 0 0 16
[ 6] .text PROGBITS 00000000004003d0 000003d0
0000000000094988 0000000000000000 AX 0 0 16
[ 7] __libc_thread_fre PROGBITS 0000000000494d60 00094d60
00000000000000a8 0000000000000000 AX 0 0 16
[ 8] __libc_freeres_fn PROGBITS 0000000000494e10 00094e10
000000000000181c 0000000000000000 AX 0 0 16
[ 9] .fini PROGBITS 000000000049662c 0009662c
000000000000000e 0000000000000000 AX 0 0 4
[10] .rodata PROGBITS 0000000000496640 00096640
000000000001d344 0000000000000000 A 0 0 32
[11] __libc_thread_sub PROGBITS 00000000004b3988 000b3988
0000000000000008 0000000000000000 A 0 0 8
[12] __libc_subfreeres PROGBITS 00000000004b3990 000b3990
0000000000000058 0000000000000
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。