#include "stdafx.h"
int XMemory::m_iDetaching()
{
if (!m_hndProcessHandle)
{
std::wstring wsErrorText = L"'m_iDetaching' : Invalid handle specified.";
Debug.m_fnAddError(wsErrorText, 1);
return 1;
}
if (!CloseHandle(m_hndProcessHandle))
{
std::wstring wsErrorText = L"'m_iDetaching' : Failed to close handle.";
Debug.m_fnAddError(wsErrorText, 2);
return 2;
}
return 0;
}
int XMemory::m_iAttaching()
{
if (m_iGetProcessHandleByName(&m_hndProcessHandle, Silver.m_wXProcessName))
{
std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXProcessName; wsErrorText += L"' handle.";
Debug.m_fnAddError(wsErrorText, 1);
return 1;
}
if (m_iGetModuleAddressByName(&m_dwClientModuleBaseAddress, Silver.m_wXClientModuleName, m_hndProcessHandle))
{
std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXClientModuleName; wsErrorText += L"' handle.";
Debug.m_fnAddError(wsErrorText, 2);
return 2;
}
if (m_iGetModuleAddressByName(&m_dwEngineModuleBaseAddress, Silver.m_wXEngineModuleName, m_hndProcessHandle))
{
std::wstring wsErrorText = L"'m_iAttaching' : Failed to get '"; wsErrorText += Silver.m_wXEngineModuleName; wsErrorText += L"' handle.";
Debug.m_fnAddError(wsErrorText, 3);
return 3;
}
return 0;
}
int XMemory::m_iGetProcessHandleByName(HANDLE* phndOutput, std::wstring wXProcessName)
{
if (!phndOutput)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Invalid pointer specified.";
Debug.m_fnAddError(wsErrorText, 1);
return 1;
}
PROCESSENTRY32 p32Entry;
p32Entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE hndProcessHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (!hndProcessHandle)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to create snapshot handle.";
Debug.m_fnAddError(wsErrorText, 2);
return 2;
}
if (Process32First(hndProcessHandle, &p32Entry) == TRUE)
{
if (!_wcsicmp(p32Entry.szExeFile, wXProcessName.c_str()))
{
HANDLE hndProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, p32Entry.th32ProcessID);
if (!hndProcessHandle)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to open process handle.";
Debug.m_fnAddError(wsErrorText, 3);
return 3;
}
*phndOutput = hndProcessHandle;
return 0;
}
else
{
while (Process32Next(hndProcessHandle, &p32Entry) == TRUE)
{
if (!_wcsicmp(p32Entry.szExeFile, wXProcessName.c_str()))
{
HANDLE hndProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, p32Entry.th32ProcessID);
if (!hndProcessHandle)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to open process handle.";
Debug.m_fnAddError(wsErrorText, 4);
return 4;
}
*phndOutput = hndProcessHandle;
return 0;
}
}
}
}
int m_iGetProcessHandleByName(HANDLE* phndOutput, std::wstring wsProcessName)
{
if (!phndOutput)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Invalid pointer specified.";
Debug.m_fnAddError(wsErrorText, 1);
return 1;
}
PROCESSENTRY32 p32Entry;
p32Entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE hndProcessHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (!hndProcessHandle)
{
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to create snapshot handle.";
Debug.m_fnAddError(wsErrorText 2);
return 2;
}
if (Module32First(hndProcessHandle, &m32Entry) == TRUE)
{
if (!_wcsicmp(m32Entry.szModule, wsModuleName.c_str()))
{
DWORD dwModuleAdress = (DWORD)m32Entry.modBaseAddr;
if (!dwModuleAddress)
{
std::wstring wsErrorText = L"'m_iGetModuleAddressByName' : Invalid address found.";
Debug.m_fnAddError(wsErrorText, 3);
return 3;
}
*pdwOutput = dwModuleAddress;
return 0;
}
else {
while (Module32Next(hndModuleHandle, &m32Entry) == TRUE)
{
if (!_wsicmp(m32Entry.szModule, wsModuleName.c_str()))
{
DWORD dwModuleAddress = (DWORD)m32Entry.modBaseAddr;
if (!dwModuleAddress)
{
std::wstring wsErrorText = L"'m_iGetModuleAddressByName' : Invalid Address found.";
Debug.m_fnAddError(wsErrorText, 4);
return 4;
}
*pdwOutput = dwModuleAddress;
return 0;
}
}
CloseHandle(hndProcessHandle);
std::wstring wsErrorText = L"'m_iGetProcessHandleByName' : Failed to find process.";
Debug.m_fnAddError(wsErrorText, 5);
return 5;
}
}
}

#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <TlHelp32.h>
__int64 GetModuleBaseAddress(LPCWSTR szProcessName, LPCWSTR szModuleName)
{
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe32;
if (hSnap == INVALID_HANDLE_VALUE)
{
return 0;
}
pe32.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnap, &pe32) == 0)
{
CloseHandle(hSnap);
return 0;
}
do
{
if (lstrcmp(pe32.szExeFile, szProcessName) == 0)
{
int PID;
PID = pe32.th32ProcessID;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID);
MODULEENTRY32 xModule;
if (hSnap == INVALID_HANDLE_VALUE)
{
return 0;
}
xModule.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnap, &xModule) == 0)
{
CloseHandle(hSnap);
return 0;
}
do
{
if (lstrcmp(xModule.szModule, szModuleName) == 0)
{
CloseHandle(hSnap);
return (__int64)xModule.modBaseAddr;
}
} while (Module32Next(hSnap, &xModule));
CloseHandle(hSnap);
return 0;
}
} while (Process32Next(hSnap, &pe32));
CloseHandle(hSnap);
return 0;
}
int main()
{
wchar_t* wCharWindowName = L"Grand Theft Auto V";
wchar_t* GameTitle = L"GTA5.exe";
HWND WindowHandle = FindWindow(NULL, wCharWindowName);
__int64 baseaddr = GetModuleBaseAddress(GameTitle, GameTitle);
DWORD NamePointer = 0x23713DE;
DWORD PlayerInfo = 0x1B29400;
DWORD PlayerOffset = 0x280;
float value = 0;
DWORD pid;
GetWindowThreadProcessId(WindowHandle, &pid);
HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
char* buffer = new char[1];
ReadProcessMemory(phandle, (void*)(baseaddr + 0x23713DE), &buffer[0], 10, 0);
std::cout << "PlayerName: " << buffer;
__int64 pLifeAddress = 0;
while (1)
{
float Life = 0;
ReadProcessMemory(phandle, (void*)(baseaddr + PlayerInfo), &pLifeAddress, sizeof(pLifeAddress), 0);
ReadProcessMemory(phandle, (void*)(pLifeAddress + PlayerOffset), &Life, sizeof(Life), 0);
std::cout << Life << "\n";
Sleep(1000);
}
return 0;
}