ロードされた DLL からシンボルとセクションをダンプするルーチンを作成しましたLoadLibrary
が、セクション名がそれよりも長い MinGW DLL をデコードする方法がわかりません。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];
しかし、私は間違いなく文字列テーブルではないものを手に入れました。16 進エディタで文字列テーブルを確認できます。移植可能な実行可能ファイルの文字列テーブルはどこにありますか?