1
I’m trying to read a variable within another process, in the case of the game "Spider Solitaire". So far it’s all worked out, but when I close the game and open again it doesn’t work anymore.
I know that when you close and open the location of the variable in memory changes and you need to do a calculation to know the address (Adress = Baseddress + Offset). I only get this Address from Artmoney, but I don’t know how to find the base or the offset. Someone can help me?
My code:
int main()
{
std::wstring processName = L"SpiderSolitaire.exe";
DWORD pid = FindProcessId(processName);
DWORD*address = (DWORD*)0x000000525570;
DWORD value;
if (pid == 0) {
std::wcout << "nao achou " << processName.c_str() << std::endl;
}
else {
HANDLE phandle = OpenProcess(PROCESS_VM_READ, 0, pid);
if (!phandle)
{
cout << "nao achou handle \n";
cin.get();
}
ReadProcessMemory(phandle, address, &value, sizeof(value), 0);
cout << value << "\n"; //mostra o valor
Sleep(1000);
}
system("PAUSE");
return 0;
}
DWORD FindProcessId(const std::wstring& processName)
{
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (processesSnapshot == INVALID_HANDLE_VALUE)
return 0;
Process32First(processesSnapshot, &processInfo);
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
while (Process32Next(processesSnapshot, &processInfo))
{
if (!processName.compare(processInfo.szExeFile))
{
CloseHandle(processesSnapshot);
return processInfo.th32ProcessID;
}
}
CloseHandle(processesSnapshot);
return 0;
}