readelf ELF 文件格式分析
这个工具和objdump命令提供的功能类似,但是它显示的信息更为具体,并且它不依赖BFD库(BFD库是一个GNU项目,它的目标就是希望通过一种统一的接口来处理不同的目标文件);
ELF文件类型
ELF(Executable and Linking Format)是一种对象文件的格式,用于定义不同类型的对象文件(Object files)中都放了什么东西、以及都以什么样的格式去放这些东西。它自最早在 System V 系统上出现后,被 xNIX 世界所广泛接受,作为缺省的二进制文件格式来使用。可以说,ELF是构成众多xNIX系统的基础之一。
ELF文件有三种类型:
- 可重定位的对象文件(Relocatable file)
由汇编器汇编生成的 .o 文件 - 可执行的对象文件(Executable file)
可执行应用程序 - 可被共享的对象文件(Shared object file)
动态库文件,也即 .so 文件
- .text section 里装载了可执行代码;
- .data section 里面装载了被初始化的数据;
- .bss section 里面装载了未被初始化的数据;
- 以 .rec 打头的 sections 里面装载了重定位条目;
- .symtab 或者 .dynsym section 里面装载了符号信息;
- .strtab 或者 .dynstr section 里面装载了字符串信息;
参数说明
- -a --all 全部 Equivalent to: -h -l -S -s -r -d -V -A -I
- -h --file-header 文件头 Display the ELF file header
- -l --program-headers 程序 Display the program headers
- –segments An alias for --program-headers
- -S --section-headers 段头 Display the sections’ header
- –sections An alias for --section-headers
- -e --headers 全部头 Equivalent to: -h -l -S
- -s --syms 符号表 Display the symbol table
- –symbols An alias for --syms
- -n --notes 内核注释 Display the core notes (if present)
- -r --relocs 重定位 Display the relocations (if present)
- -u --unwind Display the unwind info (if present)
- -d --dynamic 动态段 Display the dynamic segment (if present)
- -V --version-info 版本 Display the version sections (if present)
- -A --arch-specific CPU构架 Display architecture specific information (if any).
- -D --use-dynamic 动态段 Use the dynamic section info when displaying symbols
- -x --hex-dump= 显示 段内内容Dump the contents of section
- -w[liaprmfFso] or
- -I --histogram Display histogram of bucket list lengths
- -W --wide 宽行输出 Allow output width to exceed 80 characters
- -H --help Display this information
- -v --version Display the version number of readelf
示例
想知道一个应用程序的可运行的架构平台::
$readelf -h main| grep Machine
-h选项将显示文件头的概要信息,从里面可以看到,有很多有用的信息:
$readelf -h main
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: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1
Entry point address: 0x400790
Start of program headers: 64 (bytes into file)
Start of section headers: 5224 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 29
Section header string table index: 26
一个编译好的应用程序,想知道其编译时是否使用了-g选项(加入调试信息):
$readelf -S main| grep debug
用-S选项是显示所有段信息;如果编译时使用了-g选项,则会有debug段;
查看.o文件是否编入了调试信息(编译的时候是否加了-g)::
$readelf -S Shpos.o | grep debug
完整输出
readelf输出的完整内容:
$readelf -all a.out
ELF Header:Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32Data: 2's complement, little endianVersion: 1 (current)OS/ABI: UNIX - System VABI Version: 0Type: EXEC (Executable file)Machine: Intel 80386Version: 0x1Entry point address: 0x8048330Start of program headers: 52 (bytes into file)Start of section headers: 4412 (bytes into file)Flags: 0x0Size of this header: 52 (bytes)Size of program headers: 32 (bytes)Number of program headers: 9Size of section headers: 40 (bytes)Number of section headers: 30Section header string table index: 27Section Headers:[Nr] Name Type Addr Off Size ES Flg Lk Inf Al[ 0] NULL 00000000 000000 000000 00 0 0 0[ 1] .interp PROGBITS 08048154 000154 000013 00 A 0 0 1[ 2] .note.ABI-tag NOTE 08048168 000168 000020 00 A 0 0 4[ 3] .note.gnu.build-i NOTE 08048188 000188 000024 00 A 0 0 4[ 4] .gnu.hash GNU_HASH 080481ac 0001ac 000020 04 A 5 0 4[ 5] .dynsym DYNSYM 080481cc 0001cc 000050 10 A 6 1 4[ 6] .dynstr STRTAB 0804821c 00021c 00004c 00 A 0 0 1[ 7] .gnu.version VERSYM 08048268 000268 00000a 02 A 5 0 2[ 8] .gnu.version_r VERNEED 08048274 000274 000020 00 A 6 1 4[ 9] .rel.dyn REL 08048294 000294 000008 08 A 5 0 4[10] .rel.plt REL 0804829c 00029c 000018 08 A 5 12 4[11] .init PROGBITS 080482b4 0002b4 00002e 00 AX 0 0 4[12] .plt PROGBITS 080482f0 0002f0 000040 04 AX 0 0 16[13] .text PROGBITS 08048330 000330 00018c 00 AX 0 0 16[14] .fini PROGBITS 080484bc 0004bc 00001a 00 AX 0 0 4[15] .rodata PROGBITS 080484d8 0004d8 000011 00 A 0 0 4[16] .eh_frame_hdr PROGBITS 080484ec 0004ec 000034 00 A 0 0 4[17] .eh_frame PROGBITS 08048520 000520 0000c4 00 A 0 0 4[18] .ctors PROGBITS 08049f14 000f14 000008 00 WA 0 0 4[19] .dtors PROGBITS 08049f1c 000f1c 000008 00 WA 0 0 4[20] .jcr PROGBITS 08049f24 000f24 000004 00 WA 0 0 4[21] .dynamic DYNAMIC 08049f28 000f28 0000c8 08 WA 6 0 4[22] .got PROGBITS 08049ff0 000ff0 000004 04 WA 0 0 4[23] .got.plt PROGBITS 08049ff4 000ff4 000018 04 WA 0 0 4[24] .data PROGBITS 0804a00c 00100c 000008 00 WA 0 0 4[25] .bss NOBITS 0804a014 001014 000008 00 WA 0 0 4[26] .comment PROGBITS 00000000 001014 00002a 01 MS 0 0 1[27] .shstrtab STRTAB 00000000 00103e 0000fc 00 0 0 1[28] .symtab SYMTAB 00000000 0015ec 000410 10 29 45 4[29] .strtab STRTAB 00000000 0019fc 0001f9 00 0 0 1
Key to Flags:W (write), A (alloc), X (execute), M (merge), S (strings)I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)O (extra OS processing required) o (OS specific), p (processor specific)There are no section groups in this file.Program Headers:Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg AlignPHDR 0x000034 0x08048034 0x08048034 0x00120 0x00120 R E 0x4INTERP 0x000154 0x08048154 0x08048154 0x00013 0x00013 R 0x1[Requesting program interpreter: /lib/ld-linux.so.2]LOAD 0x000000 0x08048000 0x08048000 0x005e4 0x005e4 R E 0x1000LOAD 0x000f14 0x08049f14 0x08049f14 0x00100 0x00108 RW 0x1000DYNAMIC 0x000f28 0x08049f28 0x08049f28 0x000c8 0x000c8 RW 0x4NOTE 0x000168 0x08048168 0x08048168 0x00044 0x00044 R 0x4GNU_EH_FRAME 0x0004ec 0x080484ec 0x080484ec 0x00034 0x00034 R 0x4GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4GNU_RELRO 0x000f14 0x08049f14 0x08049f14 0x000ec 0x000ec R 0x1Section to Segment mapping:Segment Sections...00 01 .interp 02 .interp .note.ABI-tag .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame 03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss 04 .dynamic 05 .note.ABI-tag .note.gnu.build-id 06 .eh_frame_hdr 07 08 .ctors .dtors .jcr .dynamic .got Dynamic section at offset 0xf28 contains 20 entries:Tag Type Name/Value0x00000001 (NEEDED) Shared library: [libc.so.6]0x0000000c (INIT) 0x80482b40x0000000d (FINI) 0x80484bc0x6ffffef5 (GNU_HASH) 0x80481ac0x00000005 (STRTAB) 0x804821c0x00000006 (SYMTAB) 0x80481cc0x0000000a (STRSZ) 76 (bytes)0x0000000b (SYMENT) 16 (bytes)0x00000015 (DEBUG) 0x00x00000003 (PLTGOT) 0x8049ff40x00000002 (PLTRELSZ) 24 (bytes)0x00000014 (PLTREL) REL0x00000017 (JMPREL) 0x804829c0x00000011 (REL) 0x80482940x00000012 (RELSZ) 8 (bytes)0x00000013 (RELENT) 8 (bytes)0x6ffffffe (VERNEED) 0x80482740x6fffffff (VERNEEDNUM) 10x6ffffff0 (VERSYM) 0x80482680x00000000 (NULL) 0x0Relocation section '.rel.dyn' at offset 0x294 contains 1 entries:Offset Info Type Sym.Value Sym. Name
08049ff0 00000206 R_386_GLOB_DAT 00000000 __gmon_start__Relocation section '.rel.plt' at offset 0x29c contains 3 entries:Offset Info Type Sym.Value Sym. Name
0804a000 00000107 R_386_JUMP_SLOT 00000000 printf
0804a004 00000207 R_386_JUMP_SLOT 00000000 __gmon_start__
0804a008 00000307 R_386_JUMP_SLOT 00000000 __libc_start_mainThere are no unwind sections in this file.Symbol table '.dynsym' contains 5 entries:Num: Value Size Type Bind Vis Ndx Name0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)2: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__3: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)4: 080484dc 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_usedSymbol table '.symtab' contains 65 entries:Num: Value Size Type Bind Vis Ndx Name0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 08048154 0 SECTION LOCAL DEFAULT 1 2: 08048168 0 SECTION LOCAL DEFAULT 2 3: 08048188 0 SECTION LOCAL DEFAULT 3 4: 080481ac 0 SECTION LOCAL DEFAULT 4 5: 080481cc 0 SECTION LOCAL DEFAULT 5 6: 0804821c 0 SECTION LOCAL DEFAULT 6 7: 08048268 0 SECTION LOCAL DEFAULT 7 8: 08048274 0 SECTION LOCAL DEFAULT 8 9: 08048294 0 SECTION LOCAL DEFAULT 9 10: 0804829c 0 SECTION LOCAL DEFAULT 10 11: 080482b4 0 SECTION LOCAL DEFAULT 11 12: 080482f0 0 SECTION LOCAL DEFAULT 12 13: 08048330 0 SECTION LOCAL DEFAULT 13 14: 080484bc 0 SECTION LOCAL DEFAULT 14 15: 080484d8 0 SECTION LOCAL DEFAULT 15 16: 080484ec 0 SECTION LOCAL DEFAULT 16 17: 08048520 0 SECTION LOCAL DEFAULT 17 18: 08049f14 0 SECTION LOCAL DEFAULT 18 19: 08049f1c 0 SECTION LOCAL DEFAULT 19 20: 08049f24 0 SECTION LOCAL DEFAULT 20 21: 08049f28 0 SECTION LOCAL DEFAULT 21 22: 08049ff0 0 SECTION LOCAL DEFAULT 22 23: 08049ff4 0 SECTION LOCAL DEFAULT 23 24: 0804a00c 0 SECTION LOCAL DEFAULT 24 25: 0804a014 0 SECTION LOCAL DEFAULT 25 26: 00000000 0 SECTION LOCAL DEFAULT 26 27: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c28: 08049f14 0 OBJECT LOCAL DEFAULT 18 __CTOR_LIST__29: 08049f1c 0 OBJECT LOCAL DEFAULT 19 __DTOR_LIST__30: 08049f24 0 OBJECT LOCAL DEFAULT 20 __JCR_LIST__31: 08048360 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux32: 0804a014 1 OBJECT LOCAL DEFAULT 25 completed.608633: 0804a018 4 OBJECT LOCAL DEFAULT 25 dtor_idx.608834: 080483c0 0 FUNC LOCAL DEFAULT 13 frame_dummy35: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c36: 08049f18 0 OBJECT LOCAL DEFAULT 18 __CTOR_END__37: 080485e0 0 OBJECT LOCAL DEFAULT 17 __FRAME_END__38: 08049f24 0 OBJECT LOCAL DEFAULT 20 __JCR_END__39: 08048490 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux40: 00000000 0 FILE LOCAL DEFAULT ABS a.c41: 08049f14 0 NOTYPE LOCAL DEFAULT 18 __init_array_end42: 08049f28 0 OBJECT LOCAL DEFAULT 21 _DYNAMIC43: 08049f14 0 NOTYPE LOCAL DEFAULT 18 __init_array_start44: 08049ff4 0 OBJECT LOCAL DEFAULT 23 _GLOBAL_OFFSET_TABLE_45: 08048480 2 FUNC GLOBAL DEFAULT 13 __libc_csu_fini46: 08048482 0 FUNC GLOBAL HIDDEN 13 __i686.get_pc_thunk.bx47: 0804a00c 0 NOTYPE WEAK DEFAULT 24 data_start48: 00000000 0 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.049: 0804a014 0 NOTYPE GLOBAL DEFAULT ABS _edata50: 080484bc 0 FUNC GLOBAL DEFAULT 14 _fini51: 08049f20 0 OBJECT GLOBAL HIDDEN 19 __DTOR_END__52: 0804a00c 0 NOTYPE GLOBAL DEFAULT 24 __data_start53: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__54: 0804a010 0 OBJECT GLOBAL HIDDEN 24 __dso_handle55: 080484dc 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used56: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_57: 08048410 97 FUNC GLOBAL DEFAULT 13 __libc_csu_init58: 0804a01c 0 NOTYPE GLOBAL DEFAULT ABS _end59: 08048330 0 FUNC GLOBAL DEFAULT 13 _start60: 080484d8 4 OBJECT GLOBAL DEFAULT 15 _fp_hw61: 0804a014 0 NOTYPE GLOBAL DEFAULT ABS __bss_start62: 080483e4 40 FUNC GLOBAL DEFAULT 13 main63: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses64: 080482b4 0 FUNC GLOBAL DEFAULT 11 _initHistogram for `.gnu.hash' bucket list length (total of 2 buckets):Length Number % of total Coverage0 1 ( 50.0%)1 1 ( 50.0%) 100.0%Version symbols section '.gnu.version' contains 5 entries:Addr: 0000000008048268 Offset: 0x000268 Link: 5 (.dynsym)000: 0 (*local*) 2 (GLIBC_2.0) 0 (*local*) 2 (GLIBC_2.0) 004: 1 (*global*) Version needs section '.gnu.version_r' contains 1 entries:Addr: 0x0000000008048274 Offset: 0x000274 Link: 6 (.dynstr)000000: Version: 1 File: libc.so.6 Cnt: 10x0010: Name: GLIBC_2.0 Flags: none Version: 2Notes at offset 0x00000168 with length 0x00000020:Owner Data size DescriptionGNU 0x00000010 NT_GNU_ABI_TAG (ABI version tag)OS: Linux, ABI: 2.6.15Notes at offset 0x00000188 with length 0x00000024:Owner Data size DescriptionGNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring)Build ID: 17fb9651029b6a8543bfafec9eea23bd16454e65
关于ELF文件格式的参考:http://www.cnblogs.com/xmphoenix/archive/2011/10/23/2221879.html
参考
https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/readelf.html
readelf ELF 文件格式分析相关推荐
- 实践2.4 ELF文件格式分析
实践2.4 ELF文件格式分析 1.ELF文件头 查看/usr/include/elf.h文件: #define EI_NIDENT (16)typedef struct {unsigned char ...
- linux ELF文件格式分析
一.ELF文件格式概述 1. ELF:是一种对象文件的格式,用于定义不同类型的对象文件中都放了什么东西.以及都以什么样的格式去放这些东西. 二.分析一个ELF文件 以一个最简单的helloworld程 ...
- linux分析文件格式,linux elf文件格式分析
#include void main() { printf("hello,jinxin!"); } 然后执行: gcc -o jin jin.c readelf -a jin EL ...
- readelf和ldd分析elf文件
1. elf 文件格式 linux系统中,gcc编译器编译出的object文件.可执行文件都属于elf文件. elf文件由三个部分组成:elf header.program headers|secti ...
- android中so文件格式详解,[原创]一 Android ELF系列:ELF文件格式简析到linker的链接so文件原理分析...
Android ELF系列:ELF文件格式简析和linker的链接so文件原理分析 Android ELF系列:实现一个so文件加载器 Android ELF系列:手写一个so文件(包含两个导出函数) ...
- Linux的ELF格式分析
为什么80%的码农都做不了架构师?>>> 第一部分: ELF格式概述 ELF(Executable and Linkable Format)是一种对可执行文件.目标文件以及库文 ...
- Linux内核文件vmlinux 和压缩后的bzImage文件格式分析
Linux内核文件vmlinux 和压缩后的bzImage文件格式分析 ================= 1. 需要使用的命令 ================ readelf -- 显示el ...
- cfile清空文件内容_编译-链接-加载 :ELF文件格式解析
摘要:对于C++的初学者,经常在程序的编译或者加载过程中遇到很多错误,类似undefined reference to ... 和 GLIBCXX_3.4.20 not found 等.这些错误都涉及 ...
- elf文件格式实例解析
试验环境:archlinux 速龙3000+(即x86兼容32位处理器) 必须软件:gcc binutils 参考资料: System V application binary interface E ...
- linux elf文件格式
一.ELF文件格式概述 1. ELF:是一种对象文件的格式,用于定义不同类型的对象文件中都放了什么东西.以及都以什么样的格式去放这些东西. 二.分析一个ELF文件 以一个最简单的hellowor ...
最新文章
- php查找多个字符串替换,php 替换多个字符串
- Hands-On Unity 2018 x 移动游戏开发教程
- python数字排序分组代码_python pandas 组内排序、单组排序、标号的实例
- 即使连网了ping也会失败
- Shadow Brokers扬言兜售新漏洞攻击工具
- ttshop是PHP开发的,商家应该如何选择商城系统?
- 解决gcc version 不匹配问题。
- 【2020团体程序设计天梯赛】L2-3 完全二叉树的层序遍历(后序遍历转层次遍历)
- SaaS行业乘风杨帆,中小企业市场潜力分析
- 从零基础入门Tensorflow2.0 ----六、29keras_generator读取 kaggle 10 monkeys数据
- git cherry-pick 的使用
- shell清空数据库表
- 微信投票python脚本_微信刷票Python脚本教程
- xmr-stak compile
- 向量微积分——理解梯度
- Windows makecert生成代码签名证书
- barebox启动分析(一)
- 基于Python绘制一个摸鱼倒计时界面
- 输入快递单号查询不到物流怎么办
- VMware vRealize Automation 8.6 下载 - 现代基础架构自动化
热门文章
- java 中文网址大全
- windows安装fiddler
- 终于搞定了一个C#的聊天室 使用的SQLServer+VS 用的Socket 整理下搜的书签
- 深入浅出数据分析pdf
- 10年专业导师整理的单片机控制电动机正反转设计类毕业论文文献
- 头歌平台(EduCoder)—— 数据挖掘算法原理与实践:k-近邻
- Mac OS 下创建txt文本文件
- 三星s7250d下载php,HTML5表现令人满意_三星 S7250D(Wave M)_手机其它OS-中关村在线...
- Welcome to Xiao
- python控制电脑定时开机关机软件_用python写一个windows下的定时关机脚本(推荐)