【发布时间】:2020-04-17 10:25:24
【问题描述】:
我目前正在尝试让我的 readProcessMemory 函数工作,但我不断收到错误“Attempted to read or write protected memory. This is often an indication that other memory is corrupt”。我一直在努力解决它,但我就是做不到。我已阅读其他论坛和主题来解决问题,但没有任何效果。我一直试图在测试程序中读取一个整数变量以确保它有效,但我最初在记事本和突击立方体上尝试过,但没有任何效果。
这是我的代码:
const int PROCESS_VM_READ = 0x0010;
#region imports
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(int hProcess,
Int64 lpBaseAddress, byte[] lpBuffer, UInt64 dwSize, out IntPtr lpNumberOfBytesRead);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, UInt32 dwSize, out IntPtr lpNumberOfBytesWritten);
#endregion
private static IntPtr processHandle;
static void Main(string[] args)
{
Console.WriteLine(readInt(0x003CECC4));
Console.Read();
}
static byte[] readMemory(int memoryAddress, int bytesToRead)
{
Process process = Process.GetProcessesByName("test")[0];
processHandle = OpenProcess(PROCESS_VM_READ, false, process.Id);
IntPtr bytesRead;
byte[] buffer = new byte[bytesToRead];
ReadProcessMemory((int)processHandle, memoryAddress, buffer, (uint)buffer.Length, out bytesRead);
return buffer;
}
static int readInt(int memoryAddress)
{
return BitConverter.ToInt32(readMemory(memoryAddress, 4), 0);
}
}
}
【问题讨论】:
-
我的猜测是您正在尝试读取受保护的内存。我意识到这听起来很“陈词滥调”,但你不能只读取另一个应用程序的内存 - 有很多保护措施可以防止这种情况发生。
-
我知道有些程序有保护功能,但突击魔方是游戏模组制作者/黑客开始使用的,因为它是开始读取和写入内存的简单场所。我以前在这个游戏上工作过,但这次它不想
标签: c# readprocessmemory