【问题标题】:Issue with WriteProcessMemoryWriteProcessMemory 的问题
【发布时间】: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 中。我的错误是什么?感谢您的帮助。

【问题讨论】:

标签: c++ memory


【解决方案1】:

看看你在哪里写了(LPCVOID)val。这是您要在进程中复制的内存地址。 2000 可能不是有效地址。您想从val 变量本身复制,因此您应该使用它的地址&amp;val

【讨论】:

  • 非常感谢!这种侮辱性的错误。
猜你喜欢
  • 2023-03-23
  • 2011-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-05
  • 1970-01-01
  • 1970-01-01
  • 2014-10-10
相关资源
最近更新 更多