【发布时间】:2015-03-25 17:02:02
【问题描述】:
我正在尝试获取 .text 部分的标题。 似乎起作用的是:
// Get the DOS header.
pDosHeader = (PIMAGE_DOS_HEADER) hMap;
// Get header of first section
pSectionHeader = (PIMAGE_SECTION_HEADER) ((DWORD) hMap + pDosHeader->e_lfanew + sizeof(IMAGE_NT_HEADERS));
// Get last section's header.
pLastSectionHeader = pSectionHeader + (pNtHeaders->FileHeader.NumberOfSections - 1);
但我不完全明白为什么。我原以为最后一条指令必须是:
// Get last section's header.
pLastSectionHeader = pSectionHeader + (pNtHeaders->FileHeader.NumberOfSections - 1) * sizeof(IMAGE_SECTION_HEADER);
以便指针移动section-header。
另外,(pNtHeaders->FileHeader.NumberOfSections - 1) 真的是 .text 部分吗?
【问题讨论】:
-
您查看的是 elf 文件还是其他目标文件格式?这是精灵格式信息的链接。请注意,它很长,并且包含几张图片,因此不能在 SO 上发布。 en.wikipedia.org/wiki/Executable_and_Linkable_Format>
-
应该是exe格式。
-
这里是 COFF 格式的链接:skyfree.org/linux/references/coff.pdf> 这里是 .exe 文件格式的链接:delorie.com/djgpp/doc/exe> 但是,请务必阅读此信息:
-
这个指向 pdf 文件的链接更详细地说明了 windows 可执行文件与其他系统的不同之处。 : openwatcom.org/ftp/devel/docs/pecoff.pdf>
-
我已经阅读了 Matt Pietrek 的文章,但这对我的实际实施没有多大帮助。
标签: c portable-executable