-
Notifications
You must be signed in to change notification settings - Fork 33
/
AntiDebugMethod.cpp
101 lines (84 loc) · 2.66 KB
/
AntiDebugMethod.cpp
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
#include "AntiDebugMethod.h"
#include <algorithm>
int AntiDebugMethod::current_id = 0; // added
bool AntiDebugMethod::anyDetection = false;
std::vector<AntiDebugMethod*> AntiDebugMethod::allInstances;
void AntiDebugMethod::toggleThisMethod(int id) {
AntiDebugMethod* methodPtr = AntiDebugMethod::getMethodById(id);
methodPtr->toggle();
}
AntiDebugMethod* AntiDebugMethod::getMethodById(int id) {
std::vector<AntiDebugMethod*>::iterator it = std::find_if(AntiDebugMethod::allInstances.begin(), AntiDebugMethod::allInstances.end(), [&id] ( const AntiDebugMethod* method) {
return id == method->id;
} );
if (it != AntiDebugMethod::allInstances.end()) {
return *it;
}
else {
return nullptr;
}
}
void AntiDebugMethod::mainLoop() {
std::vector<AntiDebugMethod*>::iterator ptr;
AntiDebugMethod::anyDetection = false;
for (ptr = AntiDebugMethod::allInstances.begin(); ptr < AntiDebugMethod::allInstances.end(); ptr++) {
if ((*ptr)->checkIfDetected() && AntiDebugMethod::anyDetection == false)
{
AntiDebugMethod::anyDetection = true;
std::cout << "detected!" << (*ptr)->name << "\n";
}
}
}
AntiDebugMethod::AntiDebugMethod(bool (*funcPtrParam)(), int windowPosXParam, int windowPosYParam, std::string nameParam) {
funcPtr = funcPtrParam;
windowPosX = windowPosXParam;
windowPosY = windowPosYParam;
name = nameParam;
id = current_id++;
allInstances.push_back(this);
}
void AntiDebugMethod::toggle() {
std::cout << "Function toggle() was called \n";
enabled = !enabled;
detected = false;
char newButtonName[200];
strcpy_s(newButtonName, name.c_str());
if (enabled)
{
strcat_s(newButtonName, "\n ENABLED");
}
else {
strcat_s(newButtonName, "\n DISABLED");
}
SendMessageA(enableButtonHwnd, WM_SETTEXT, 0, (LPARAM)newButtonName);
};
bool AntiDebugMethod::checkIfDetected() {
bool oldDetected = detected;
if (enabled && funcPtr != nullptr) {
detected = funcPtr();
if (oldDetected != detected)
{
char newButtonName[200];
strcpy_s(newButtonName, name.c_str());
strcat_s(newButtonName, "\n ENABLED - DETECTED!");
SendMessageA(enableButtonHwnd, WM_SETTEXT, 0, (LPARAM)newButtonName);
}
} else {
detected = false;
}
return detected;
};
bool AntiDebugMethod::createGUI(HWND hWnd) {
std::cout << "Function createGUI() was called \n";
char newButtonName[100];
strcpy_s(newButtonName, name.c_str());
if (enabled)
{
strcat_s(newButtonName, "\n ENABLED");
}
else {
strcat_s(newButtonName, "\n DISABLED");
}
enableButtonHwnd = CreateWindowA("button", newButtonName, WS_VISIBLE | WS_CHILD | BS_MULTILINE | SS_CENTER, windowPosX, windowPosY, 230, 50, hWnd, (HMENU)(90+id), NULL,NULL);
return 1;
};