SHARE
TWEET

Functions.cpp

a guest Nov 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Functions.h"
  2. bool AttachProcess(const char* processName)
  3. {
  4.     PROCESSENTRY32 procEntry32;
  5.     procEntry32.dwSize = sizeof(PROCESSENTRY32);
  6.  
  7.     HANDLE hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  8.     if (hProcSnap == INVALID_HANDLE_VALUE)
  9.         return false;
  10.  
  11.     while (Process32Next(hProcSnap, &procEntry32))
  12.     {
  13.         if (!strcmp(processName, procEntry32.szExeFile))
  14.         {
  15.             HANDLE temp = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procEntry32.th32ProcessID);
  16.             if (temp == INVALID_HANDLE_VALUE) {
  17.                 CloseHandle(hProcSnap);
  18.                 return false;
  19.             }
  20.  
  21.             pID = procEntry32.th32ProcessID;
  22.             pHandle = temp;
  23.  
  24.             CloseHandle(hProcSnap);
  25.             return true;
  26.         }
  27.     }
  28.  
  29.     CloseHandle(hProcSnap);
  30.     return false;
  31. }
  32. DWORD GetModule(const char* moduleName)
  33. {
  34.     HANDLE hSnapShot;
  35.     hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pID);
  36.  
  37.     MODULEENTRY32 mEntry;
  38.     mEntry.dwSize = sizeof(MODULEENTRY32);
  39.  
  40.     if (hSnapShot == INVALID_HANDLE_VALUE) {
  41.         CloseHandle(hSnapShot);
  42.         return 0;
  43.     }
  44.  
  45.     if (Module32First(hSnapShot, &mEntry))
  46.     {
  47.         if (!strcmp(moduleName, mEntry.szModule))
  48.         {
  49.             CloseHandle(hSnapShot);
  50.             return (DWORD)mEntry.modBaseAddr;
  51.         }
  52.     }
  53.  
  54.     while (Module32Next(hSnapShot, &mEntry))
  55.     {
  56.         if (!strcmp(moduleName, mEntry.szModule))
  57.         {
  58.             CloseHandle(hSnapShot);
  59.             return (DWORD)mEntry.modBaseAddr;
  60.         }
  61.     }
  62.     CloseHandle(hSnapShot);
  63.     return false;
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top