好友
阅读权限10
听众
最后登录1970-1-1
|
25吾爱币
代码如下,把读取基址的代码放在WinMain里就行,但写成函数就不行
#include <windows.h>
void InfintSunine(HANDLE& process) {
unsigned long baseAddress = 0x6A9EC0;
unsigned long baseValue = 0;
if (ReadProcessMemory(process, (LPCVOID)baseAddress, &baseValue, sizeof(unsigned long), NULL) == FALSE) {
MessageBox(NULL, "fail", "", MB_OK);
}
unsigned long one = 0x768;
unsigned long oneValue = 0;
ReadProcessMemory(process, (LPCVOID)(baseValue + one), &oneValue, sizeof(unsigned long), NULL);
unsigned long two = 0x5560;
unsigned long towValue = 0;
ReadProcessMemory(process, (LPCVOID)(oneValue + two), &towValue, sizeof(unsigned long), NULL);
int changeVal = 99999;
if (WriteProcessMemory(process, (LPVOID)(oneValue + two), &changeVal, sizeof(unsigned long), NULL) == FALSE) {
MessageBox(NULL, "修改失败", "", MB_OK);
}
else {
MessageBox(NULL, "修改成功", "", MB_OK);
}
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND pvz = FindWindow("MainWindow", NULL);
DWORD pid = 0;
GetWindowThreadProcessId(pvz, &pid);
//HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
switch (uMsg)
{
case WM_CREATE: {
HWND hwnd1 = CreateWindowEx(
0,
"BUTTON",
"一键99999阳光",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
10,
10,
100,
40,
hWnd,
(HMENU)1001,
((LPCREATESTRUCT)lParam)->hInstance,
NULL
);
HWND hwnd2 = CreateWindowEx(
0,
"BUTTON",
"植物无冷却",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
120,
10,
100,
40,
hWnd,
(HMENU)1002,
((LPCREATESTRUCT)lParam)->hInstance,
NULL
);
break;
}
case WM_COMMAND: {
switch (LOWORD(wParam))
{
case 1001: {
if (HIWORD(wParam) == BN_CLICKED) {
HWND pvz = FindWindow("MainWindow", NULL);
DWORD pid = 0;
GetWindowThreadProcessId(pvz, &pid);
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (process != NULL) {
unsigned long baseAddress = 0x6A9EC0;
unsigned long baseValue = 0;
if (ReadProcessMemory(process, (LPCVOID)baseAddress, &baseValue, sizeof(unsigned long), NULL) != FALSE) {
MessageBox(NULL, "读取成功", "", MB_OK);
}
else {
MessageBox(NULL, "读取失败", "", MB_OK);
}
unsigned long one = 0x768;
unsigned long oneValue = 0;
ReadProcessMemory(process, (LPCVOID)(baseValue + one), &oneValue, sizeof(unsigned long), NULL);
unsigned long two = 0x5560;
unsigned long towValue = 0;
ReadProcessMemory(process, (LPCVOID)(oneValue + two), &towValue, sizeof(unsigned long), NULL);
int changeVal = 99999;
if (WriteProcessMemory(process, (LPVOID)(oneValue + two), &changeVal, sizeof(unsigned long), NULL) == FALSE) {
MessageBox(NULL, "修改失败", "", MB_OK);
}
else {
MessageBox(NULL, "修改成功", "", MB_OK);
}
}
else {
MessageBox(NULL, "未查找到进程", "", MB_OK);
}
}
break;
}
case 1002:
if (HIWORD(wParam) == BN_CLICKED) {
MessageBox(NULL, "你好", "", MB_OK);
}
break;
}
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hWnd, &ps);
}
return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow)
{
HWND pvz = FindWindow("MainWindow", NULL);
if (pvz == NULL) {
MessageBox(NULL, "请打开游戏", "", MB_OK);
return 0;
}
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = "MainWindow";
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0,
"MainWindow",
"第一个窗口程序",
WS_OVERLAPPEDWINDOW,
0,
0,
800,
500,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
|
|