forked from cheat-engine/cheat-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindWindowUnit.pas
executable file
·226 lines (166 loc) · 4.89 KB
/
FindWindowUnit.pas
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
unit FindWindowUnit;
{$MODE Delphi}
interface
uses
LCLIntf, Messages, LMessages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,CEFuncProc,ComCtrls, ExtCtrls, LResources, memscan,
commonTypeDefs, math, {$ifdef windows}win32proc,{$endif} symbolhandler, betterControls;
const wm_fw_scandone=wm_user+1;
type
{ TFindWindow }
TFindWindow = class(TForm)
Panel1: TPanel;
labelType: TLabel;
Label2: TLabel;
Label3: TLabel;
labelArray: TLabel;
editStart: TEdit;
EditStop: TEdit;
rbText: TRadioButton;
rbArByte: TRadioButton;
cbUnicode: TCheckBox;
Panel2: TPanel;
btnOK: TButton;
btnCancel: TButton;
Scanvalue: TEdit;
procedure btnOKClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
memscan: TMemScan;
procedure scandone(Sender: TObject);
public
{ Public declarations }
firstscan: boolean;
end;
var
FindWindow: TFindWindow;
implementation
uses MemoryBrowserFormUnit, ProcessHandlerUnit, Parsers;
resourcestring
rsNothingFound = 'Nothing found';
rsTheSpecifiedRangeIsInvalid = 'The specified range is invalid';
procedure TFindWindow.scandone(sender: TObject);
var x: ptruint;
begin
if TMemScan(sender).GetOnlyOneResult(x) then
begin
MemoryBrowser.memoryaddress:=x;
modalresult:=mrok;
end else
begin
MessageDlg(rsNothingFound, mtError, [mbok], 0);
end;
if memscan=sender then
freeandnil(memscan);
btnOK.enabled:=true;
end;
procedure TFindWindow.btnOKClick(Sender: TObject);
var startaddress,stopaddress: ptruint;
//cb: TCheckbox;
valtype: TVariableType;
i: integer;
begin
if memscan<>nil then
freeandnil(memscan);
try
startaddress:=StrToQWordEx('$'+editstart.text);
except
startaddress:=symhandler.getAddressFromName(editstart.text);
end;
try
stopaddress:=StrToQWordEx('$'+editstop.text);
except
stopaddress:=symhandler.getAddressFromName(editstop.text);
end;
if startaddress>stopaddress then
begin //xor swap
startaddress:=startaddress xor stopaddress;
stopaddress:=stopaddress xor startaddress;
startaddress:=startaddress xor stopaddress;
end;
if rbText.checked then valtype:=vtString else valtype:=vtByteArray;
memscan:=TMemscan.create(nil);
memscan.onlyone:=true;
memscan.scanCopyOnWrite:=scanDontCare;
memscan.scanExecutable:=scanDontCare;
memscan.scanWritable:=scanDontCare;
memscan.firstscan(soExactValue, valtype, rtRounded, scanvalue.text, '', startaddress, stopaddress, true, false, cbunicode.checked, false, fsmNotAligned);
memscan.OnScanDone:=ScanDone;
btnOK.enabled:=false;
end;
procedure TFindWindow.FormDestroy(Sender: TObject);
begin
if memscan<>nil then
freeandnil(memscan);
end;
procedure TFindWindow.FormShow(Sender: TObject);
const EM_GETMARGINS=$d4;
var m: dword;
begin
if firstscan then
begin
{$ifdef windows}
if WindowsVersion>=wvVista then
m:=sendmessage(editstart.Handle, EM_GETMARGINS, 0,0)
else
{$endif}
m:=0;
if processhandler.is64bit then
begin
//init just once if needed
if (editstop.Text = '') or (editstart.Text = '') then // if not initialized
begin
editstop.text:='7FFFFFFFFFFFFFFF';
editstart.Text:='0000000000000000';
end;
editstart.clientwidth:=canvas.TextWidth('DDDDDDDDDDDDDDDD')+(m shr 16)+(m and $ffff);
end
else
begin
//init just once if needed
if (editstop.Text = '') or (editstart.Text = '') then // if not initialized
begin
editstop.text:='7FFFFFFF';
editstart.Text:='00000000';
end;
editstart.clientwidth:=canvas.TextWidth('DDDDDDDD')+(m shr 16)+(m and $ffff);
end;
labelType.visible:=true;
labelarray.visible:=true;
rbtext.visible:=true;
rbArByte.visible:=true;
scanvalue.Visible:=true;
btnOK.visible:=true;
btnCancel.visible:=true;
EditStop.visible:=true;
editStart.visible:=true;
label2.Visible:=true;
label3.Visible:=true;
Scanvalue.SetFocus;
end
else
begin
labelType.visible:=false;
labelarray.visible:=false;
rbtext.visible:=false;
rbArByte.visible:=false;
scanvalue.Visible:=false;
btnOK.visible:=false;
btnCancel.visible:=false;
EditStop.visible:=false;
editStart.visible:=false;
label2.Visible:=false;
label3.Visible:=false;
end;
btnok.AutoSize:=true;
btnok.AutoSize:=false;
btnCancel.autosize:=true;
btnCancel.autosize:=false;
btnok.width:=max(btnok.width, btncancel.width);
btncancel.width:=max(btnok.width, btncancel.width);
end;
initialization
{$i FindWindowUnit.lrs}
end.