c++ - DLL注入(inject)和偏移读内存

标签 c++ memory dll

我将一个 DLL 注入(inject)到一个 exe 中。现在我需要从特定偏移量读取数据。我的 DLL 代码:

DWORD ExeBaseAddress = (DWORD)GetModuleHandleA(0); 
// HANDLE baseAddr = GetModuleHandleA(0)

uint16_t value = ExeBaseAddress + 0x7198BC + 0x70e;

cout << value << endl;

问题是它没有给我预期的值,即 1000。它也没有给我正确的地址。

使用内存读取软件我可以获得CORRECT 值。见:

cheatengine

但我仍然从代码中得到错误的值,即使我使用的是与内存读取应用程序完全相同的偏移量。那我错过了什么?


我试过了,但它仍然给我错误的值。

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/

相关文章:

c++ - 使用 _beginthread 和 CreateThread 的多线程

c++ - 尽管用户提供了良好的输入,但我的验证功能仍在运行?

c++ - 我应该为一个只是 vector 包装器的类编写迭代器吗?

c++ - 谁能解释常量或 const 变量存储在哪里?

php - php文件下载,内存限制问题?

dll - 如何反编译.dll文件?

java - 如何在java中调用c# dll中的方法?

c++ - 需要从DLL导出纯基类?

c++ - 以 root ubuntu 身份自动运行我的可执行文件

c++ - C++ 结构中的动态内存分配