Guest User

Untitled

a guest
Mar 20th, 2024
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include "memory.h"
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include "skStr.h"
  5. i_memory& i_memory::reeq()
  6. {
  7.     static i_memory ins;
  8.     return ins;
  9. }
  10.  
  11.  
  12. void i_memory::initialize()
  13. {
  14.  
  15.     window = FindWindowA("grcWindow", 0);
  16.     if (!window)
  17.     {
  18.         std::cout << "Fivem not found (start fivem before load)";
  19.     }
  20.     GetWindowThreadProcessId(window, &pid);
  21.     hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
  22.  
  23.  
  24. }
  25.  
  26.  
  27.  
  28. bool i_memory::find_build(const wchar_t* processName) {
  29.  
  30.     bool exists = false;
  31.     PROCESSENTRY32 entry;
  32.     entry.dwSize = sizeof(PROCESSENTRY32);
  33.  
  34.     HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  35.  
  36.     if (Process32First(snapshot, &entry))
  37.         while (Process32Next(snapshot, &entry))
  38.             if (!_wcsicmp(entry.szExeFile, processName))
  39.                 exists = true;
  40.  
  41.     CloseHandle(snapshot);
  42.     return exists;
  43. }
  44.  
  45.  
  46.  
  47. uintptr_t i_memory::get_base_address(std::string a1)
  48. {
  49.     std::wstring pname = std::wstring(a1.begin(), a1.end());
  50.     HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
  51.     if (hSnap == INVALID_HANDLE_VALUE)
  52.         return 0;
  53.     MODULEENTRY32 ent;
  54.     ent.dwSize = sizeof(ent);
  55.     if (Module32First(hSnap, &ent))
  56.     {
  57.         do
  58.         {
  59.             if (!_wcsicmp(ent.szModule, pname.c_str()))
  60.             {
  61.                 std::wcout << "Build :" << ent.szModule << std::endl;
  62.                 CloseHandle(hSnap);
  63.                 return (uintptr_t)ent.modBaseAddr;
  64.             }
  65.         } while (Module32Next(hSnap, &ent));
  66.     }
  67.     CloseHandle(hSnap);
  68.     return 0;
  69. }
  70.  
  71.  
  72. HWND i_memory::get_process_wnd(uint32_t pid)
  73. {
  74.     std::pair<HWND, uint32_t> params = { 0, pid };
  75.     BOOL bResult = EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
  76.         auto pParams = (std::pair<HWND, uint32_t>*)(lParam);
  77.         uint32_t processId = 0;
  78.  
  79.         if (GetWindowThreadProcessId(hwnd, reinterpret_cast<LPDWORD>(&processId)) && processId == pParams->second) {
  80.             SetLastError((uint32_t)-1);
  81.             pParams->first = hwnd;
  82.             return FALSE;
  83.         }
  84.  
  85.         return TRUE;
  86.  
  87.         }, (LPARAM)&params);
  88.  
  89.     if (!bResult && GetLastError() == -1 && params.first)
  90.         return params.first;
  91.  
  92.     return NULL;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment