其中 是 Windows DLL 中的字符串表
Where is the string table in a Windows DLL?
我编写了一个例程来从加载LoadLibrary
但不确定如何解码节名长于IMAGE_SIZEOF_SHORT_NAME
的 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] = ' ';
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];
但我得到的东西绝对不是字符串表。 我可以在我的十六进制编辑器中看到字符串表。 可移植可执行文件中的字符串表在哪里?
当可执行文件映射到内存中时,它不会作为一个连续的块加载。 各节分散在各处,如节标题中所述。
符号根本不必然映射到内存中。
PointerToSymbolTable
(我认为)是文件偏移量,而不是内存偏移量(如上所述,它们不是一回事)。
EXE 和 DLL 根本不应该有 COFF 符号,尽管这个文件显然有。
大多数此类问题的答案都可以在PEDUMP中找到。
我来晚了,但似乎这个问题没有得到完全回答。在找到解决方案之前,我自己来到这里寻找相同的答案。
可移植可执行文件中的字符串表在哪里?
字符串表紧跟在符号表之后。符号的数量与符号表起始地址一起出现在文件头信息中,每个符号为 18 个字节。一个很好的简单计算来获得字符串表。
前 4 个字节是字符串表本身的大小(因此第一个条目为/4)。每个字符串都遵循前一个字符串。每个字符串都以 null 结尾。这并不重要,因为偏移量位于部分名称本身中,因此您可以直接查看它们。
字符串表在可执行文件 (DLL) 中不可用,仅在 OBJ 文件中可用。这就是在分析 PE 文件时无法枚举这些内容的原因。PE 文件的节名称永远不会超过 8 个字符。
- Visual c ++,使用字符串引用/指针调用 dll 函数
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 如何将 VB.Net 字符串作为字符*传递给C++dll?
- C# 和 C++ dll - 封送字符串
- 为什么在调用C#DLL时不需要提供字符串缓冲区
- 随机字符,从强制转换 Arduino 字符串到 Excel BSTR 通过 c++ DLL
- Java 调用 dll 字符串返回类型方法
- 如何在 VBA/Excel 中创建字符串数组并将其发送到C++ DLL,以便可以在 DLL 中循环访问它
- 将字符串向量从 C# 传递到C++ DLL
- 使用 DLL 在 c++ 和 C# 之间交换字符串
- 为什么 C# 封送字符串不适用于C++ DLL
- C++中具有"::"字符串名称的 DLL 导出调用
- 放置在外部 DLL 中的类中的字符串数据的内存损坏
- 从 dll 返回多个字符串
- 将字符串从 C# 发送到 dll 文件C++
- 从dll传递c字符串,穿过外部C
- 如何将字符串从C++DLL返回到MetaTrader 4代码执行生态系统?
- 将字符串[]从C#发送到SafeArrayAccessData()上的C++ Dll 'E_UNEXPECTEDCatastrophic Error'
- 编译时如何隐藏DLL文件中的字符串?
- 将C#中的C++类与字符串(Dll)一起使用