Memory Hacking with C and CheatEngine, writing to Process Memory
Learn to create a trainer (a program that writes to remote process memory) in C++ using a Calculator as an example. There are also references to cheat engine.
Source Code
#include <iostream>
#include <windows.h>
// FindWindow();
// GetWindowThreadProcessId();
// OpenProcess();
// WriteProcessMemory();
// CloseHandle();
using namespace std;
int main()
{
int newValue = 500;
HWND hWnd = FindWindow(0, "Calculator");
if (hWnd == 0) {
cerr << "Cannot find window." << endl;
} else {
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
if (!hProc) {
cerr << "Cannot open process." << endl;
} else {
int isSuccessful = WriteProcessMemory(hProc, (LPVOID)0x000AFCC4, &newValue, (DWORD)sizeof(newValue), NULL);
if (isSuccessful > 0) {
clog << "Process memory written." << endl;
} else {
cerr << "Cannot write process memory." << endl;
}
CloseHandle(hProc);
}
}
return 0;
}