c++ - 读取 Win32 变量

标签 c++ winapi

如果我可以挂接到 Win32 进程,我能够做到:

  • 从进程内的类内部读取变量?

  • 我有上述 Win32 应用程序的完整源代码,我可以将其用作此主题的引用吗?

干杯。

最佳答案

是的。一旦您的模块挂接到进程中,您就共享相同的地址空间。这意味着您可以访问进程分配的内存(例如,用于类实例)。

如果您知道类实例的偏移量,那么您可以:

  • 将此内存地址转换为指向类的指针(前提是包含类 header )
  • 使用此内存地址的偏移量来访问类的成员。

参见Traversing the Module List在 MSDN 上。一旦您拥有MODULEENTRY32对于您希望“ Hook ”的进程,您可以使用 modBaseAddr 作为偏移量的基础。例如,如果您知道指向类实例的全局变量位于 0x000AD421,您可以执行以下操作:

ClassName *pClassBase = moduleEntry->modBaseAddr + 0x000AD421;
pClassBase->UseSomeFunctions();

unsigned char *pClassBase = moduleEntry->modBaseAddr + 0x000AD421; // if we don't know the exact definition of the class we want to play with
float flMemberValue = *reinterpret_cast<float*>((unsigned char *)pClassBase + 24); // float member value at offset 24
// value of member is flMemberValue

*reinterpret_cast<float*>((unsigned char *)pClassBase + 24) = 15.25; // setting the same member value to 15.25.

正如其他评论者所说,找到类基的偏移量是这个过程中最难的部分。但是,如果您手头有类定义,那么这本质上是您必须做的唯一工作(即您也不必找到类成员偏移量)。

关于c++ - 读取 Win32 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11126547/

相关文章:

c++ - .def 文件 C/C++ DLL

c++ - 是否可以在 C 程序中使用 C++ 库函数?

c++ - 隐藏其他运营商一段时间

windows - 将客户端打印机映射到 Windows 终端服务器的 API

c++ - 如何在win32的窗口类中设置动态菜单?

c++ - 否定多个类型 std::size_t 的安全方法

c++ - 视觉 C++ 2008 : Finding the cause of slow link times

windows - DLL 文件到底是什么,它们是如何工作的?

c - 如何将 Unicode 路径转换为 ​​C 字符串?

c++ - ConvertStringSecurityDescriptorToSecurityDescriptor() 阻止我的程序正常结束