部分地址超出图像区域 - Intel Pin

Section addresses goes beyond the image region - Intel Pin

我开发了一个简单的 pintool 来列出程序主要可执行映像的所有部分(遍历其所有部分),以及使用 IMG_HighAddressIMG_LowAddress 的下限和上限;根据 Pin 的说法,这些 return 图像的明确限制。

令我惊讶的是,这些部分远远超出了这些函数报告的下限和上限。是我做错了什么,还是这些功能不准确?

我的图片加载函数:

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;
}

}

运行 它在 /bin/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

Have I done something wrong

不一定。

看起来 Pin 正试图将 ELF 概念映射到 Windows 特定概念,但没有一对一的映射。

英特尔 documentation IMG_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 不可用。