昨晚点了一份炒螺狮粉外卖后,直接拉肚子到今天下午五点,人快被送去医院了。
躺着刷手机也好无聊,继续起来刚代码
即通过代码获取植物大战僵尸的阳光值,并修改,代码基于win控制台
[C++] 纯文本查看 复制代码 // PlantsVsZombies.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//通过基址获取阳光
#include <iostream>
#include <Windows.h>
#define lpClassName "MainWindow"
#define lpWindowName "Plants vs. Zombies GOTY "
//获取传入地址内的值
int mGetAddrValue(UINT_PTR memoryBaseAddress)
{
HWND windowHandle = FindWindowA(lpClassName, lpWindowName);// 1.通过类名+ 窗口名获取窗口句柄
std::cout << "窗口句柄:" << windowHandle<<"\n";
DWORD processID = 0,threadID = 0;
threadID = GetWindowThreadProcessId(windowHandle, &processID);//2.传入窗口句柄,进程ID地址,得到进程ID,线程ID
std::cout << "窗口进程ID:" << processID << "\n" << "窗口所属线程ID:" << threadID << "\n";
HANDLE handleProcess = OpenProcess(PROCESS_ALL_ACCESS,0, processID);//3.通过进程ID,以获取进程全部权限的方式,取得进程句柄
unsigned int readData = 0;//用于保存地址中的4字节值,一般都是无符号int 如果是读取地址,UINT_PTR readData这样可以兼容32-64为游戏
//4.传入: 进程句柄 读取内存的基址 读出内容后输出的缓冲区的头地址 需要读取内存的大小:4,因为阳光就4字节 实际读取内存的大小,0默认不传值
ReadProcessMemory(handleProcess, (LPCVOID)memoryBaseAddress, &readData,4,0);//读进程内存
CloseHandle(handleProcess);//释放进程句柄
std::cout << "返回数据:" << readData << "\n";
return readData;
}
UINT_PTR memoryAddr;
int main()
{
//0x028DAF38
int ii = mGetAddrValue(mGetAddrValue(mGetAddrValue(0x7794F8) + 0x868) + 0x5578);
std::cout << "原有阳光:" << ii;
UINT_PTR writeAddr = mGetAddrValue(mGetAddrValue(0x7794F8) + 0x868) + 0x5578;
HWND windowHandle = FindWindowA(lpClassName, lpWindowName);// 1.通过类名+ 窗口名获取窗口句柄
std::cout << "窗口句柄:" << windowHandle << "\n";
DWORD processID = 0, threadID = 0;
threadID = GetWindowThreadProcessId(windowHandle, &processID);//2.传入窗口句柄,进程ID地址,得到进程ID,线程ID
std::cout << "窗口进程ID:" << processID << "\n" << "窗口所属线程ID:" << threadID << "\n";
HANDLE handleProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, processID);//3.通过进程ID,以获取进程全部权限的方式,取得进程句柄
unsigned int sunData = 3333;//最终要修改的阳光的值
WriteProcessMemory(handleProcess, (LPVOID)writeAddr, &sunData, 4, NULL);//传入:1.进程句柄2.写入地址3.写入数值的指针4.写入字节数5.默认传NULL不去理解
} |