fbn

csgo HackProcess.h

fbn
Dec 22nd, 2014
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.63 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <Windows.h>
  4. #include <TlHelp32.h>
  5.  
  6. //THIS FILE SIMPLY DOES MOST OF THE BACKEND WORK FOR US,
  7. //FROM FINDING THE PROCESS TO SETTING UP CORRECT ACCESS FOR US
  8. //TO EDIT MEMORY
  9. //IN MOST GAMES, A SIMPLER VERSION OF THIS CAN BE USED, or if you're injecting then its often not necessary
  10. //This file has been online for quite a while so credits should be shared but im using this from NubTIK
  11. //So Credits to him and thanks
  12.  
  13. class CHackProcess
  14. {
  15. public:
  16.  
  17.     PROCESSENTRY32 __gameProcess;
  18.     HANDLE __HandleProcess;
  19.     HWND __HWNDCsgo;
  20.     DWORD __dwordClient;
  21.     DWORD __dwordEngine;
  22.     DWORD __dwordOverlay;
  23.     DWORD __dwordVGui;
  24.     DWORD __dwordServer;
  25.     DWORD __dwordLibCef;
  26.     DWORD __dwordSteam;
  27.     DWORD FindProcessName(const char *__ProcessName, PROCESSENTRY32 *pEntry)
  28.     {    
  29.         PROCESSENTRY32 __ProcessEntry;
  30.         __ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
  31.         HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  32.         if (hSnapshot == INVALID_HANDLE_VALUE) return 0;        if (!Process32First(hSnapshot, &__ProcessEntry))
  33.         {
  34.             CloseHandle(hSnapshot);
  35.             return 0;
  36.         }
  37.         do{if (!_strcmpi(__ProcessEntry.szExeFile, __ProcessName))
  38.         {
  39.             memcpy((void *)pEntry, (void *)&__ProcessEntry, sizeof(PROCESSENTRY32));
  40.             CloseHandle(hSnapshot);
  41.             return __ProcessEntry.th32ProcessID;
  42.         }} while (Process32Next(hSnapshot, &__ProcessEntry));
  43.         CloseHandle(hSnapshot);
  44.         return 0;
  45.     }
  46.  
  47.     DWORD getThreadByProcess(DWORD __DwordProcess)
  48.     {    
  49.             THREADENTRY32 __ThreadEntry;
  50.             __ThreadEntry.dwSize = sizeof(THREADENTRY32);
  51.             HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
  52.             if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
  53.  
  54.             if (!Thread32First(hSnapshot, &__ThreadEntry)) {CloseHandle(hSnapshot); return 0; }
  55.  
  56.             do {if (__ThreadEntry.th32OwnerProcessID == __DwordProcess)
  57.             {
  58.                 CloseHandle(hSnapshot);
  59.                 return __ThreadEntry.th32ThreadID;
  60.             }} while (Thread32Next(hSnapshot, &__ThreadEntry));
  61.             CloseHandle(hSnapshot);      
  62.             return 0;
  63.     }
  64.  
  65.     DWORD GetModuleNamePointer(LPSTR LPSTRModuleName, DWORD __DwordProcessId)
  66.     {
  67.             MODULEENTRY32 lpModuleEntry = {0};
  68.             HANDLE hSnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, __DwordProcessId);
  69.             if(!hSnapShot)
  70.                 return NULL;  
  71.             lpModuleEntry.dwSize = sizeof(lpModuleEntry);
  72.             BOOL __RunModule = Module32First( hSnapShot, &lpModuleEntry );
  73.             while(__RunModule)
  74.             {
  75.                 if(!strcmp(lpModuleEntry.szModule, LPSTRModuleName ) )
  76.                 {CloseHandle( hSnapShot );
  77.                 return (DWORD)lpModuleEntry.modBaseAddr;
  78.                 }
  79.                 __RunModule = Module32Next( hSnapShot, &lpModuleEntry );
  80.             }
  81.             CloseHandle( hSnapShot );
  82.             return NULL;
  83.     }
  84.  
  85.     void runSetDebugPrivs()
  86.     {
  87.         HANDLE __HandleProcess=GetCurrentProcess(), __HandleToken;
  88.         TOKEN_PRIVILEGES priv;
  89.         LUID __LUID;
  90.         OpenProcessToken(__HandleProcess, TOKEN_ADJUST_PRIVILEGES, &__HandleToken);
  91.         LookupPrivilegeValue(0, "seDebugPrivilege", &__LUID);
  92.         priv.PrivilegeCount = 1;
  93.         priv.Privileges[0].Luid = __LUID;
  94.         priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  95.         AdjustTokenPrivileges(__HandleToken, false, &priv, 0, 0, 0);
  96.         CloseHandle(__HandleToken);
  97.         CloseHandle(__HandleProcess);
  98.     }
  99.      
  100.     void RunProcess()
  101.     {
  102.         //commented lines are for non steam versions of the game
  103.         runSetDebugPrivs();
  104.         while (!FindProcessName("csgo.exe", &__gameProcess)) Sleep(12);
  105.         while (!(getThreadByProcess(__gameProcess.th32ProcessID))) Sleep(12);
  106.         __HandleProcess = OpenProcess(PROCESS_ALL_ACCESS, false, __gameProcess.th32ProcessID);
  107.         while(__dwordClient == 0x0) __dwordClient = GetModuleNamePointer("client.dll", __gameProcess.th32ProcessID);
  108.         while(__dwordEngine == 0x0) __dwordEngine = GetModuleNamePointer("engine.dll", __gameProcess.th32ProcessID);
  109.         while(__dwordVGui == 0x0) __dwordVGui = GetModuleNamePointer("vguimatsurface.dll", __gameProcess.th32ProcessID);
  110.         while(__dwordServer == 0x0)__dwordServer = GetModuleNamePointer("server.dll", __gameProcess.th32ProcessID);
  111.         __HWNDCsgo = FindWindow(NULL, "Counter-Strike: Global Offensive");
  112.     }
  113. };
  114.  
  115. extern CHackProcess fProcess;
Advertisement
Add Comment
Please, Sign In to add comment