-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathutils.h
More file actions
216 lines (188 loc) · 6.08 KB
/
utils.h
File metadata and controls
216 lines (188 loc) · 6.08 KB
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
#pragma once
#define PHNT_VERSION PHNT_WIN10_22H2
#include <phnt_windows.h>
#include <phnt.h>
#include <ntexapi.h>
#include <ntpsapi.h>
#include <stdint.h>
#include <share.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <filesystem>
#include "systemhooks.h"
const extern WCHAR* BadProcessnameList[];
const extern WCHAR* BadWindowTextList[];
const extern WCHAR* BadWindowClassList[];
const uint64_t EndOfTextSection = 0xd75c000;
const uint64_t StartOfTextSection = 0x7FF71AA91000;
const uint64_t StartOfBinary = 0x7FF71AA90000;
extern FILE* logFile;
extern bool suspendNewThreads;
// temporary fix until we nop out all the arxan "self healing" spots in the executable
struct intactChecksumHook
{
uint64_t* functionAddress;
uint8_t buffer[7];
};
struct intactBigChecksumHook
{
uint64_t* functionAddress;
uint8_t buffer[7+3];
};
struct splitChecksumHook
{
uint64_t* functionAddress;
uint8_t buffer[8];
};
enum checksumType {
intactSmall,
intactBig,
split
};
struct inlineAsmStub {
void* functionAddress;
uint8_t* buffer;
size_t bufferSize;
checksumType type;
};
enum Condition { Execute = 0, Write = 1, ReadWrite = 3 };
void removeAllHardwareBP();
void SuspendAllThreads();
void placeHardwareBP(void* addr, int count, Condition condition);
bool RtlUnicodeStringContains(PUNICODE_STRING Str, PUNICODE_STRING SubStr, BOOLEAN CaseInsensitive);
bool IsWindowClassNameBad(PUNICODE_STRING className);
bool IsWindowNameBad(PUNICODE_STRING windowName);
bool IsWindowBad(HWND hWnd);
void FilterHwndList(HWND* phwndFirst, PULONG pcHwndNeeded);
void ManualHookFunction(uint64_t functionAddress, uint64_t setInfoOffset);
std::string GetLastErrorAsString();
inline void SetBits(unsigned long& dw, int lowBit, int bits, int newValue)
{
int mask = (1 << bits) - 1; // e.g. 1 becomes 0001, 2 becomes 0011, 3 becomes 0111
dw = (dw & ~(mask << lowBit)) | (newValue << lowBit);
}
bool remove_evil_keywords_from_string(const UNICODE_STRING& string);
FILE* fmemopen(void* buf, size_t len, const char* type);
bool is_relatively_far(const void* pointer, const void* data);
uint8_t* allocate_somewhere_near(const void* base_address, const size_t size);
uint32_t reverse_bytes(uint32_t bytes);
#define pushad64() a.push(asmjit::x86::rax); \
a.push(asmjit::x86::rcx); \
a.push(asmjit::x86::rdx); \
a.push(asmjit::x86::rbx); \
a.push(asmjit::x86::rsp); \
a.push(asmjit::x86::rbp); \
a.push(asmjit::x86::rsi); \
a.push(asmjit::x86::rdi); \
a.push(asmjit::x86::r8); \
a.push(asmjit::x86::r9); \
a.push(asmjit::x86::r10); \
a.push(asmjit::x86::r11); \
a.push(asmjit::x86::r12); \
a.push(asmjit::x86::r13); \
a.push(asmjit::x86::r14); \
a.push(asmjit::x86::r15);
#define popad64() a.pop(asmjit::x86::r15); \
a.pop(asmjit::x86::r14); \
a.pop(asmjit::x86::r13); \
a.pop(asmjit::x86::r12); \
a.pop(asmjit::x86::r11); \
a.pop(asmjit::x86::r10); \
a.pop(asmjit::x86::r9); \
a.pop(asmjit::x86::r8); \
a.pop(asmjit::x86::rdi); \
a.pop(asmjit::x86::rsi); \
a.pop(asmjit::x86::rbp); \
a.pop(asmjit::x86::rsp); \
a.pop(asmjit::x86::rbx); \
a.pop(asmjit::x86::rdx); \
a.pop(asmjit::x86::rcx); \
a.pop(asmjit::x86::rax);
#define popad64WithoutRAX() a.pop(asmjit::x86::r11); \
a.pop(asmjit::x86::r10); \
a.pop(asmjit::x86::r9); \
a.pop(asmjit::x86::r8); \
a.pop(asmjit::x86::rdi); \
a.pop(asmjit::x86::rsi); \
a.pop(asmjit::x86::rbp); \
a.pop(asmjit::x86::rsp); \
a.pop(asmjit::x86::rbx); \
a.pop(asmjit::x86::rdx); \
a.pop(asmjit::x86::rcx);
// TODO: if we remove any of the r15 14 13 registers on the popad64 macro it crashes the game
// think we messed up the stack or something on the checksum stub generation
// fix it later, for now use these so we can actually use the r12-r15 registers since those are non violatile
#define pushad64_Min() a.push(asmjit::x86::rax); \
a.push(asmjit::x86::rcx); \
a.push(asmjit::x86::rdx); \
a.push(asmjit::x86::rbx); \
a.push(asmjit::x86::rsp); \
a.push(asmjit::x86::rbp); \
a.push(asmjit::x86::rsi); \
a.push(asmjit::x86::rdi); \
a.push(asmjit::x86::r8); \
a.push(asmjit::x86::r9); \
a.push(asmjit::x86::r10); \
a.push(asmjit::x86::r11);
#define popad64_Min() a.pop(asmjit::x86::r11); \
a.pop(asmjit::x86::r10); \
a.pop(asmjit::x86::r9); \
a.pop(asmjit::x86::r8); \
a.pop(asmjit::x86::rdi); \
a.pop(asmjit::x86::rsi); \
a.pop(asmjit::x86::rbp); \
a.pop(asmjit::x86::rsp); \
a.pop(asmjit::x86::rbx); \
a.pop(asmjit::x86::rdx); \
a.pop(asmjit::x86::rcx); \
a.pop(asmjit::x86::rax);
/*
#define pushad64() a.push(asmjit::x86::rax); \
a.push(asmjit::x86::rcx); \
a.push(asmjit::x86::rdx); \
a.push(asmjit::x86::rbx); \
a.push(asmjit::x86::rsp); \
a.push(asmjit::x86::rbp); \
a.push(asmjit::x86::rsi); \
a.push(asmjit::x86::rdi); \
a.push(asmjit::x86::r8); \
a.push(asmjit::x86::r9); \
a.push(asmjit::x86::r10); \
a.push(asmjit::x86::r11); \
a.push(asmjit::x86::r12); \
a.push(asmjit::x86::r13); \
a.push(asmjit::x86::r14); \
a.push(asmjit::x86::r15);
#define popad64() a.pop(asmjit::x86::r15); \
a.pop(asmjit::x86::r14); \
a.pop(asmjit::x86::r13); \
a.pop(asmjit::x86::r12); \
a.pop(asmjit::x86::r11); \
a.pop(asmjit::x86::r10); \
a.pop(asmjit::x86::r9); \
a.pop(asmjit::x86::r8); \
a.pop(asmjit::x86::rdi); \
a.pop(asmjit::x86::rsi); \
a.pop(asmjit::x86::rbp); \
a.pop(asmjit::x86::rsp); \
a.pop(asmjit::x86::rbx); \
a.pop(asmjit::x86::rdx); \
a.pop(asmjit::x86::rcx); \
a.pop(asmjit::x86::rax);
#define popad64WithoutRAX() a.pop(asmjit::x86::r15); \
a.pop(asmjit::x86::r14); \
a.pop(asmjit::x86::r13); \
a.pop(asmjit::x86::r12); \
a.pop(asmjit::x86::r11); \
a.pop(asmjit::x86::r10); \
a.pop(asmjit::x86::r9); \
a.pop(asmjit::x86::r8); \
a.pop(asmjit::x86::rdi); \
a.pop(asmjit::x86::rsi); \
a.pop(asmjit::x86::rbp); \
a.pop(asmjit::x86::rsp); \
a.pop(asmjit::x86::rbx); \
a.pop(asmjit::x86::rdx); \
a.pop(asmjit::x86::rcx);
*/