-
Notifications
You must be signed in to change notification settings - Fork 6
/
MagicPoints.cpp
298 lines (281 loc) · 8.53 KB
/
MagicPoints.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#include "MagicPoints.h"
#include <windows.h>
#include <vcl.h>
#include "frmMain.h"
#include "frmAbout.h"
#include "pluginmain.h"
#include "dll_link.h"
#include "_scriptapi_module.h"
/*=============================================================================================*/
//---------------------------------------------------------------------------
/* global functions pointers */
//---------------------------------------------------------------------------
_DebugSetBreakpoint DebugSetBreakpoint;
_PatternFindMem PatternFindMem;
_CommentSet CommentSet;
_ModuleGetMainModuleName ModuleGetMainModuleName;
_ModuleSectionFromName ModuleSectionFromName;
_ModuleSectionListFromName ModuleSectionListFromName;
/*=============================================================================================*/
bool cbSetMagicPoints(int argc, char* argv[])
{
// Create Form
if(!MainFrm)
MainFrm = new TMainFrm(NULL);
MainFrm->ShowModal();
delete MainFrm;
MainFrm = NULL;
return true;
}
/*=============================================================================================*/
void ShowAboutForm()
{
if(!AboutFrm)
AboutFrm = new TAboutFrm(NULL);
AboutFrm->ShowModal();
delete AboutFrm;
AboutFrm = NULL;
}
/*=============================================================================================*/
void OnInitDbg(PLUG_CB_INITDEBUG* info)
{
// get dinamic dll functions
GetDllFunctions();
}
/*=============================================================================================*/
int LocateMagicPoint(COMPILER_TYPE compiler)
{
stMagicPoint MagicPoint;
char *name;
int result = 0;
MagicPoint.compiler = compiler;
switch(compiler)
{
case COMPILER_VB5:
MagicPoint.module = "msvbvm50.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 2;
strcpy(MagicPoint.pattern, "F3A5FFD08BE55D8945FC8B45FC5F5E8BE55DC20C"); // VB5 pattern
MagicPoint.loop = false;
break;
case COMPILER_VB6:
MagicPoint.module = "msvbvm60.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 2;
strcpy(MagicPoint.pattern, "F3A5FFD08BE55D8945FC8B45FC5F5EC9C20C"); // VB6 pattern
MagicPoint.loop = false;
break;
case COMPILER_BORLAND:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 0;
MagicPoint.bp_displacement = 10;
strcpy(MagicPoint.pattern, "740E8BD38B83????????FF93????????"); // DELPHI pattern
MagicPoint.loop = true;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC6:
MagicPoint.module = "mfc42d.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 10;
strcpy(MagicPoint.pattern, "CC33C085C075E38B4D08FF55FCE94804????33C985C97401CC"); // VC6 pattern
MagicPoint.loop = false;
break;
case COMPILER_VC10_MFC_DYNAMIC_DEBUG:
MagicPoint.module = "mfc100ud.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 4;
strcpy(MagicPoint.pattern, "CC8B4D08FF55F8E9????????837D18007411"); // VC10 DYNAMIC DEBUG pattern
MagicPoint.loop = false;
break;
case COMPILER_VC10_MFC_DYNAMIC_RELEASE:
MagicPoint.module = "mfc100u.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 15;
strcpy(MagicPoint.pattern, "8B550C83C2C783FA0B0F87????????FF2495????????"); // VC10 DYNAMIC RELEASE pattern
MagicPoint.loop = false;
break;
case COMPILER_VC10_MFC_STATIC_DEBUG:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 1;
MagicPoint.bp_displacement = 4;
strcpy(MagicPoint.pattern, "CC8B4D08FF55F8E9????????837D18007411"); // VC10 STATIC DEBUG pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC10_MFC_STATIC_RELEASE:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 0;
MagicPoint.bp_displacement = 16;
strcpy(MagicPoint.pattern, "8B451C83C0C75683F80B0F87????????FF2485????????"); // VC10 STATIC RELEASE pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC12_MFC_DYNAMIC_DEBUG:
MagicPoint.module = "mfc120ud.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 6;
strcpy(MagicPoint.pattern, "CC8BF48B4D08FF55F83BF4E8????????E9????????"); // VC12 DYNAMIC DEBUG pattern
MagicPoint.loop = false;
break;
case COMPILER_VC12_MFC_DYNAMIC_RELEASE:
MagicPoint.module = "mfc120u.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 15;
strcpy(MagicPoint.pattern, "8B451483C0C683F80B0F87????????FF2485????????"); // VC12 DYNAMIC RELEASE pattern
MagicPoint.loop = false;
break;
case COMPILER_VC12_MFC_STATIC_DEBUG:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 1;
MagicPoint.bp_displacement = 6;
strcpy(MagicPoint.pattern, "CC8BF48B4D08FF55F83BF4E8????????E9????????"); // VC12 STATIC DEBUG pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC12_MFC_STATIC_RELEASE:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 0;
MagicPoint.bp_displacement = 16;
strcpy(MagicPoint.pattern, "8B451C83C0C65683F80B0F87????????FF2485????????"); // VC12 STATIC RELEASE pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC14_MFC_DYNAMIC_DEBUG:
MagicPoint.module = "mfc140ud.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 3;
strcpy(MagicPoint.pattern, "8B4D08FF55B83BF4E8????????E9????????"); // VC14 DYNAMIC DEBUG pattern
MagicPoint.loop = false;
break;
case COMPILER_VC14_MFC_DYNAMIC_RELEASE:
MagicPoint.module = "mfc140u.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 16;
strcpy(MagicPoint.pattern, "8B451483C0C65783F80B0F87????????FF2485????????"); // VC14 DYNAMIC RELEASE pattern
MagicPoint.loop = false;
break;
case COMPILER_VC14_MFC_STATIC_DEBUG:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 1;
MagicPoint.bp_displacement = 3;
strcpy(MagicPoint.pattern, "8B4D08FF55B83BF4E8????????E9????????"); // VC14 STATIC DEBUG pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case COMPILER_VC14_MFC_STATIC_RELEASE:
name = new char[MAX_MODULE_SIZE];
if(ModuleGetMainModuleName(name))
{
MagicPoint.module = name;
MagicPoint.section = 0;
MagicPoint.bp_displacement = 16;
strcpy(MagicPoint.pattern, "8B451C83C0C65783F80B0F87????????FF2485????????"); // VC14 STATIC RELEASE pattern
MagicPoint.loop = false;
delete[] name;
}
else
{
delete[] name;
return result;
}
break;
case POINT_HMEMCPY:
MagicPoint.module = "user32.dll";
MagicPoint.section = 0;
MagicPoint.bp_displacement = 3;
strcpy(MagicPoint.pattern, "515053E88429010083C40C8BCF"); // HMEMCPY pattern
MagicPoint.loop = false;
break;
default:
break;
}
return FindPattern(&MagicPoint);
}
/*=============================================================================================*/
int FindPattern(stMagicPoint *MagicPoint)
{
int result = 0;
Script::Module::ModuleSectionInfo *modInfo = new Script::Module::ModuleSectionInfo;
if(!ModuleSectionFromName(MagicPoint->module.c_str(), MagicPoint->section, modInfo))
return result;
duint rvaCodeSection = modInfo->addr; // get section address
duint sectionSize = modInfo->size; // get section size
TListItem *Item;
DWORD lpPattern = -1;
DWORD startRVA = rvaCodeSection;
do
{
lpPattern = PatternFindMem(rvaCodeSection, sectionSize, MagicPoint->pattern);
if(lpPattern > 0)
{
rvaCodeSection = lpPattern + MagicPoint->bp_displacement;
DebugSetBreakpoint(rvaCodeSection); // set breakpoint
CommentSet(rvaCodeSection, "<<-- MAGIC_POINT", true); // set comment
// populate gui info listview
Item = MainFrm->lstPointsData->Items->Add();
Item->Caption = MagicPoint->module;
Item->SubItems->Add(IntToHex((__int64)rvaCodeSection, 8));
// recalculate section size
sectionSize = sectionSize - (lpPattern - startRVA);
startRVA = lpPattern;
result++;
}
else
break;
}while(MagicPoint->loop);
return result;
}