Memory hacking

Posts 1–2 of 2 · Page 1 of 1
Memory hacking
console trainer base [CREDITS] Kwak
//==============================
[HTML]#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>

std::string GameStatus;
bool IsGameAvailable;
bool UpdateOnNextRun;

//////////////////////////////
// Params //
//////////////////////////////

// Game window title
LPCSTR LGameWindow = "MyGame"; // MODIFY ME --------------

// Feature 1
std::string sFeature1Status = "OFF";
bool Feature1Status;
int iFeature1Key = VK_F1; // EDIT ME --------------
std::string sFeature1Key = "F1"; // EDIT ME --------------
std::string sFeature1Desc = "Feature 1"; // EDIT ME --------------
BYTE Feature1Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
DWORD Feature1BaseAddress = {0x00000000}; // EDIT ME --------------
int iFeature1Levels = 2; // EDIT ME --------------
DWORD Feature1Offsets[] = {0x0, 0x0}; // EDIT ME --------------

// Feature 2
std::string sFeature2Status = "OFF";
bool Feature2Status;
int iFeature2Key = VK_F2; // EDIT ME --------------
std::string sFeature2Key = "F2"; // EDIT ME --------------
std::string sFeature2Desc = "Feature 2"; // EDIT ME --------------
BYTE Feature2Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
DWORD Feature2BaseAddress = {0x00000000}; // EDIT ME --------------
int iFeature2Levels = 2; // EDIT ME --------------
DWORD Feature2Offsets[] = {0x0, 0x0}; // EDIT ME --------------

// Feature 3
std::string sFeature3Status = "OFF";
bool Feature3Status;
int iFeature3Key = VK_F3; // EDIT ME --------------
std::string sFeature3Key = "F3"; // EDIT ME --------------
std::string sFeature3Desc = "Feature 3"; // EDIT ME --------------
BYTE Feature3Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
DWORD Feature3BaseAddress = {0x00000000}; // EDIT ME --------------
int iFeature3Levels = 2; // EDIT ME --------------
DWORD Feature3Offsets[] = {0x0, 0x0}; // EDIT ME --------------

DWORD findDmaAddress(HANDLE hProcHandle, int levelNumber, DWORD Offsets[], DWORD BaseAddress)
{
DWORD pointer = BaseAddress;
DWORD pTemp;
DWORD pointerAddress;

for (int i=0; i<levelNumber; i++)
{
if (i == 0)
{
ReadProcessMemory(hProcHandle, (LPCVOID) pointer, &pTemp, sizeof(pTemp), NULL);
}

pointerAddress = pTemp + Offsets[i];
ReadProcessMemory(hProcHandle, (LPCVOID) pointerAddress, &pTemp, sizeof(pTemp), NULL);
}

return pointerAddress;
}

int main()
{
HWND hGameWindow = NULL;
int iTimeSinceLastUpdate = clock();
int iGameAvailableTMR = clock();
int iOnePressTMR = clock();
DWORD dwProcID = NULL;
HANDLE hProcHandle = NULL;
UpdateOnNextRun = true;

while (!GetAsyncKeyState(VK_INSERT))
{
if (clock() - iGameAvailableTMR > 100)
{
iGameAvailableTMR = clock();
IsGameAvailable = false;
hGameWindow = FindWindow(NULL, LGameWindow);
if (hGameWindow)
{
GetWindowThreadProcessId(hGameWindow, &dwProcID);
if (dwProcID != 0)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
GameStatus = "[ERROR] Failed to open process for valid handle";
}
else
{
GameStatus = "[SUCCESS] Game is ready to hack";
IsGameAvailable = true;
}
}
else
{
GameStatus = "[ERROR] Failed to get process ID";
}
}
else
{
GameStatus = "[ERROR] Game cannot be found";
}
}

if (UpdateOnNextRun || clock() - iTimeSinceLastUpdate > 5000)
{
system("cls");
std::cout << "--------------------------------------------" << std::endl;
std::cout << " MMHT" << std::endl;
std::cout << " My memory hack tool" << std::endl;
std::cout << "--------------------------------------------" << std::endl << std::endl;
std::cout << "Status: " << GameStatus << std::endl << std::endl;
std::cout << "[" << sFeature1Key << "] " << sFeature1Desc << " ->" << sFeature1Status << "<-" << std::endl;
std::cout << "[" << sFeature2Key << "] " << sFeature2Desc << " ->" << sFeature2Status << "<-" << std::endl;
std::cout << "[" << sFeature3Key << "] " << sFeature3Desc << " ->" << sFeature3Status << "<-" << std::endl;
std::cout << std::endl << "[INSERT] Exit" << std::endl;

UpdateOnNextRun = false;
iTimeSinceLastUpdate = clock();
}

if (IsGameAvailable)
{
DWORD AddressToWrite;

// Memory hacking
if (Feature1Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature1Levels, Feature1Offsets, Feature1BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature1Value, sizeof(Feature1Value), NULL);
}
else if (Feature2Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature2Levels, Feature2Offsets, Feature2BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature2Value, sizeof(Feature2Value), NULL);
}
else if (Feature3Status)
{
AddressToWrite = findDmaAddress(hProcHandle, iFeature3Levels, Feature3Offsets, Feature3BaseAddress);
WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature3Value, sizeof(Feature3Value), NULL);
}
}

if (IsGameAvailable && clock() - iOnePressTMR > 400)
{
// Key pressed
if (GetAsyncKeyState(iFeature1Key))
{
iOnePressTMR = clock();
Feature1Status = !Feature1Status;
UpdateOnNextRun = true;
sFeature1Status = Feature1Status ? "ON" : "OFF";
}
else if (GetAsyncKeyState(iFeature2Key))
{
iOnePressTMR = clock();
Feature2Status = !Feature2Status;
UpdateOnNextRun = true;
sFeature2Status = Feature2Status ? "ON" : "OFF";
}
else if (GetAsyncKeyState(iFeature3Key))
{
iOnePressTMR = clock();
Feature3Status = !Feature3Status;
UpdateOnNextRun = true;
sFeature3Status = Feature3Status ? "ON" : "OFF";
}
}
}

CloseHandle(hProcHandle);
CloseHandle(hGameWindow);

return ERROR_SUCCESS;
}[/HTML]
Code:
#include <iostream>
 #include <Windows.h>
 #include <string>
 #include <ctime>

 std::string GameStatus;
 bool IsGameAvailable;
 bool UpdateOnNextRun;

 //////////////////////////////
 // Params //
 //////////////////////////////

 // Game window title
 LPCSTR LGameWindow = "MyGame"; // MODIFY ME --------------

 // Feature 1
 std::string sFeature1Status = "OFF";
 bool Feature1Status;
 int iFeature1Key = VK_F1; // EDIT ME --------------
 std::string sFeature1Key = "F1"; // EDIT ME --------------
 std::string sFeature1Desc = "Feature 1"; // EDIT ME --------------
 BYTE Feature1Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
 DWORD Feature1BaseAddress = {0x00000000}; // EDIT ME --------------
 int iFeature1Levels = 2; // EDIT ME --------------
 DWORD Feature1Offsets[] = {0x0, 0x0}; // EDIT ME --------------

 // Feature 2
 std::string sFeature2Status = "OFF";
 bool Feature2Status;
 int iFeature2Key = VK_F2; // EDIT ME --------------
 std::string sFeature2Key = "F2"; // EDIT ME --------------
 std::string sFeature2Desc = "Feature 2"; // EDIT ME --------------
 BYTE Feature2Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
 DWORD Feature2BaseAddress = {0x00000000}; // EDIT ME --------------
 int iFeature2Levels = 2; // EDIT ME --------------
 DWORD Feature2Offsets[] = {0x0, 0x0}; // EDIT ME --------------

 // Feature 3
 std::string sFeature3Status = "OFF";
 bool Feature3Status;
 int iFeature3Key = VK_F3; // EDIT ME --------------
 std::string sFeature3Key = "F3"; // EDIT ME --------------
 std::string sFeature3Desc = "Feature 3"; // EDIT ME --------------
 BYTE Feature3Value[] = {0xF, 0xF, 0x0, 0x0}; // EDIT ME --------------
 DWORD Feature3BaseAddress = {0x00000000}; // EDIT ME --------------
 int iFeature3Levels = 2; // EDIT ME --------------
 DWORD Feature3Offsets[] = {0x0, 0x0}; // EDIT ME --------------

 DWORD findDmaAddress(HANDLE hProcHandle, int levelNumber, DWORD Offsets[], DWORD BaseAddress)
 {
 DWORD pointer = BaseAddress;
 DWORD pTemp;
 DWORD pointerAddress;

 for (int i=0; i<levelNumber; i++)
 {
 if (i == 0)
 {
 ReadProcessMemory(hProcHandle, (LPCVOID) pointer, &pTemp, sizeof(pTemp), NULL);
 }

 pointerAddress = pTemp + Offsets[i];
 ReadProcessMemory(hProcHandle, (LPCVOID) pointerAddress, &pTemp, sizeof(pTemp), NULL);
 }

 return pointerAddress;
 }

 int main()
 {
 HWND hGameWindow = NULL;
 int iTimeSinceLastUpdate = clock();
 int iGameAvailableTMR = clock();
 int iOnePressTMR = clock();
 DWORD dwProcID = NULL;
 HANDLE hProcHandle = NULL;
 UpdateOnNextRun = true;

 while (!GetAsyncKeyState(VK_INSERT))
 {
 if (clock() - iGameAvailableTMR > 100)
 {
 iGameAvailableTMR = clock();
 IsGameAvailable = false;
 hGameWindow = FindWindow(NULL, LGameWindow);
 if (hGameWindow)
 {
 GetWindowThreadProcessId(hGameWindow, &dwProcID);
 if (dwProcID != 0)
 {
 hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
 if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
 {
 GameStatus = "[ERROR] Failed to open process for valid handle";
 }
 else
 {
 GameStatus = "[SUCCESS] Game is ready to hack";
 IsGameAvailable = true;
 }
 }
 else
 {
 GameStatus = "[ERROR] Failed to get process ID";
 }
 }
 else
 {
 GameStatus = "[ERROR] Game cannot be found";
 }
 }

 if (UpdateOnNextRun || clock() - iTimeSinceLastUpdate > 5000)
 {
 system("cls");
 std::cout << "--------------------------------------------" << std::endl;
 std::cout << " MMHT" << std::endl;
 std::cout << " My memory hack tool" << std::endl;
 std::cout << "--------------------------------------------" << std::endl << std::endl;
 std::cout << "Status: " << GameStatus << std::endl << std::endl;
 std::cout << "[" << sFeature1Key << "] " << sFeature1Desc << " ->" << sFeature1Status << "<-" << std::endl;
 std::cout << "[" << sFeature2Key << "] " << sFeature2Desc << " ->" << sFeature2Status << "<-" << std::endl;
 std::cout << "[" << sFeature3Key << "] " << sFeature3Desc << " ->" << sFeature3Status << "<-" << std::endl;
 std::cout << std::endl << "[INSERT] Exit" << std::endl;

 UpdateOnNextRun = false;
 iTimeSinceLastUpdate = clock();
 }

 if (IsGameAvailable)
 {
 DWORD AddressToWrite;

 // Memory hacking
 if (Feature1Status)
 {
 AddressToWrite = findDmaAddress(hProcHandle, iFeature1Levels, Feature1Offsets, Feature1BaseAddress);
 WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature1Value, sizeof(Feature1Value), NULL);
 }
 else if (Feature2Status)
 {
 AddressToWrite = findDmaAddress(hProcHandle, iFeature2Levels, Feature2Offsets, Feature2BaseAddress);
 WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature2Value, sizeof(Feature2Value), NULL);
 }
 else if (Feature3Status)
 {
 AddressToWrite = findDmaAddress(hProcHandle, iFeature3Levels, Feature3Offsets, Feature3BaseAddress);
 WriteProcessMemory(hProcHandle, (BYTE*) AddressToWrite, &Feature3Value, sizeof(Feature3Value), NULL);
 }
 }

 if (IsGameAvailable && clock() - iOnePressTMR > 400)
 {
 // Key pressed
 if (GetAsyncKeyState(iFeature1Key))
 {
 iOnePressTMR = clock();
 Feature1Status = !Feature1Status;
 UpdateOnNextRun = true;
 sFeature1Status = Feature1Status ? "ON" : "OFF";
 }
 else if (GetAsyncKeyState(iFeature2Key))
 {
 iOnePressTMR = clock();
 Feature2Status = !Feature2Status;
 UpdateOnNextRun = true;
 sFeature2Status = Feature2Status ? "ON" : "OFF";
 }
 else if (GetAsyncKeyState(iFeature3Key))
 {
 iOnePressTMR = clock();
 Feature3Status = !Feature3Status;
 UpdateOnNextRun = true;
 sFeature3Status = Feature3Status ? "ON" : "OFF";
 }
 }
 }

 CloseHandle(hProcHandle);
 CloseHandle(hGameWindow);

 return ERROR_SUCCESS;
 }
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us