I'm trying to make a program that read the timer value from Minesweeper. (OS is windows 7 64bit)
Using cheat engine I found the base address of the variable, but it changes every time I run Minesweeper.
What do I need to do to find out the base address automatically?
Does it have something to do with the executable base address?
Here's my code:
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD baseAddress = 0xFF1DAA38;//always changing
DWORD offset1 = 0x18;
DWORD offset2 = 0x20;
DWORD pAddress1;
DWORD pAddress2;
float value = 0;
DWORD pid;
HWND hwnd;
hwnd = FindWindow(NULL,"Minesweeper");
if(!hwnd)//didn't find the window
{
cout <<"Window not found!
";
cin.get();
}
else
{
GetWindowThreadProcessId(hwnd,&pid);
HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,pid);//get permission to read
if(!phandle)//failed to get permission
{
cout <<"Could not get handle!
";
cin.get();
}
else
{
ReadProcessMemory(phandle,(void*)(baseAddress),&pAddress1,sizeof(pAddress1),0);
ReadProcessMemory(phandle,(void*)(pAddress1 + offset1),&pAddress2,sizeof(pAddress2),0);
while(1)
{
ReadProcessMemory(phandle,(void*)(pAddress2 + offset2),&value,sizeof(value),0);
cout << value << "
";
Sleep(1000);
}
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…