大致思路:
1.获取游戏窗口,使用FindWindow函数
2.获取游戏PID(ProcessID),使用GetWindowThreadProcessId函数
3.获取游戏进程句柄,使用OpenProcess函数
4.读取游戏阳光基址 5.读取后修改阳光数值
大家查看源码后可能疑惑的问题:
1.上图源码中的窗口信息是怎么找到的?解析如下↓↓
打开VS中的Spy++,将准星拖入植物大战僵尸窗口上,方可一键获取窗口信息,操作如下↓↓
2.源码中阳光的基址和偏移是怎么找到的?
这涉及游戏逆向相关的基础:需看得懂汇编和熟练运用调试器,如CE(CheatEngine)
以后会增加更多有趣功能,麻烦点点关注
源码如下:
本人癖好源码内不喜欢出现中文(包括注释)如果有地方看不懂可以用翻译软件
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <Windows.h>
int main()
{
//My thinking:
//1.Get game window
//2.Get game process id
//3.Get process handle
//4.Get sunshine address
//5.Modify sunshine data
HWND hGameWnd = FindWindow(L"MainWindow", L"Plants vs. Zombies");
if (hGameWnd == NULL)
{
printf("Failed to get Window\n");
return 0;
}
DWORD GamePid;
GetWindowThreadProcessId(hGameWnd, &GamePid);
printf("PID:%d\n", GamePid);
if (GamePid == 0)
{
printf("Failed to get ProcessId\n");
return 0;
}
HANDLE Hprocess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GamePid);
if (Hprocess == NULL)
{
printf("Failed to open game process.Error code:%d\n",GetLastError());
}
DWORD SunshineBaseAddress = 0x00731C50;
DWORD SunshineAddressValue = 0;
DWORD Size = 0;
if (FALSE == ReadProcessMemory(Hprocess, (void*)SunshineBaseAddress, &SunshineAddressValue, 4, &Size))
{
printf("Failed to Read BaseAddress.Error:%d", GetLastError());
}
DWORD SunshineFirstOffset = 0x868;
DWORD SunshineFirstOffsetValue = 0;
if (FALSE == ReadProcessMemory(Hprocess, (void*)(SunshineAddressValue + SunshineFirstOffset), &SunshineFirstOffsetValue, 4, &Size))
{
printf("Failed to Read FirstOffset.Error:%d", GetLastError());
}
DWORD SunshineSecondOffset = 0x5578;
DWORD SunshineValue = 0;
if (FALSE == ReadProcessMemory(Hprocess, (void*)(SunshineFirstOffsetValue + SunshineSecondOffset), &SunshineValue, 4, &Size))
{
printf("Failed to Read SunshineValue.Error:%d", GetLastError());
}
printf("Sunshine:%d", SunshineValue);
while (1)
{
int ModifySunshineValue = 9999;
WriteProcessMemory(Hprocess, (void*)(SunshineFirstOffsetValue + SunshineSecondOffset), &ModifySunshineValue, 4, &Size);
}
return 0;
}
版权归原作者 UPX666 所有, 如有侵权,请联系我们删除。