【发布时间】:2020-06-29 10:21:24
【问题描述】:
我想了解一下游戏黑客是如何工作的,所以我做了一个简单的游戏:
#include <iostream>
#include <Windows.h>
#include <typeinfo>
using namespace std;
void main() {
int score = 100;
int* address = &score;
SetConsoleTitle(L"Simple game");
cout << "Address of score is " << address << endl;
cout << typeid(address).name() << endl;
for (; ;) {
cout << score << ' ' << address << endl;
score = max(score - 1, 0);
Sleep(1000);
}
}
只是值减少到零。它还写了这个分数的地址,以便于更改。 这是我的“黑客”:
#include <iostream>
#include <Windows.h>
#include <tchar.h>
using namespace std;
int main() {
HWND handle = FindWindow(NULL, L"Simple game");
DWORD processId;
if (handle == NULL) {
cerr << "No such window" << endl;
}
else {
cout << "Window handle: " << handle << endl;
GetWindowThreadProcessId(handle, &processId);
cout << processId << endl;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processId);
if (!hProcess) {
cerr << "Couldn't find window";
}
else {
int writeResult = 0;
int val = 2000;
writeResult = WriteProcessMemory(hProcess, (LPVOID)0x00DAFC58, (LPCVOID)val, sizeof(val), NULL);
if (writeResult == 0) {
cerr << "Declined" << endl;
cerr << GetLastError() << endl;
}
else {
cout << "Success" << endl;
}
}
}
return 0;
}
我知道这段代码不是以完美的形式编写的,抱歉。它给了我错误 299。据我了解,这意味着编写过程的部分执行。我认为问题出在 WriteProcessMemory 的第二个参数 lpBaseAddress 中。我的错误是什么?感谢您的帮助。
【问题讨论】:
-
你好 agamemdon,检查如何设置访问不同进程内存的权限,也可能有其他原因,有一个关于它的话题stackoverflow.com/questions/3799195/…