如何获取其他程序内存的地址,然后在我的程序中读取
How to obtain address of other program memory and then read it in my program
我想找到其他程序 (other.exe
) 存储某些特定值的地址
然后从我的程序 (C#) 中读取它,但我真的不明白如何实现它
我尝试用 CheatEngine 找到它,我设法在两个地址下找到了那个值,例如 0x048907B0
现在我尝试将这个特定地址添加到进程的基址,但返回的值只是一团乱麻,甚至没有接近我的值
我哪里做错了?
以前我见过一些“经过验证”的方法,其中涉及“异或”,基本上你必须读取一些具有已知“异或地址”的“异或”值,然后才能读取其他值,公式是
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;
}
}
我post将其作为评论编辑,但由于它有效,我将post将其作为答案。
当你在Cheat Engine中找到你的数据地址时,它给你的地址已经是正确的了。因此,要读取正确的地址,而不是 0x048907B0 + baseAddress
,您只需输入 0x048907B0
就可以了。
我想找到其他程序 (other.exe
) 存储某些特定值的地址
然后从我的程序 (C#) 中读取它,但我真的不明白如何实现它
我尝试用 CheatEngine 找到它,我设法在两个地址下找到了那个值,例如 0x048907B0
现在我尝试将这个特定地址添加到进程的基址,但返回的值只是一团乱麻,甚至没有接近我的值
我哪里做错了?
以前我见过一些“经过验证”的方法,其中涉及“异或”,基本上你必须读取一些具有已知“异或地址”的“异或”值,然后才能读取其他值,公式是
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;
}
}
我post将其作为评论编辑,但由于它有效,我将post将其作为答案。
当你在Cheat Engine中找到你的数据地址时,它给你的地址已经是正确的了。因此,要读取正确的地址,而不是 0x048907B0 + baseAddress
,您只需输入 0x048907B0
就可以了。