2017-01-09 35 views
0

我開發了一個簡單的pintool來列出該程序的主要可執行映像的所有部分(迭代所有部分),以及使用IMG_HighAddressIMG_LowAddress的低限和高限;根據Pin,這些返回圖像的一定限制。段地址超出圖像區域 - 英特爾銷

令我驚訝的是,該段就遠遠超出這些函數報道的下限和上限。我做錯了什麼,還是這些功能不準確?

我的圖像加載功能:

VOID ImageLoad(IMG img, VOID *v) 
{ 

if (!IMG_IsMainExecutable(img)) 
    return; 

ADDRINT mainExeImageLowAddr = IMG_LowAddress(img); 
ADDRINT mainExeImageHighAddr = IMG_HighAddress(img);  

cout << "Image limits " << hex << mainExeImageLowAddr << " - " << mainExeImageHighAddr << endl; 

for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec)) 
{ 
    cout << "Section " << SEC_Name(sec) << " at addresses 0x" << hex << SEC_Address(sec) << " - 0x" << SEC_Address(sec)+SEC_Size(sec)-1 << endl; 
} 

} 

上運行它/斌/ LS結果:

Image limits 400000 - 418b23 
Section .interp at addresses 0x400200 - 0x40021b 
Section .note.ABI-tag at addresses 0x40021c - 0x40023b 
Section .note.gnu.build-id at addresses 0x40023c - 0x40025f 
Section .dynsym at addresses 0x4002c8 - 0x400eaf 
Section .rela.dyn at addresses 0x401618 - 0x4017c7 
Section .rela.plt at addresses 0x4017c8 - 0x402157 
Section .init at addresses 0x402158 - 0x40216f 
Section .plt at addresses 0x402170 - 0x4027df 
Section .text at addresses 0x4027e0 - 0x412347 
Section .fini at addresses 0x412348 - 0x412355 
Section .rodata at addresses 0x412360 - 0x415e86 
Section .eh_frame_hdr at addresses 0x415e88 - 0x41653b 
Section .eh_frame at addresses 0x416540 - 0x41851b 
Section .dynstr at addresses 0x41851c - 0x418b23 
Section .ctors at addresses 0x619000 - 0x61900f 
Section .dtors at addresses 0x619010 - 0x61901f 
Section .jcr at addresses 0x619020 - 0x619027 
Section .data.rel.ro at addresses 0x619040 - 0x619a87 
Section .dynamic at addresses 0x619a88 - 0x619c57 
Section .got at addresses 0x619c58 - 0x619cef 
Section .got.plt at addresses 0x619cf0 - 0x61a037 
Section .data at addresses 0x61a040 - 0x61a23f 
Section .bss at addresses 0x61a240 - 0x61af5f 
Section .gnu.conflict at addresses 0x61af60 - 0x61b6f7 
Section .gnu_debuglink at addresses 0x0 - 0xf 
Section .gnu.prelink_undo at addresses 0x0 - 0x8ff 
Section .shstrtab at addresses 0x0 - 0x12d 

回答

1

難道我做錯了什麼事

不一定。

它看起來像針正試圖映射ELF概念到Windows的特定概念,並沒有一個一對一的映射。

英特爾documentationIMG_HighAddress說:

Tells the highest address of any code or data loaded by the image. 
This is the address of the last byte loaded by the image. 

但究竟是什麼意思呢?

ELF圖像加載由PT_LOAD段限定。您可以在readelf -Wl a.out的輸出中看到分段以及分段到分段的映射。

一般會有兩個LOAD段:一個與r-x保護覆蓋.text.rodata,和其他的只讀段,和一個第二與rw-保護,覆蓋.data.bss等可寫的部分。

它看起來(從輸出),如IMG_HighAddress的描述只有第一LOAD段。

你也應該注意到,並非所有部分是LOAD能,和非LOAD能夠部分通常不屬於任何部分(不佔用在運行時內存)。各種.debug*部分通常不是LOAD能夠。

+0

通知的功能句話:'在這種情況下,該函數將返回文本segment'的高地址。由於你寫的Unix映像往往會在內存中分裂,所以這種情況幾乎總是會發生的。 – nitzanms