如何使用多指针写入ProcessMemory [英] How to WriteProcessMemory with multipointers

查看:71
本文介绍了如何使用多指针写入ProcessMemory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要做的是更改游戏内存中的值. 为了写入该变量,我需要添加以下指针和偏移量,因为这样我总会到达一个有效的地址:

First of all, what I am trying to do is changing a value in the memory of a game. In order to write to that variable I need to add the following pointer and offsets because then I always get to an address that works:

baseAddr + offset1 + offset2 + offset3 = myDesiredAddr

现在,这就是我试图做的...

Now, this is what I have tried to do...

ReadProcessMemory(
hProc, (LPVOID)(BaseAddr + offset1), &myDesiredAddr, sizeof(myDesiredAddr), 0
);
ReadProcessMemory(
hProc, (LPVOID)(myDesiredAddr + offset2), &myDesiredAddr, sizeof(myDesiredAddr), 0
);
ReadProcessMemory(
hProc, (LPVOID)(myDesiredAddr + offset3), &myDesiredAddr, sizeof(myDesiredAddr), 0
);

我对到达的最终地址上的WriteProcessMemory感到厌倦,但它无法成功读写.任何建议都会有所帮助.

I've tired to WriteProcessMemory on the final address that I got but it does not read and write successfully. Any advice will be helpful.

推荐答案

您可以执行以下操作:

unsigned long offset1 =  /* your value              */
unsigned long offset2 =  /* your value              */
unsigned long offset3 =  /* your value              */
unsigned long BaseAddr = /* your value              */
unsigned long Pointer;   /* to hold the final value */
unsigned long temp;      /* hold the temp values    */
unsigned value =         /* value to write          */

上面显示了您的声明.我假设您检查读写功能是否成功返回,否则我建议您这样做.

The above shows your declarations. I presume you check if the read and write functions return successfully, otherwise I would suggest you do so.

ReadProcessMemory(
hProc, reinterpret_cast<LPVOID>(BaseAddr), &temp, sizeof(temp), 0);
Pointer = temp + offset1;

ReadProcessMemory(
hProc, reinterpret_cast<LPVOID>(Pointer), &temp, sizeof(temp), 0);
Pointer = temp + offset2;

ReadProcessMemory(
hProc, reinterpret_cast<LPVOID>(Pointer), &temp, sizeof(temp), 0);
Pointer = temp + offset3;

/* Now Pointer stores the final address and *
 * you can write to it                      */
WriteProcessMemory(
hProc, reinterpret_cast<unsigned*>(Pointer), &value, sizeof(value), 0);

通过添加内存地址和偏移量并将值存储在 Pointer 中,您可以继续从 Pointer 读取并将临时地址存储在 temp 变量,直到获得所需的最终地址.

By adding the memory addresses and offsets and storing the value in Pointer, you can continue to read from Pointer and store the temporary addresses in a temp variable until you get to the final address that you want.

我建议您循环执行此操作,以提高效率和代码的整洁度.

I suggest you do this in a loop for efficiency and neater code.

这篇关于如何使用多指针写入ProcessMemory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆