进程内存读取总是 returns 0

Process memory reading always returns 0

我试图读取内存地址(浮点型)。所以,在任何情况下它都只是 return 0(我试过 int、float 等内存地址值)。在其他程序中(作弊引擎)一切正常。

#include <windows.h>
#include <process.h>
#include <iostream>

DWORD adresss = 0x00179574;
DWORD pid;
float id;



int main()
{
    HWND game = FindWindowA(0, ("Window name"));
    GetWindowThreadProcessId(game, &pid);
    HANDLE maincs = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    for (;;)
    {
        ReadProcessMemory(maincs, (void*)adresss, &id, sizeof(int), 0);

        std::cout << id << std::endl;
        Sleep(100);
    }
}

您似乎正在从进程中读取 int 的值,但将其保存为 float。尝试将其更改为 sizeof(float)。此外,使 address LPVOID,而不是将其转换为空指针。

如果还是不行,那就还有一件事。您正在阅读的地址似乎太小了。该过程中的常见地址将类似于 0x7ff6d91c0000.

另外,你不需要<Process.h>ReadProcessMemory的最后地址应该是nullptr而不是0

检查您的 Windows API 呼叫是否失败:

#include <Windows.h>
#include <iostream>
#include <vector>
#include <string>


LPVOID adresss = (LPVOID)0x00179574;
DWORD pid;
float id;

int main()
{
    HWND game;
    HANDLE maincs;

    if ((game = FindWindowA(0, ("Window name"))))
    {
        GetWindowThreadProcessId(game, &pid);
        if ((maincs = OpenProcess(PROCESS_VM_READ, FALSE, pid)))
        {
            for (;;)
            {
                if (ReadProcessMemory(maincs, adresss, &id, sizeof(float), 0))
                {
                    std::cout << id << std::endl;
                }
                else std::cout << "ReadProcessMemory failed with : " << GetLastError() << std::endl;

                Sleep(100);
            }
            CloseHandle(maincs);
        }
        else std::cout << "OpenProcess failed with : " << GetLastError() << std::endl;
    }
    else std::cout << "FindWindowA failed with : " << GetLastError() << std::endl;

    std::string dummy;
    std::cin >> dummy;
    return 0;
}

告诉我们它打印出什么或者它是否有效