Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <Psapi.h>
- #include <thread>
- #include <vector>
- #include <tlhelp32.h>
- #include <tchar.h>
- using namespace std;
- extern "C"
- {
- DWORD GetProcessBaseAddress(HANDLE processHandle)
- {
- DWORD baseAddress = 0;
- HMODULE* moduleArray;
- LPBYTE moduleArrayBytes;
- DWORD bytesRequired;
- if (processHandle)
- {
- if (EnumProcessModules(processHandle, NULL, 0, &bytesRequired))
- {
- if (bytesRequired)
- {
- moduleArrayBytes = (LPBYTE)LocalAlloc(LPTR, bytesRequired);
- if (moduleArrayBytes)
- {
- unsigned int moduleCount;
- moduleCount = bytesRequired / sizeof(HMODULE);
- moduleArray = (HMODULE*)moduleArrayBytes;
- if (EnumProcessModules(processHandle, moduleArray, bytesRequired, &bytesRequired))
- {
- baseAddress = (DWORD)moduleArray[0];
- }
- LocalFree(moduleArrayBytes);
- }
- }
- }
- CloseHandle(processHandle);
- }
- return baseAddress;
- }
- char* GetModuleBase(const wchar_t* ModuleName, DWORD procID)
- {
- MODULEENTRY32 ModuleEntry = { 0 };
- HANDLE SnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, procID);
- if (!SnapShot) return NULL;
- ModuleEntry.dwSize = sizeof(ModuleEntry);
- if (!Module32First(SnapShot, &ModuleEntry)) return NULL;
- do
- {
- if (!wcscmp(ModuleEntry.szModule, ModuleName))
- {
- CloseHandle(SnapShot);
- return (char*)ModuleEntry.modBaseAddr;
- }
- } while (Module32Next(SnapShot, &ModuleEntry));
- CloseHandle(SnapShot);
- return NULL;
- }
- HANDLE procHandle;
- DWORD entityAddr;
- DWORD baseAddr;
- //string checkAgainst = "d:/game stuff/steam/steam ui/steamapps/common/supreme commander/schook/lua/aibrain.lua";
- //BYTE checkAgainstBT[] = { 0x64,0x3A,0x2F,0x67,0x61,0x6D,0x65,0x20,0x73,0x74,0x75,0x66,0x66,0x2F,0x73,0x74,0x65,0x61,0x6D,0x2F,0x73,0x74,0x65,0x61,0x6D,0x20,0x75,0x69,0x2F,0x73,0x74,0x65,0x61,0x6D,0x61,0x70,0x70,0x73,0x2F,0x63,0x6F,0x6D,0x6D,0x6F,0x6E,0x2F,0x73,0x75,0x70,0x72,0x65,0x6D,0x65,0x20,0x63,0x6F,0x6D,0x6D,0x61,0x6E,0x64,0x65,0x72,0x2F,0x73,0x63,0x68,0x6F,0x6F,0x6B,0x2F,0x6C,0x75,0x61,0x2F,0x61,0x69,0x62,0x72,0x61,0x69,0x6E,0x2E,0x6C,0x75,0x61 };
- BYTE checkAgainstBT[] = { 0x45,0x52,0x52,0x4F,0x52,0x3A,0x20,0x41,0x74,0x74,0x65,0x6D,0x70,0x74,0x20,0x74,0x6F,0x20,0x61,0x64,0x64,0x20,0x55,0x6E,0x69,0x74,0x42,0x75,0x69,0x6C,0x74,0x50,0x65,0x72,0x63,0x65,0x6E,0x74,0x61,0x67,0x65,0x43,0x61,0x6C,0x6C,0x62,0x61,0x63,0x6B,0x20,0x62,0x75,0x74,0x20,0x69,0x6E,0x76,0x61,0x6C,0x69,0x64,0x20,0x64,0x61,0x74,0x61,0x20,0x67,0x69,0x76,0x65,0x6E,0x00 };
- DWORD offsetFromBYTEArr = 0x63;
- DWORD scanAllProcMem(DWORD startAddr, DWORD endAddr)
- {
- //
- // FIND AN EFFICIENT WAY TO DO THIS THAT DOESNT TAKE MORE THAN 10 SECONDS PLEASE
- //
- //cout << hex << GetProcessBaseAddress(procHandle) + 0x30DA0D43 << endl;
- //for (int i = baseAddr + 0x309A0D43;; i++)
- DWORD curAddr;
- BYTE read[sizeof(checkAgainstBT) * 1500];
- ReadProcessMemory(procHandle, (LPCVOID)(startAddr), &read, sizeof(read), NULL);
- for(int i = 0; i < endAddr; i++)
- {
- if (i > sizeof(checkAgainstBT) * 1500)
- ReadProcessMemory(procHandle, (LPCVOID)(startAddr + i), &read, sizeof(read), NULL);
- if (memcmp(checkAgainstBT, read, sizeof(checkAgainstBT)) == 0)
- {
- return startAddr + i + offsetFromBYTEArr;
- }
- /*if (memcmp(checkAgainstBT, read, sizeof(checkAgainstBT)) == 0)
- return i - 0xF0;*/
- /*char read[86];
- string cur;
- for (int x = 0; x < sizeof(read); x++)
- {
- cur += read[x];
- if (cur.length() > 172)
- cur = cur.substr(1, 172);
- if (cur == checkAgainst)
- return i;
- }*/
- }
- //return scanAllProcMem(startAddr, endAddr);
- return NULL;
- }
- __declspec(dllexport) int maxEnergy()
- {
- if (entityAddr != NULL && procHandle != NULL)
- {
- int data = 500;
- ReadProcessMemory(procHandle, (LPCVOID)(entityAddr + 0x28), &data, sizeof(data), 0);
- float dataF = data;
- WriteProcessMemory(procHandle, (LPVOID)entityAddr, &dataF, sizeof(dataF), NULL);
- }
- else
- return 0;
- }
- __declspec(dllexport) int maxMass()
- {
- if (entityAddr != NULL && procHandle != NULL)
- {
- int data = 500;
- ReadProcessMemory(procHandle, (LPCVOID)(entityAddr + 0x30), &data, sizeof(data), 0);
- float dataF = data;
- WriteProcessMemory(procHandle, (LPVOID)(entityAddr + 0x04), &dataF, sizeof(dataF), NULL);
- }
- else
- return 0;
- }
- // FreeER's code
- DWORD readPointerChain(HANDLE phandle, DWORD base, int* offsets, size_t numOffsets)
- {
- DWORD addr = base;
- SIZE_T read;
- for (size_t i = 0; i < numOffsets; i++)
- {
- BOOL success = ReadProcessMemory(phandle, (void*)addr, &addr, sizeof(addr), &read);
- if (!success) { cout << "failed to read " << hex << addr; return 0; }
- addr += offsets[i];
- //cout << "end address " << hex << addr << endl;
- }
- return addr;
- }
- __declspec(dllexport) int scanForProc()
- {
- baseAddr = GetProcessBaseAddress(procHandle);
- HWND hGameWin = FindWindowA(NULL, "Supreme Commander");
- if (hGameWin == NULL)
- {
- procHandle = NULL;
- cout << "no sup com open, dummy!" << endl;
- }
- else
- {
- DWORD procID;
- GetWindowThreadProcessId(hGameWin, &procID);
- procHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
- // [[[[baseaddr] + 0x00994378] + 0x34] + 0x10] + 0x588
- int offsets[] = { 0x920, 0x0, 0x100, 0x10, 0x18, 0x9c, 0x48 };
- entityAddr = readPointerChain(procHandle, (DWORD)(GetModuleBase(L"MohoEngine.dll", procID) + 0x00991030), offsets, sizeof(offsets) / 4) - 0x30;// + 0x00994378 + 0x34 + 0x0 + 0x10 + 0x588;
- int newval = 5000;
- WriteProcessMemory(procHandle, (LPVOID)entityAddr, &newval, sizeof(newval), NULL);
- //entityAddr = scanAllProcMem(0x30B90F77, 0x40000000);
- cout << hex << entityAddr << endl;
- //WriteProcessMemory(procHandle, (LPVOID)0x33981CA8, &newval, sizeof(newval), NULL);
- }
- return entityAddr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement