简化多个 ReadProcessMemory 调用

Simplify multiple ReadProcessMemory calls

我最近开始尝试使用 Cheat Engine 进行一些试验,以便能够从 运行 进程的内存中读取数据,并偶然发现了本教程的第 8 步。我想从我正在读取的第二个进程的 [[[[[0x00645390]+0xC]+0x14]+0x0]+0x18] 中存储的应用程序中读取一个特定的值,其中 0x00645390 是静态的。

目前它适用于以下疯狂指针处理片段:

::ReadProcessMemory(hProcess, (void *)0x00645390,           (void *)&dwAddress, sizeof(dwAddress), NULL);
::ReadProcessMemory(hProcess, (void *)(dwAddress + 0xc),    (void *)&dwAddress, sizeof(dwAddress), NULL);
::ReadProcessMemory(hProcess, (void *)(dwAddress + 0x14),   (void *)&dwAddress, sizeof(dwAddress), NULL);
::ReadProcessMemory(hProcess, (void *)(dwAddress),          (void *)&dwAddress, sizeof(dwAddress), NULL);
::ReadProcessMemory(hProcess, (void *)(dwAddress + 0x18),   (void *)&dwValue,   sizeof(dwAddress), NULL);

我想知道当我手头有基本地址和一些偏移量时,是否有可以使用的函数或更短的符号。

你当然可以有一个静态数组:

int offset[] = { 0, 12, 20, 0, 24 };/* (or 0xC, 0x14,m 0, 0x18) */

dwAddress = 0x00645390;
for( auto i : offset)
    ::ReadProcessMemory(hProcess, (void *)(dwAddress + i),
                        (void *)&dwAddress, sizeof(dwAddress), NULL);
dwValue = dwAddress;

不确定收益有多大。

你所做的基本上是遵循一组指针,所以:

 global->something->other->thingy->value

您需要读取每一层的每个指针,因此读取所有地址没有捷径可走。 [当编译器必须访问一长串指针时,这也适用——必须在访问指针指向的元素之前读取每个指针]

(不确定我有足够的元素,但这个概念适用)