-
Notifications
You must be signed in to change notification settings - Fork 14
/
Protect.h
64 lines (55 loc) · 1.5 KB
/
Protect.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
struct ProtectedFunction {
void* address;
size_t size;
BYTE lastXor;
bool crypted;
};
int funcCount = 0;
ProtectedFunction functions[50];
int GetFunctionIndex(void* FunctionAddress) {
for (int i = 0; i < funcCount; i++) {
if ((uintptr_t)functions[i].address <= (uintptr_t)FunctionAddress &&
(uintptr_t)functions[i].address + functions[i].size >= (uintptr_t)FunctionAddress) {
return i;
}
}
return -1;
}
void XOR(BYTE* data, size_t size, BYTE XOR_KEY = 0x6F) {
for (size_t i = 0; i < size; i++) {
data[i] = data[i] ^ XOR_KEY;
}
}
void nextLastXor(int index) {
BYTE xorByte = functions[index].lastXor;
if (xorByte > 0xf3) {
xorByte = 0x5;
}
xorByte += 0x01;
functions[index].lastXor = xorByte;
}
void unsafe_unprotect(int index) {
//XOR((BYTE*)functions[index].address, functions[index].size, functions[index].lastXor);
}
void unsafe_protect(int index) {
nextLastXor(index);
unsafe_unprotect(index);
}
void Unprotect(void* FunctionAddress) {
int function = GetFunctionIndex(FunctionAddress);
if (function > -1 && functions[function].crypted == true) {
unsafe_unprotect(function);
functions[function].crypted = false;
}
}
void Protect(void* FunctionAddress) {
int function = GetFunctionIndex(FunctionAddress);
if (function > -1 && functions[function].crypted == false) {
unsafe_protect(function);
functions[function].crypted = true;
}
}
void addFunc(ProtectedFunction func) {
functions[funcCount] = func;
funcCount++;
}