-
Notifications
You must be signed in to change notification settings - Fork 1
/
GuardThread.cpp
168 lines (138 loc) · 4.01 KB
/
GuardThread.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
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
#include <windows.h>
#include <vector>
#include <string>
#include "ScannerInterface.h"
#include "ImportScanner.h"
#include "MemoryScanner.h"
#include "ProcessNameScanner.h"
#include "WindowNameScanner.h"
#include "WindowClassScanner.h"
#include "Singleton.h"
#include "Stream.h"
#include "GuardThread.h"
#define SECURITY_WIN32
#define SCAN_INTERVAL 1000
RLKTGuard::RLKTGuard()
{
}
RLKTGuard::~RLKTGuard()
{
for (auto& it : m_pVecScanners)
{
delete it;
}
m_pVecScanners.clear();
}
bool RLKTGuard::Initialize()
{
AddScanner(ScannerInterface::eScannerType::IMPORT, new ImportScanner(), true);
AddScanner(ScannerInterface::eScannerType::MEMORY, new MemoryScanner(), true);
AddScanner(ScannerInterface::eScannerType::PROCESS, new ProcessNameScanner(), true);
AddScanner(ScannerInterface::eScannerType::WINDOWCLASS, new WindowNameScanner(), true);
AddScanner(ScannerInterface::eScannerType::WINDOWNAME, new WindowClassScanner(), true);
HANDLE m_hScannerThread = CreateThread(NULL, NULL, LPTHREAD_START_ROUTINE(ScannerThread), this, 0, &m_dwScannerThreadID);
if (m_hScannerThread == NULL)
{
//Failed to start.
DWORD dwError = GetLastError();
//
return false;
}
return true;
}
void RLKTGuard::AddScanner(ScannerInterface::eScannerType type, ScannerInterface *pScanner, bool bRun)
{
pScanner->Run(bRun);
m_pVecScanners.push_back(pScanner);
}
ScannerInterface * RLKTGuard::GetScanner(ScannerInterface::eScannerType type)
{
for(auto &it : m_pVecScanners)
{
if (it->GetType() == type)
return it;
}
return NULL;
}
void RLKTGuard::OnRecvCheatDatabase(char *pBuffer, int nBufferSize)
{
CMemoryStream Stream;
Stream.Initialize(pBuffer, nBufferSize);
int nCurrentPos = Stream.Tell();
int Header;
Stream.Read(&Header, sizeof(int));
ScannerInterface *pScanner = NULL;
int nSize = 0;
Stream.Read(&nSize, sizeof(int));
std::vector<ScannerInterface::CheatDefinition> pVec;
//MEMORY
for (int i = 0; i < nSize; i++)
{
int nDataSize = 0;
DWORD dwOffset;
Stream.Read(&nDataSize, sizeof(int));
char *pData = (char*)malloc(nDataSize);
Stream.ReadBuffer(pData, nDataSize);
Stream.Read(&dwOffset, sizeof(DWORD));
pVec.push_back(ScannerInterface::CheatDefinition(nDataSize, pData, dwOffset));
}
pScanner = GetScanner(ScannerInterface::eScannerType::MEMORY);
if (pScanner)
pScanner->OnRecvCheatDBPacket(ScannerInterface::eScannerType::MEMORY, pVec);
//PROCESS
Stream.Read(&nSize, sizeof(int));
pVec.clear();
for (int i = 0; i < nSize; i++)
{
int nDataSize = 0;
Stream.Read(&nDataSize, sizeof(int));
char *pData = (char*)malloc(nDataSize);
Stream.ReadBuffer(pData, nDataSize);
pVec.push_back(ScannerInterface::CheatDefinition(nDataSize, pData));
}
pScanner = GetScanner(ScannerInterface::eScannerType::PROCESS);
if (pScanner)
pScanner->OnRecvCheatDBPacket(ScannerInterface::eScannerType::PROCESS, pVec);
//WINDOWCLASS
Stream.Read(&nSize, sizeof(int));
pVec.clear();
for (int i = 0; i < nSize; i++)
{
int nDataSize = 0;
Stream.Read(&nDataSize, sizeof(int));
char *pData = (char*)malloc(nDataSize);
Stream.ReadBuffer(pData, nDataSize);
pVec.push_back(ScannerInterface::CheatDefinition(nDataSize, pData));
}
pScanner = GetScanner(ScannerInterface::eScannerType::WINDOWCLASS);
if (pScanner)
pScanner->OnRecvCheatDBPacket(ScannerInterface::eScannerType::WINDOWCLASS, pVec);
//WINDOWNAME
Stream.Read(&nSize, sizeof(int));
pVec.clear();
for (int i = 0; i < nSize; i++)
{
int nDataSize = 0;
Stream.Read(&nDataSize, sizeof(int));
char *pData = (char*)malloc(nDataSize);
Stream.ReadBuffer(pData, nDataSize);
pVec.push_back(ScannerInterface::CheatDefinition(nDataSize, pData));
}
pScanner = GetScanner(ScannerInterface::eScannerType::WINDOWNAME);
if (pScanner)
pScanner->OnRecvCheatDBPacket(ScannerInterface::eScannerType::WINDOWNAME, pVec);
}
DWORD WINAPI RLKTGuard::ScannerThread(LPVOID ptr)
{
RLKTGuard *pClass = (RLKTGuard*)ptr;
if (!pClass) return 0;
do
{
for (auto &it : pClass->m_pVecScanners)
{
it->Process();
}
Sleep(SCAN_INTERVAL);
} while (1);
return 0;
}