#include <Windows.h>
#include <iostream>
#include <vector>
#include <TlHelp32.h>
DWORD GetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *lpszModuleName)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessIdentifier);
DWORD dwModuleBaseAddress = 0;
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32 = { 0 };
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (strcmp(ModuleEntry32.szModule, lpszModuleName) == 0)
{
dwModuleBaseAddress = (DWORD)ModuleEntry32.modBaseAddr;
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
return dwModuleBaseAddress;
}
DWORD getPointer(HANDLE pHandle, DWORD pID, char name[], std::vector<DWORD> offsets) {
DWORD gameBase = GetModuleBaseAddress(pID, name);
DWORD address = gameBase;
if (offsets.empty()) {
return NULL;
}
address += offsets[0];
for (std::vector<DWORD>::iterator it = offsets.begin() + 1; it != offsets.end(); ++it) {
ReadProcessMemory(pHandle, (LPVOID)address, &address, 4, 0);
address = address + *it;
}
if (address <= gameBase) { // Increase accuracy
return NULL;
}
return address;
}
DWORD getPID(char procName[]) {
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
DWORD pID = 0;
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (_stricmp(entry.szExeFile, procName) == 0)
{
pID = entry.th32ProcessID;
break;
}
}
}
CloseHandle(snapshot);
return pID;
}
int main() {
char gameName[] = " Shipping.exe";
std::vector<DWORD> offsets = { 0x02d3b0f0 , 0x3A0, 0x318 };
DWORD pID = getPID(gameName);
if (!pID) {
std::cout << "Could not find game." << std::endl;
std::cin.get();
return 1;
}
HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, false, pID);
if (!pHandle) {
std::cout << "Could not obtain handle." << std::endl;
std::cin.get();
return 2;
}
DWORD pointerAddress = getPointer(pHandle, pID, gameName, offsets);
if (!pointerAddress) {
std::cout << "Invalid pointer." << std::endl;
std::cin.get();
return 3;
}
std::cout << "Your address is : " << std::hex << pointerAddress << std::endl;
std::cin.get();
return 0;
}