我正在将DLL文件读取到缓冲区(pSrcData
),从这里我想打印e_lfanew
bool readDll(const char* dllfile)
{
BYTE* pSrcData;
std::ifstream File(dllfile, std::ios::binary | std::ios::ate);
auto FileSize = File.tellg();
pSrcData = new BYTE[static_cast<UINT_PTR>(FileSize)];
File.seekg(0, std::ios::beg);
File.read(reinterpret_cast<char*>(pSrcData), FileSize);
File.close();
std::cout << std::hex << reinterpret_cast<IMAGE_DOS_HEADER*>(pSrcData)->e_lfanew;
pOldNtHeader = reinterpret_cast<IMAGE_NT_HEADERS*>(pSrcData + reinterpret_cast<IMAGE_DOS_HEADER*>(pSrcData)->e_lfanew);
return true;
}
输出:E8
在 HxD 中打开 dll,我得到这个(地址 0000000 - 00000030):
4D 5A 90 00 03 00 00 00 04 00 00 00 FF FF 00 00
B8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 F8 00 00 00
意思是e_lfanew
应该是F8
。但是,我在运行上面的代码时遇到E8
。谁能看出我做错了什么?
加法: 获得e_magic工作,因为std::cout << std::hex << reinterpret_cast<IMAGE_DOS_HEADER*>(pSrcData)->e_magic
产生5a4d
,使用小端序转换为4D 5A
抱歉,我发现在Visual Studio 2019中将配置设置为x86 Release
集e_lfanew
F9
和x86 Debug
集e_lfanew
E8
。我正在比较不同的调试/发布版本。