我正在嘗試查找ELF文件的基地址。我知道你可以使用readelf來找到程序入口點和不同部分的細節(基地址,大小,標誌等等)。ELF的基址地址
例如,x86體系結構的程序基於鏈接器的0x8048000。使用readelf我可以看到程序入口點,但輸出中沒有特定的字段告訴基地址。
$ readelf -e test
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: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048390
Start of program headers: 52 (bytes into file)
Start of section headers: 4436 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section 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 000024 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481d0 0001d0 000070 10 A 6 1 4
在部分細節,我可以看到,該偏移量是相對於所述ELF的基地址計算。
因此,.dynsym段開始於地址0x080481d0,偏移量爲0x1d0。這意味着基地址是0x08048000。它是否正確?
同樣,對於像PPC,ARM,MIPS等不同體系結構編譯的程序,我看不到它們的基地址,但只能看到OEP,Section Headers。
[爲什麼Linux/GNU鏈接器選擇地址0x400000?](http://stackoverflow.com/questions/14314021/why-linux-gnu-linker-chose-address-0x400000) – andrewrk