forked from jacobjl/autohop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcProcess.h
125 lines (104 loc) · 2.99 KB
/
cProcess.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <time.h>
class CProcess
{
private:
public:
PROCESSENTRY32 pGame;
HANDLE hProcess;
DWORD dwEngine;
DWORD dwOverlay;
DWORD FindProcess(const char *ccName, PROCESSENTRY32 *pEntry)
{
PROCESSENTRY32 pEntry32;
pEntry32.dwSize = sizeof(PROCESSENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
if (!Process32First(hSnapshot, &pEntry32))
{
CloseHandle(hSnapshot);
return 0;
}
do
{
if (!_strcmpi(pEntry32.szExeFile, ccName))
{
memcpy((void *)pEntry, (void *)&pEntry32, sizeof(PROCESSENTRY32));
CloseHandle(hSnapshot);
return pEntry32.th32ProcessID;
}
} while (Process32Next(hSnapshot, &pEntry32));
CloseHandle(hSnapshot);
return 0;
}
DWORD FindThread(DWORD dwProcess)
{
THREADENTRY32 tEntry32;
tEntry32.dwSize = sizeof(THREADENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
if (!Thread32First(hSnapshot, &tEntry32))
{
CloseHandle(hSnapshot);
return 0;
}
do
{
if (tEntry32.th32OwnerProcessID == dwProcess)
{
CloseHandle(hSnapshot);
return tEntry32.th32ThreadID;
}
} while (Thread32Next(hSnapshot, &tEntry32));
CloseHandle(hSnapshot);
return 0;
}
DWORD GetModuleBase(LPSTR lpModuleName, DWORD dwProcessId)
{
MODULEENTRY32 lpModuleEntry = { 0 };
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessId);
if (!hSnapShot) return NULL;
lpModuleEntry.dwSize = sizeof(lpModuleEntry);
BOOL bModule = Module32First(hSnapShot, &lpModuleEntry);
while (bModule)
{
if (!strcmp(lpModuleEntry.szModule, lpModuleName))
{
CloseHandle(hSnapShot);
return (DWORD)lpModuleEntry.modBaseAddr;
}
bModule = Module32Next(hSnapShot, &lpModuleEntry);
}
CloseHandle(hSnapShot);
return NULL;
}
void SetDebugPrivilege()
{
HANDLE hProcess = GetCurrentProcess(), hToken;
TOKEN_PRIVILEGES priv;
LUID luid;
OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);
LookupPrivilegeValue(0, "seDebugPrivilege", &luid);
priv.PrivilegeCount = 1;
priv.Privileges[0].Luid = luid;
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, false, &priv, 0, 0, 0);
CloseHandle(hToken);
CloseHandle(hProcess);
}
void Initialize()
{
SetDebugPrivilege();
while (!FindProcess("svencoop.exe", &pGame)) Sleep(10);
while (!(FindThread(pGame.th32ProcessID))) Sleep(10);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pGame.th32ProcessID);
while (dwEngine == 0x0) dwEngine = GetModuleBase("hw.dll", pGame.th32ProcessID);
while (dwOverlay == 0x0) dwOverlay = GetModuleBase("gameoverlayrenderer.dll", pGame.th32ProcessID);
}
};
extern CProcess gProcess;