2

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

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

  • 我有上面 Win32 应用程序的完整源代码,我可以用它作为这个主题的参考吗?

干杯。

4

1 回答 1

2

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

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

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

请参阅MSDN 上的遍历模块列表。一旦你有了想要“挂钩”的进程的MODULEENTRY32modBaseAddr ,你就可以使用它作为你的偏移量的基础。例如,如果您知道指向类实例的全局变量位于 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.

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

于 2012-06-20T19:20:35.283 回答