问题描述
我想找到其他程序(other.exe
)正在存储某些特定值的地址
然后从我的程序(C#)中读取它,但是我真的不明白如何实现这一目标
我尝试使用CheatEngine查找它,并设法在两个地址下找到该值,例如0x048907B0
现在,我尝试将这个特定地址添加到进程的基地址中,但是返回的值只是混乱,什至没有接近我的值
我在这里做错了什么?
以前,我曾见过一些涉及“ xor”的“经过验证”的方法,基本上,您必须读取带有已知“ xor地址”的“ xor”值,然后才能读取其他值,公式为
info.MyValue = BitConverter.ToInt32(buffer,0) ^ xor;
谢谢!
我的代码:
var process = Process.GetProcessesByName(processName).FirstOrDefault();
if (process == null)
{
throw new Exception($"Process with name: '{processName}' is not running");
}
var mc = new MemoryContext(process);
public class MemoryContext
{
const int PROCESS_WM_READ = 0x0010;
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess,bool bInheritHandle,int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess,int lpBaseAddress,byte[] lpBuffer,int dwSize,ref int lpNumberOfBytesRead);
private int baseAddress;
private Process _process;
private IntPtr handle;
public MemoryContext(Process process)
{
_process = process;
baseAddress = _process.MainModule.BaseAddress.ToInt32();
handle = OpenProcess(PROCESS_WM_READ,false,_process.Id);
}
public ProcessDetails RefreshData()
{
var info = new ProcessDetails();
int bytesRead = 0;
byte[] buffer = new byte[4];
// here I'm trying to read that value
ReadProcessMemory((int)handle,0x048907B0 + baseAddress,buffer,buffer.Length,ref bytesRead);
info.MyValue = BitConverter.ToInt32(buffer,0);
return info;
}
}
解决方法
我将其发布为评论,但由于它可以正常工作,因此我将其发布为答案。
在Cheat Engine中找到数据的地址时,它提供给您的地址已经是正确的地址。因此,要读取正确的地址,只需输入0x048907B0 + baseAddress
即可代替0x048907B0
,它应该可以工作。