-
Notifications
You must be signed in to change notification settings - Fork 32
/
HackProcess.h
226 lines (174 loc) · 5.69 KB
/
HackProcess.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#pragma once
#include <Windows.h>
#include <TlHelp32.h>
#include <psapi.h>
//THIS FILE SIMPLY DOES MOST OF THE BACKEND WORK FOR US,
//FROM FINDING THE PROCESS TO SETTING UP CORRECT ACCESS FOR US
//TO EDIT MEMORY
//IN MOST GAMES, A SIMPLER VERSION OF THIS CAN BE USED, or if you're injecting then its often not necessary
//This file has been online for quite a while so credits should be shared but im using this from NubTIK
//So Credits to him and thanks
class CHackProcess
{
public:
HANDLE _GameHandle;
DWORD _GameProcessID;
CHAR* _GameProcessName;
HANDLE Open(DWORD ProcessID)
{
_GameProcessID = ProcessID;
_GameHandle = OpenProcess(PROCESS_ALL_ACCESS, NULL, ProcessID);
return _GameHandle;
}
BOOL Close()
{
return CloseHandle(_GameHandle);
}
DWORD GetProcess(CHAR *__ProcessName, PROCESSENTRY32 *pEntry)//进程名获取进程信息
{
_GameProcessName = __ProcessName;
PROCESSENTRY32 __ProcessEntry;
__ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
if (!Process32First(hSnapshot, &__ProcessEntry))
{
CloseHandle(hSnapshot);
return 0;
}
do{if (!_strcmpi(__ProcessEntry.szExeFile, __ProcessName))
{
memcpy((void *)pEntry, (void *)&__ProcessEntry, sizeof(PROCESSENTRY32));
CloseHandle(hSnapshot);
Open(__ProcessEntry.th32ProcessID);
return __ProcessEntry.th32ProcessID;//返回进程ID
}} while (Process32Next(hSnapshot, &__ProcessEntry));
CloseHandle(hSnapshot);
return 0;
}
INT64 GetProcessModuleOffset()
{
MODULEENTRY32 lpModuleEntry = { 0 };
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, _GameProcessID);
if (!hSnapShot)
return NULL;
lpModuleEntry.dwSize = sizeof(lpModuleEntry);
BOOL __RunModule = Module32First(hSnapShot, &lpModuleEntry);
while (__RunModule)
{
if (!_strcmpi(lpModuleEntry.szModule, _GameProcessName))
{
CloseHandle(hSnapShot);
return (INT64)lpModuleEntry.modBaseAddr;
}
__RunModule = Module32Next(hSnapShot, &lpModuleEntry);
}
CloseHandle(hSnapShot);
return NULL;
}
template <class T> T Read(INT64 dwAddress)
{
T value;
ReadProcessMemory(_GameHandle, (LPVOID)dwAddress, &value, sizeof(T), NULL);
return value;
}
template <class T> bool Write(INT64 dwAddress, T ValueToWrite)
{
return WriteProcessMemory(_GameHandle, (LPVOID)dwAddress, &ValueToWrite, sizeof(T), NULL) == TRUE;
}
bool IsValid32(int address)
{
return (address >= 0x40000 && address < 0x7fffffff);
}
bool IsValid64(INT64 address)
{
return (address >= 0x400000 && address < 0x000F000000000000);
}
DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcID, TCHAR *szModuleName)
{
DWORD_PTR dwModuleBaseAddress = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 ModuleEntry32;
ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
if (Module32First(hSnapshot, &ModuleEntry32))
{
do
{
if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
{
dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
break;
}
} while (Module32Next(hSnapshot, &ModuleEntry32));
}
CloseHandle(hSnapshot);
}
return dwModuleBaseAddress;
}
DWORD getThreadByProcess(DWORD __DwordProcess)
{
THREADENTRY32 __ThreadEntry;
__ThreadEntry.dwSize = sizeof(THREADENTRY32);
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot == INVALID_HANDLE_VALUE) return 0;
if (!Thread32First(hSnapshot, &__ThreadEntry)) {CloseHandle(hSnapshot); return 0; }
do {if (__ThreadEntry.th32OwnerProcessID == __DwordProcess)
{
CloseHandle(hSnapshot);
return __ThreadEntry.th32ThreadID;
}} while (Thread32Next(hSnapshot, &__ThreadEntry));
CloseHandle(hSnapshot);
return 0;
}
void ReadShare(char *ShareValue, LPSTR Name)
{
LPSTR lpMapAddr;
HANDLE m_hMapFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Name);
if (m_hMapFile)
{
lpMapAddr = (LPSTR)MapViewOfFile(m_hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
memcpy(ShareValue, lpMapAddr, strlen(lpMapAddr) - 8); //-8 对应超级模块8.0 的指针 .写共享
UnmapViewOfFile(lpMapAddr);
CloseHandle(m_hMapFile);
}
else
{
memset(ShareValue, 0, strlen(ShareValue));
}
}
DWORD GetProcessID(char *FileName)//取进程ID,(进程名)
{
HANDLE myhProcess;
PROCESSENTRY32 mype;
mype.dwSize = sizeof(PROCESSENTRY32);
BOOL mybRet;
myhProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
mybRet = Process32First(myhProcess, &mype);
while (mybRet)
{
if (strcmp(FileName, mype.szExeFile) == 0)
return mype.th32ProcessID;
else
mybRet = Process32Next(myhProcess, &mype);
}
return 0;
}
int EnableDebugPriv(char* name)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
//打开进程令牌环
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
//获得进程本地唯一ID
LookupPrivilegeValue(NULL, name, &luid);
tp.PrivilegeCount = 1;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
tp.Privileges[0].Luid = luid;
//调整权限
AdjustTokenPrivileges(hToken, 0, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL);
return 0;
}
};