了解ELF的文件格式可通过SO(ELF)文件格式详解
通过命令greadelf -a xxx.so和gobjdump -x xxx.so以及readelf这三个命令得到so的信息
我个人常用readelf命令,具体指令的使用可参考readelf命令使用说明
命令安装和配置
运行下述命令:
brew update
brew install binutils
执行安装命令 brew install binutils,控制台会打印如下信息
If you need to have binutils first in your PATH run:
echo 'export PATH="/usr/local/opt/binutils/bin:$PATH"' >> ~/.bash_profile
配置Mac环境变量即可
vi ~/.bash_profile 添加path即可
source ~/.bash_profile 命令生效
执行结果预览
以armeabi-v7a包下的声网 libagora-rtc-sdk-jni.so 为例
具体指令可安装之后输入对应的命令,查看命令行提示自行选用,个人常用
-h --file-header Display the ELF file header
-a --all Equivalent to: -h -l -S -s -r -d -V -A -I
readelf -h libagora-rtc-sdk-jni.so
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 9480288 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 28
Section header string table index: 27
greadelf -a libagora-rtc-sdk-jni.so
ELF Header:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: ARM (x86的此处为 Intel 80386)
Version: 0x1
Entry point address: 0x0
Start of program headers: 52 (bytes into file)
Start of section headers: 9480288 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 28
Section header string table index: 27
Section Headers:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .note.androi[...] NOTE 00000134 000134 000098 00 A 0 0 4
[ 2] .note.gnu.bu[...] NOTE 000001cc 0001cc 000024 00 A 0 0 4
[ 3] .dynsym DYNSYM 000001f0 0001f0 00d440 10 A 4 1 4
[ 4] .dynstr STRTAB 0000d630 00d630 01fb31 00 A 0 0 1
[ 5] .hash HASH 0002d164 02d164 00552c 04 A 3 0 4
[ 6] .gnu.version VERSYM 00032690 032690 001a88 02 A 3 0 2
[ 7] .gnu.version_d VERDEF 00034118 034118 00001c 00 A 4 1 4
[ 8] .gnu.version_r VERNEED 00034134 034134 000060 00 A 4 3 4
[ 9] .rel.dyn REL 00034194 034194 04ceb8 08 A 3 0 4
[10] .rel.plt REL 0008104c 08104c 000a68 08 AI 3 21 4
[11] .plt PROGBITS 00081ab4 081ab4 000fb0 00 AX 0 0 4
[12] .text PROGBITS 00082a70 082a70 5b579c 00 AX 0 0 16
[13] .ARM.exidx ARM_EXIDX 0063820c 63820c 0433e0 08 AL 12 0 4
[14] .ARM.extab PROGBITS 0067b5ec 67b5ec 04b270 00 A 0 0 4
[15] .rodata PROGBITS 006c6860 6c6860 1360fc 00 A 0 0 16
[16] .data.rel.ro[...] PROGBITS 007fdde0 7fcde0 000b24 00 WA 0 0 8
[17] .fini_array FINI_ARRAY 007fe904 7fd904 00000c 04 WA 0 0 4
[18] .data.rel.ro PROGBITS 007fe910 7fd910 046970 00 WA 0 0 16
[19] .init_array INIT_ARRAY 00845280 844280 000150 04 WA 0 0 4
[20] .dynamic DYNAMIC 008453d0 8443d0 000140 08 WA 4 0 4
[21] .got PROGBITS 00845514 844514 002aec 00 WA 0 0 4
[22] .data PROGBITS 00848000 847000 0c357c 00 WA 0 0 16
[23] .bss NOBITS 0090b580 90a57c 122718 00 WA 0 0 16
[24] .comment PROGBITS 00000000 90a57c 000163 01 MS 0 0 1
[25] .note.gnu.go[...] NOTE 00000000 90a6e0 00001c 00 0 0 4
[26] .ARM.attributes ARM_ATTRIBUTES 00000000 90a6fc 00003a 00 0 0 1
[27] .shstrtab STRTAB 00000000 90a736 00012a 00 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),
y (purecode), p (processor specific)There are no section groups in this file.
gobjdump -x libagora-rtc-sdk-jni.so
ibagora-rtc-sdk.so: file format elf32-littlearm
libagora-rtc-sdk.so
architecture: armv7, flags 0x00000150:
HAS_SYMS, DYNAMIC, D_PAGED
start address 0x00000000Program Header:
PHDR off 0x00000034 vaddr 0x00000034 paddr 0x00000034 align 22
filesz 0x00000100 memsz 0x00000100 flags r--
LOAD off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 212
filesz 0x007fc95c memsz 0x007fc95c flags r-x
LOAD off 0x007fcde0 vaddr 0x007fdde0 paddr 0x007fdde0 align 212
filesz 0x0010d79c memsz 0x0022feb8 flags rw-
DYNAMIC off 0x008443d0 vaddr 0x008453d0 paddr 0x008453d0 align 22
filesz 0x00000140 memsz 0x00000140 flags rw-
NOTE off 0x00000134 vaddr 0x00000134 paddr 0x00000134 align 22
filesz 0x000000bc memsz 0x000000bc flags r--
STACK off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 24
filesz 0x00000000 memsz 0x00000000 flags rw-
0x70000001 off 0x0063820c vaddr 0x0063820c paddr 0x0063820c align 22
filesz 0x000433e0 memsz 0x000433e0 flags r--
RELRO off 0x007fcde0 vaddr 0x007fdde0 paddr 0x007fdde0 align 24
filesz 0x0004a220 memsz 0x0004a220 flags rw-Dynamic Section:
PLTGOT 0x00847ac0
PLTRELSZ 0x00000a68
JMPREL 0x0008104c
PLTREL 0x00000011
REL 0x00034194
RELSZ 0x0004ceb8
RELENT 0x00000008
RELCOUNT 0x0000999e
SYMTAB 0x000001f0
SYMENT 0x00000010
STRTAB 0x0000d630
STRSZ 0x0001fb31
HASH 0x0002d164
NEEDED libOpenSLES.so
NEEDED libEGL.so
NEEDED libGLESv1_CM.so
NEEDED libGLESv2.so
NEEDED libdl.so
NEEDED libm.so
NEEDED liblog.so
NEEDED libc.so
SONAME libagora-rtc-sdk.so
FINI_ARRAY 0x007fe904
FINI_ARRAYSZ 0x0000000c
INIT_ARRAY 0x00845280
INIT_ARRAYSZ 0x00000150
SYMBOLIC 0x00000000
FLAGS 0x0000000a
FLAGS_1 0x00000001
VERSYM 0x00032690
VERDEF 0x00034118
VERDEFNUM 0x00000001
VERNEED 0x00034134
VERNEEDNUM 0x00000003Version definitions:
1 0x01 0x0e4641cf libagora-rtc-sdk.soVersion References:
required from libc.so:
0x00050d63 0x00 02 LIBC
required from libm.so:
0x00050d63 0x00 03 LIBC
required from libdl.so:
0x00050d63 0x00 04 LIBC
private flags = 0x5000200: [Version5 EABI] [soft-float ABI]Sections:
Idx Name Size VMA LMA File off Algn
0 .note.android.ident 00000098 00000134 00000134 00000134 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.gnu.build-id 00000024 000001cc 000001cc 000001cc 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .dynsym 0000d440 000001f0 000001f0 000001f0 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .dynstr 0001fb31 0000d630 0000d630 0000d630 20
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .hash 0000552c 0002d164 0002d164 0002d164 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .gnu.version 00001a88 00032690 00032690 00032690 21
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .gnu.version_d 0000001c 00034118 00034118 00034118 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .gnu.version_r 00000060 00034134 00034134 00034134 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .rel.dyn 0004ceb8 00034194 00034194 00034194 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .rel.plt 00000a68 0008104c 0008104c 0008104c 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .plt 00000fb0 00081ab4 00081ab4 00081ab4 22
CONTENTS, ALLOC, LOAD, READONLY, CODE
11 .text 005b579c 00082a70 00082a70 00082a70 24
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .ARM.exidx 000433e0 0063820c 0063820c 0063820c 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
13 .ARM.extab 0004b270 0067b5ec 0067b5ec 0067b5ec 22
CONTENTS, ALLOC, LOAD, READONLY, DATA
14 .rodata 001360fc 006c6860 006c6860 006c6860 24
CONTENTS, ALLOC, LOAD, READONLY, DATA
15 .data.rel.ro.local 00000b24 007fdde0 007fdde0 007fcde0 23
CONTENTS, ALLOC, LOAD, DATA
16 .fini_array 0000000c 007fe904 007fe904 007fd904 22
CONTENTS, ALLOC, LOAD, DATA
17 .data.rel.ro 00046970 007fe910 007fe910 007fd910 24
CONTENTS, ALLOC, LOAD, DATA
18 .init_array 00000150 00845280 00845280 00844280 22
CONTENTS, ALLOC, LOAD, DATA
19 .dynamic 00000140 008453d0 008453d0 008443d0 22
CONTENTS, ALLOC, LOAD, DATA
20 .got 00002aec 00845514 00845514 00844514 22
CONTENTS, ALLOC, LOAD, DATA
21 .data 000c357c 00848000 00848000 00847000 24
CONTENTS, ALLOC, LOAD, DATA
22 .bss 00122718 0090b580 0090b580 0090a57c 24
ALLOC
23 .comment 00000163 00000000 00000000 0090a57c 20
CONTENTS, READONLY
24 .note.gnu.gold-version 0000001c 00000000 00000000 0090a6e0 22
CONTENTS, READONLY, OCTETS
25 .ARM.attributes 0000003a 00000000 00000000 0090a6fc 20
CONTENTS, READONLY
SYMBOL TABLE:
no symbols