2017-07-17 39 views
-1

我在C++中的ReadProcessMemory函數有問題。實際上函數本身工作正常,但當涉及到更大的地址時(例如,當我使用ungsigned __int64而不是DWORD,因爲DWORD對於地址來說太小),該函數給了我一個錯誤的指針地址。下面是相關代碼:ReadProcessMemory不能正常工作

DWORD tempAddress; 
unsigned __int64 potentialBasePointerAddress = 0x13F8A0000 + 0x18606B8; //I used unsigned __int64 since 0x13F8A0000 is too large for DWORD 

if (ReadProcessMemory(hProcess, (LPVOID)potentialBasePointerAddress, &tempAddress, sizeof(tempAddress), NULL)) 
{ 
    cout << tempAddress << endl; 
} 
//in this specific case the tempAddress is 1BD5679 (or 29185657) but actually it should be 3E7D4FE0 (see (*)) 

(*)Cheat Engine Result

如果我改變DWORD tempAddress;無符號__int64 tempAddress; tempAddAddress是1953A4A0002C88A5(或18249832811198240377)

我真的沒有線索如何解決這個問題。我很確定有一種方法來處理大於DWORD大小的基地址,但我太愚蠢以找出...

我很感謝每一個幫助!

回答

0

您是否將程序編譯爲64位二進制文​​件?如果您將它編譯爲32位,則轉換爲LPVOID實際上會將指針截斷爲32位值,因此您只需讀取錯誤的地址。