本帖最后由 SuperGodkill 于 2023-7-24 10:03 编辑
用ReadProcessMemory函数第一次读取成功但是第二次失败了,显示错误代码299,具体查了原因是“仅完成部分的 ReadProcessMemory 或 WriteProcessMemory 请求。”
include <iostream>
include<Windows.h>
int main()
{
//找到窗口句柄
HWND hwnd = FindWindowA("MainWindow", "植物大战僵尸中文版");
//通过窗口句柄找到进程
DWORD pid;
DWORD tid = GetWindowThreadProcessId(hwnd, &pid);
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
DWORD value = 0;
bool checkread;
unsigned long base = 0x006A9EC0;
unsigned long basevalue = 0;
unsigned long size = 0;
checkread = ReadProcessMemory(handle, (LPCVOID)(base), &value, sizeof(unsigned long), &size);
if (checkread == 0)
{
printf("读取失败,错误代码为%d\n", GetLastError());
}
else
{
printf("读取成功\n");
}
unsigned firstoffset = 0x768;
unsigned long firstvalue = 0;
checkread = ReadProcessMemory(handle, (LPCVOID)(firstoffset + basevalue), &value, sizeof(unsigned long), &size);
if (checkread == 0)
{
printf("读取失败,错误代码为%d\n", GetLastError());
}
else
{
printf("读取成功\n");
}
}
|