嘗試從遊戲內存讀取實體名稱,指針100%正確,因爲使用ce進行檢查。ReadProcessMemory上的錯誤299
具有讀/寫浮點/整數值
32位過程中沒有問題,遊戲藏漢 - 試圖x64的編譯代碼,沒有幫助。
GetLastError()
回報NR 299
ERROR_PARTIAL_COPY
299 (0x12B)
Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
任何想法可能是什麼原因呢? 代碼如下
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
#include <string>
#include <time.h>
#include <tchar.h>
using namespace std;
DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *lpszModuleName);
string readName(HANDLE handlez, DWORD base, DWORD bp, DWORD ofset1, DWORD ofset2, DWORD ofsetInc);
int main()
{
DWORD baseOfset = 0x60DE90;
DWORD ofset1 = 0x4c4;
DWORD ofset2 = 0x6a0;
DWORD ofset3 = 0x18;
HWND window = NULL;//FindWindow(0, _TEXT("Gothic II - 2.6 (pol)"));
DWORD pID = 0;
DWORD dwBP = NULL;
HANDLE handle = NULL;// OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
string gameStatus;
int refresher = clock();
gameStatus = "Waiting for game";
window = FindWindow(0, _TEXT("Gothic II - 2.6 (pol)")); // window title
if (window)
{
GetWindowThreadProcessId(window, &pID);
if (pID != 0)
{
handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
dwBP = dwGetModuleBaseAddress(pID, _T("Gothic2.exe")); // proc name
if (handle == INVALID_HANDLE_VALUE || handle == NULL || dwBP == NULL)
{
gameStatus = "No handle";
}
else
{
gameStatus = "OK";
}
}
else
{
gameStatus = "No access";
}
}
else
{
gameStatus = "No window";
}
while (!GetAsyncKeyState(VK_DELETE))
{
if (clock() - refresher > 1000)
{
refresher = clock();
cout << gameStatus << endl;
string elo="a";
elo = readName(handle, dwBP, baseOfset, ofset1, ofset2, ofset3);
if (elo == "a")
{
cout << ":(\n";
}
cout << "Name: " << elo <<".\n";
cout << "Name: " << &elo << ".\n" << endl;
system("pause");
}
}
CloseHandle(handle);
}
string readName(HANDLE handlez, DWORD base, DWORD bp, DWORD ofset1, DWORD ofset2, DWORD ofsetInc)
{
DWORD adresik;
ReadProcessMemory(handlez, (LPCVOID)(base + bp), &adresik, sizeof(DWORD), NULL); // base adress + base pointer
adresik += ofset1; //1st lvl pointer
ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL);
adresik += ofset2; // 2nd lvl pointer
ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL);
adresik += ofsetInc; // 3rd lvl pointer this goes up +=20
ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL);
adresik += 0x12c; // 4th static pointer
ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL);
adresik += 0x0; // 5th static pointer
ReadProcessMemory(handlez, (LPCVOID)adresik, &adresik, sizeof(DWORD), NULL);
string papa;
ReadProcessMemory(handlez, (LPCVOID)adresik, &papa, sizeof(string), NULL); // get name
DWORD ero = GetLastError();
cout << ero << endl;
return papa; // return name
}
DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *lpszModuleName)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessIdentifier);
DWORD dwModuleBaseAddress = 0;
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32 = { 0 };
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (_tcscmp(ModuleEntry32.szModule, lpszModuleName) == 0)
{
dwModuleBaseAddress = (DWORD)ModuleEntry32.modBaseAddr;
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
return dwModuleBaseAddress;
}
你的錯誤檢查是錯誤的。你需要檢查'ReadProcessMemory'的返回值,如果**,並且只有在它是false的情況下,那麼**你調用GetLastError()。 –