Happy99

.cpp

Feb 28th, 2020
181
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Memory.h"
  2.  
  3. DWORD Memory::hPID = 0;
  4. BOOL Memory::bPOn = false, Memory::bIOn = false, Memory::bProt = false;
  5. HANDLE Memory::hProc = NULL;
  6.  
  7. bool Memory::DataCompare(const BYTE* pData, const BYTE* pMask, const char* pszMask) {
  8.     for (; *pszMask; ++pszMask, ++pData, ++pMask) {
  9.         if (*pszMask == 'x' && *pData != *pMask) {
  10.             return false;
  11.         }
  12.     }
  13.     return (*pszMask == NULL);
  14. }
  15.  
  16. DWORD Memory::FindPattern(DWORD start, DWORD size, const char* sig, const char* mask) {
  17.     BYTE* data = new BYTE[size];
  18.  
  19.     unsigned long bytesRead;
  20.     if (!ReadProcessMemory(hProc, (LPVOID)start, data, size, &bytesRead)) {
  21.         return NULL;
  22.     }
  23.  
  24.     for (DWORD i = 0; i < size; i++) {
  25.         if (DataCompare((const BYTE*)(data + i), (const BYTE*)sig, mask)) {
  26.             return start + i;
  27.         }
  28.     }
  29.     return NULL;
  30. }
  31.  
  32. DWORD Memory::FindPatternArr(DWORD start, DWORD size, const char* mask, int count, ...) {
  33.     char* sig = new char[count + 1];
  34.     va_list ap;
  35.     va_start(ap, count);
  36.     for (int i = 0; i < count; i++) {
  37.         char read = va_arg(ap, char);
  38.         sig[i] = read;
  39.     }
  40.     va_end(ap);
  41.     sig[count] = '\0';
  42.     return FindPattern(start, size, sig, mask);
  43. }
  44.  
  45.  
  46. bool Memory::Process(char * ProcessName) {
  47.     HANDLE hhPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  48.     PROCESSENTRY32 ProcEntry;
  49.     ProcEntry.dwSize = sizeof(ProcEntry);
  50.  
  51.  
  52.     do
  53.         if (!strcmp(ProcEntry.szExeFile, ProcessName))
  54.         {
  55.  
  56.  
  57.             Memory::hPID = ProcEntry.th32ProcessID;
  58.             CloseHandle(hhPID);
  59.  
  60.  
  61.             Memory::hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, Memory::hPID);
  62.             return true;
  63.         }
  64.     while (Process32Next(hhPID, &ProcEntry));
  65.     return false;
  66. }
  67.  
  68. DWORD Memory::Module(LPSTR ModuleName, DWORD& modSizeTo) {
  69.     HANDLE hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, Memory::hPID);
  70.     MODULEENTRY32 mEntry;
  71.     mEntry.dwSize = sizeof(mEntry);
  72.  
  73.  
  74.     do
  75.         if (!strcmp(mEntry.szModule, ModuleName))
  76.         {
  77.             CloseHandle(hModule);
  78.             modSizeTo = mEntry.modBaseSize;
  79.             return (DWORD)mEntry.modBaseAddr;
  80.         }
  81.     while (Module32Next(hModule, &mEntry));
  82.     return 0;
  83. }
RAW Paste Data