【发布时间】:2013-10-08 18:24:11
【问题描述】:
我已经编写了一个例程来从加载了LoadLibrary 的 DLL 中转储符号和节,但不知道如何解码节名长于 IMAGE_SIZEOF_SHORT_NAME 的 MinGW DLL
例如,如果我将以下部分打印为字符串,则 MinGW DLL 会输出它们:
[".text", ".data", ".rdata", ".pdata", ".xdata", ".bss", ".edata", ".idata",
".CRT", ".tls", ".reloc", "/4", "/19", "/31", "/45", "/57", "/70", "/81",
"/92"]
objdump.exe 的其他部分得到它们:
.debug_aranges
.debug_info
.debug_abbrev
.debug_line
.debug_frame
.debug_str
.debug_loc
.debug_ranges
都比IMAGE_SIZEOF_SHORT_NAME长。 MSDN 解释说:
For longer names, this member contains a forward slash (/) followed by an ASCII representation of a decimal number that is an offset into the string table.
所以我有以下代码:
Char buffer[IMAGE_SIZEOF_SHORT_NAME + 1];
std::strncpy(buffer, reinterpret_cast<const Char * const>(section_header_ptr[i].Name), IMAGE_SIZEOF_SHORT_NAME);
buffer[IMAGE_SIZEOF_SHORT_NAME] = '\0';
const Char * name = buffer;
if (name[0] == '/') {
const Long rva = std::strtol(name + 1, NULL, 10);
if ((LONG_MAX == rva) || (LONG_MIN == rva) || ((0 == rva) && (name[0] != '0'))) {
static const Char * const failure = "failed to convert offset";
name = failure;
}
// -- How do I get the string table here? and use the offset? --
}
阅读 COFF 规范,我发现字符串表在符号条目之后,所以它应该是
HMODULE handle = LoadLibrary("some_mingw_library.dll");
PIMAGE_DOS_HEADER idh = (PIMAGE_DOS_HEADER)(handle);
PIMAGE_NT_HEADERS inh = (PIMAGE_NT_HEADERS)(((const uint8_t*)(idh)) + idh->e_lfanew)
PIMAGE_FILE_HEADER ifh = &inh->FileHeader;
PIMAGE_SYMBOL is = (PIMAGE_SYMBOL)(((const uint8_t*)(idh)) + ifh->PointerToSymbolTable)
const char * const string_table = &is[ifh->NumberOfSymbols];
但我得到的东西绝对不是字符串表。我可以在我的十六进制编辑器中看到字符串表。可移植可执行文件中的字符串表在哪里?
【问题讨论】:
-
MSDN 还说(您放置的链接)...“可执行图像不使用字符串表并且不支持超过八个字符的部分名称”。
-
@mox 在微软的世界里,当然。 MSDN 是 Microsoft 的文档,但 PE 和 COFF 规范是公开的,并且也在 UNIX 中使用。您可以查看 GNU binutils 并查看 PE 规范是通过非
Windows.h标头编写的。 Microsoft 的“已弃用”意味着他们不再使用它,没有理由不能在野外的图像中填写这些部分 - 它完全受规范支持。
标签: c++ winapi dll mingw portable-executable