我编写了一个例程来从加载的 DLL 中转储符号和部分,LoadLibrary
但不知道如何解码部分名称长于IMAGE_SIZEOF_SHORT_NAME
例如,如果我将以下部分打印为字符串,则 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];
但我得到的东西绝对不是字符串表。我可以在我的十六进制编辑器中看到字符串表。可移植可执行文件中的字符串表在哪里?