我将一个 DLL 注入(inject)到一个 exe 中。现在我需要从特定偏移量读取数据。我的 DLL 代码:
DWORD ExeBaseAddress = (DWORD)GetModuleHandleA(0);
// HANDLE baseAddr = GetModuleHandleA(0)
uint16_t value = ExeBaseAddress + 0x7198BC + 0x70e;
cout << value << endl;
问题是它没有给我预期的值,即 1000
。它也没有给我正确的地址。
使用内存读取软件我可以获得CORRECT 值。见:
但我仍然从代码中得到错误的值,即使我使用的是与内存读取应用程序完全相同的偏移量。那我错过了什么?
我试过了,但它仍然给我错误的值。
HANDLE ExeBaseAddress = GetModuleHandleA(0);
uintptr_t p = (uintptr_t)ExeBaseAddress + 0x7198BC + 0x70e;
int value = *reinterpret_cast<int *>(p);
cout << ExeBaseAddress << " - " << value << endl;
最佳答案
从与 OP 的所有长评论和聊天(也有一些基本输入)中,找到了解决方案,
加载的 exe 将另一个 PE 的基地址存储在 0x7198BC 位置。此基地址 + 偏移量 (0x70E) 包含所需的值。
HANDLE ExeBaseAddress = GetModuleHandleA(0);
/*ExeBaseAddress is a HANDLE, so it's size is unknown to the compiler.
That's why, we cast it to (unintptr_t).
And overall, we need an address which can be dereferenced,
to get the value kept at the location, so cast it to (uintptr_t*)*/
uintptr_t *p = (uintptr_t*)((uintptr_t)ExeBaseAddress + 0x7198BC);
uintptr_t ModuleBaseAdrs = (DWORD&)*p ;
printf( "ModBaseAdrsLoc - %p, ModuleBaseAdrs - %X\n", p, ModuleBaseAdrs ) ;
uintptr_t *ValLoc = (uintptr_t *) (ModuleBaseAdrs + 0x70E);
DWORD Val = (DWORD&)*ValLoc ;
printf( "ValLoc - %p, Val - %u\n", ValLoc, Val ) ;
关于c++ - DLL注入(inject)和偏移读内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35325350/