簡體   English   中英

ReadProcessMemory 總是讀取 0

[英]ReadProcessMemory always reads 0

我正在一個小游戲中出於教育目的(目前在 Windows 上)創建作弊。 到目前為止,我的錯誤是ReadProcessMemory總是讀取 0。

LPCVOID addr = (LPCVOID *) 0x1228A93C; // TO-DO: c++ casts 
int dest = 0;
SIZE_T read = 0;
bool error = ReadProcessMemory(process, addr, &dest, sizeof(int), &read);
if (!error) {
    printf("I read %llu w/ %u at %p\r\n", read, dest, addr);
} else {
    printf("This isn't working: %p / %llu\r\n", addr, read);
    std::cerr << "err: " << std::to_string(::GetLastError()) << std::endl;
    return (1);
}

在那里,我嘗試閱讀游戲中的金錢數量。 通過使用 Cheat Engine,我獲得了每次使用金錢時都會發生變化的值,即上面代碼片段中的0x1228A93C 如果我在作弊引擎中更改此地址指向的值,則游戲中的錢也會更改,所以我猜這是正確的地址。

盡管如此,當我運行這個片段時,我得到了這個輸出:

I read 0 w/ 0 at 0x1228a93c

這意味着它不讀取。

注意:有更多代碼,在我的程序中,在這個上面,但這基本上是找到游戲窗口,創建游戲的快照並找到exe模塊。

這可能是你想要的:

LPCVOID addr = (LPCVOID *) 0x1228A93C; // TO-DO: c++ casts 
int dest = 0;
SIZE_T read = 0;
if (ReadProcessMemory(process, addr, &dest, sizeof(int), &read))
{
    printf("I read %llu w/ %u at %p\r\n", read, dest, addr);
} else {
    auto lasterror = ::GetLastError();               // first thing to do: call GetLastError
    printf("This isn't working: %p / %llu\r\n", addr, read);
    std::cerr << "err: " << lasterror << std::endl;  // std::to_string is useless here
}

如果出現錯誤,首先要做的是調用GetLastError()因為您不知道cout是否會調用SetLastError()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM