Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
283 lines (273 loc) · 9.8 KB
/
Copy pathMain.cpp
File metadata and controls
283 lines (273 loc) · 9.8 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
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
//---------------------------------------------------------------------------
#include <vcl.h>
#include <math.h>
#include <string.h>
#pragma hdrstop
#include "Main.h"
#include "Xbdm.h"
#include "Memory.h"
#include "Allocate.h"
#include "Search.h"
#include "Search2.h"
#include "Break.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
// Shared state (declared in Xbdm.h)
HMODULE hXbdm = NULL;
PFN_DmSetMemory pDmSetMemory = NULL;
PFN_DmGetMemory pDmGetMemory = NULL;
PFN_DmStop pDmStop = NULL;
PFN_DmGo pDmGo = NULL;
PFN_DmWalkCommittedMemory pDmWalkCommittedMemory = NULL;
PFN_DmCloseCommittedMemory pDmCloseCommittedMemory = NULL;
PFN_DmSetDataBreakpoint pDmSetDataBreakpoint = NULL;
PFN_DmIsBreakpoint pDmIsBreakpoint = NULL;
UnicodeString StartDir;
unsigned int CacheStart = 0;
unsigned int CacheEnd = 0;
unsigned char *CacheBuf = NULL;
// Set by the Search page's "XBOX" box when a search starts: the original Xbox is little-endian like the PC, so
// no swap is needed; the Xbox 360 is big-endian, so values are swapped.
bool NoByteSwap = false;
//---------------------------------------------------------------------------
void Swap64(void *p)
{
if (NoByteSwap)
return;
unsigned char *b = (unsigned char *)p;
unsigned char t;
t = b[0]; b[0] = b[7]; b[7] = t;
t = b[1]; b[1] = b[6]; b[6] = t;
t = b[2]; b[2] = b[5]; b[5] = t;
t = b[3]; b[3] = b[4]; b[4] = t;
}
//---------------------------------------------------------------------------
void Swap32(void *p)
{
if (NoByteSwap)
return;
unsigned char *b = (unsigned char *)p;
unsigned char t;
t = b[0]; b[0] = b[3]; b[3] = t;
t = b[1]; b[1] = b[2]; b[2] = t;
}
//---------------------------------------------------------------------------
void Swap16(void *p)
{
if (NoByteSwap)
return;
unsigned char *b = (unsigned char *)p;
unsigned char t = b[0];
b[0] = b[1];
b[1] = t;
}
//---------------------------------------------------------------------------
void CachedRead(unsigned int addr, void *dst, unsigned char n)
{
// Same test as the original: an address equal to CacheEnd still counts as inside the window.
if (addr < CacheStart || addr > CacheEnd)
{
CacheStart = addr & 0xFFFF0000;
CacheEnd = CacheStart + 0x10000;
if (pDmGetMemory((const void *)CacheStart, 0x10000, CacheBuf, NULL) < 0)
memset(CacheBuf, 0, 0x10000);
}
memcpy(dst, CacheBuf + (addr - CacheStart), n);
}
//---------------------------------------------------------------------------
bool CompareInt(const TSearchCond *c, unsigned char size, unsigned int oldValue, unsigned int newValue)
{
const unsigned int value1 = c->Value1[size];
switch (c->Mode)
{
case smExact: return newValue == value1;
case smChanged: return newValue != oldValue;
case smUnchanged: return newValue == oldValue;
case smIncreased: return newValue > oldValue;
case smDecreased: return newValue < oldValue;
case smIncreasedBy: return oldValue + value1 == newValue;
case smDecreasedBy: return oldValue - value1 == newValue;
case smBetween: return value1 <= newValue && newValue <= c->Value2[size];
case smChangedBy: return oldValue + value1 == newValue || newValue == oldValue - value1;
}
return false;
}
//---------------------------------------------------------------------------
static unsigned int FloatBits(float f)
{
unsigned int u;
memcpy(&u, &f, sizeof u);
return u;
}
static float BitsFloat(unsigned int u)
{
float f;
memcpy(&f, &u, sizeof f);
return f;
}
static unsigned __int64 DoubleBits(double d)
{
unsigned __int64 u;
memcpy(&u, &d, sizeof u);
return u;
}
// True when |d| >= 2^32, or d is infinite or NaN (the original tests the exponent bits).
static bool DoubleOutOfRange(double d)
{
return (unsigned int)((DoubleBits(d) >> 32) & 0x7FFFFFFF) >= 0x41F00000;
}
//---------------------------------------------------------------------------
bool CompareFloat(const TSearchCond *c, float oldValue, float newValue)
{
// Ordered tests skip values that are too large to be meaningful (|x| >= 2^32). For smBetween only the
// new value is checked.
if (c->Mode >= smIncreased)
{
if (fabs(newValue) >= 4294967296.0)
return false;
if (c->Mode != smBetween && fabs(oldValue) >= 4294967296.0)
return false;
}
const float value1 = BitsFloat(c->Value1[3]);
switch (c->Mode)
{
case smExact: return FloatBits(newValue) == c->Value1[3];
case smChanged: return FloatBits(newValue) != FloatBits(oldValue);
case smUnchanged: return FloatBits(newValue) == FloatBits(oldValue);
case smIncreased: return newValue > oldValue;
case smDecreased: return newValue < oldValue;
case smIncreasedBy: return oldValue + value1 == newValue;
case smDecreasedBy: return oldValue - value1 == newValue;
case smBetween: return newValue >= value1 && newValue <= BitsFloat(c->Value2[3]);
case smChangedBy: return oldValue + value1 == newValue || oldValue - value1 == newValue;
}
return false;
}
//---------------------------------------------------------------------------
bool CompareDouble(const TSearchCond *c, double oldValue, double newValue)
{
if (c->Mode >= smIncreased)
{
if (DoubleOutOfRange(newValue))
return false;
if (c->Mode != smBetween && DoubleOutOfRange(oldValue))
return false;
}
const double value1 = c->DValue1;
switch (c->Mode)
{
case smExact: return DoubleBits(newValue) == DoubleBits(c->DValue1);
case smChanged: return DoubleBits(newValue) != DoubleBits(oldValue);
case smUnchanged: return DoubleBits(newValue) == DoubleBits(oldValue);
case smIncreased: return newValue > oldValue;
case smDecreased: return newValue < oldValue;
case smIncreasedBy: return oldValue + value1 == newValue;
case smDecreasedBy: return oldValue - value1 == newValue;
case smBetween: return newValue >= value1 && newValue <= c->DValue2;
case smChangedBy: return oldValue + value1 == newValue || oldValue - value1 == newValue;
}
return false;
}
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
hXbdm = LoadLibraryA("xbdm.dll");
if (hXbdm != NULL)
{
pDmSetMemory = (PFN_DmSetMemory)GetProcAddress(hXbdm, "DmSetMemory");
pDmGetMemory = (PFN_DmGetMemory)GetProcAddress(hXbdm, "DmGetMemory");
pDmStop = (PFN_DmStop)GetProcAddress(hXbdm, "DmStop");
pDmGo = (PFN_DmGo)GetProcAddress(hXbdm, "DmGo");
pDmWalkCommittedMemory = (PFN_DmWalkCommittedMemory)GetProcAddress(hXbdm, "DmWalkCommittedMemory");
pDmCloseCommittedMemory = (PFN_DmCloseCommittedMemory)GetProcAddress(hXbdm, "DmCloseCommittedMemory");
pDmSetDataBreakpoint = (PFN_DmSetDataBreakpoint)GetProcAddress(hXbdm, "DmSetDataBreakpoint");
pDmIsBreakpoint = (PFN_DmIsBreakpoint)GetProcAddress(hXbdm, "DmIsBreakpoint");
StartDir = GetCurrentDir();
}
else
{
ShowMessage("xbdm.dll not found!!!");
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
if (hXbdm != NULL)
FreeLibrary(hXbdm);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender)
{
SearchForm->PageGroup->Parent = this;
}
//---------------------------------------------------------------------------
// Page switching: move the chosen page into this window and send the others back to their own forms.
void __fastcall TMainForm::Search1ItemClick(TObject *Sender)
{
SearchForm->PageGroup->Parent = this;
AllocateForm->PageGroup->Parent = AllocateForm;
MemoryForm->PageGroup->Parent = MemoryForm;
Search2Form->PageGroup->Parent = Search2Form;
BreakForm->PageGroup->Parent = BreakForm;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::Search2ItemClick(TObject *Sender)
{
Search2Form->PageGroup->Parent = this;
MemoryForm->PageGroup->Parent = MemoryForm;
SearchForm->PageGroup->Parent = SearchForm;
AllocateForm->PageGroup->Parent = AllocateForm;
BreakForm->PageGroup->Parent = BreakForm;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::MemoryItemClick(TObject *Sender)
{
MemoryForm->PageGroup->Parent = this;
AllocateForm->PageGroup->Parent = AllocateForm;
SearchForm->PageGroup->Parent = SearchForm;
Search2Form->PageGroup->Parent = Search2Form;
BreakForm->PageGroup->Parent = BreakForm;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::AllocateItemClick(TObject *Sender)
{
AllocateForm->PageGroup->Parent = this;
MemoryForm->PageGroup->Parent = MemoryForm;
SearchForm->PageGroup->Parent = SearchForm;
Search2Form->PageGroup->Parent = Search2Form;
BreakForm->PageGroup->Parent = BreakForm;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BreakPointItemClick(TObject *Sender)
{
BreakForm->PageGroup->Parent = this;
Search2Form->PageGroup->Parent = Search2Form;
MemoryForm->PageGroup->Parent = MemoryForm;
SearchForm->PageGroup->Parent = SearchForm;
AllocateForm->PageGroup->Parent = AllocateForm;
}
//---------------------------------------------------------------------------
// Stop / Go the console. The original compares the caption with "S&top" (C++Builder 6 menus add the
// accelerator at run time); StripHotkey makes the test work whether or not the '&' has been added.
void __fastcall TMainForm::StopItemClick(TObject *Sender)
{
if (StripHotkey(StopItem->Caption) == L"Stop")
{
pDmStop();
StopItem->Caption = L"G&o";
}
else
{
pDmGo();
StopItem->Caption = L"S&top";
}
}
//---------------------------------------------------------------------------