-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatcher.pas
297 lines (249 loc) · 8.77 KB
/
watcher.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
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
unit watcher;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
TLHelp32, Dialogs, Grids, ValEdit, StdCtrls, ExtCtrls, ComCtrls, Unit_main, Buttons;
type
Tmemview = class(TForm)
addresseslist: TListView;
Panel1: TPanel;
addressedit: TEdit;
valuelabel: TLabel;
typecombo: TComboBox;
ListUpdater: TTimer;
addbtn: TBitBtn;
delbtn: TBitBtn;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
moduleedit: TEdit;
Label4: TLabel;
lengthedit: TEdit;
Label5: TLabel;
procedure FormShow(Sender: TObject);
procedure addbtnClick(Sender: TObject);
procedure addresseditChange(Sender: TObject);
procedure FormHide(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure typecomboChange(Sender: TObject);
procedure delbtnClick(Sender: TObject);
procedure ListUpdaterTimer(Sender: TObject);
procedure moduleeditChange(Sender: TObject);
procedure lengtheditChange(Sender: TObject);
procedure addresseslistDblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
memview: Tmemview;
implementation
uses Res, modder;
{$R *.dfm}
function GetModuleBaseAddress(iProcId: Cardinal; DLLName: String): Cardinal;
var
hSnap: THandle; // Process snapshot handle.
xModule: ModuleEntry32; // Module information structure.
begin
Result:= 0; // If the result of the function is 0, it didn't find the base address.
// i.e.. the dll isn't loaded.
hSnap:= CreateToolHelp32Snapshot(TH32CS_SNAPMODULE, iProcId); // Creates a module
// snapshot of the
// game process.
xModule.dwSize:= SizeOf(xModule); // Needed for Module32First/Next to work.
If Module32First(hSnap, xModule) Then Begin // Gets the first module.
While Module32Next(hSnap, xModule) Do // Loops through the rest of the modules.
If AnsiUpperCase(xModule.szModule) = AnsiUpperCase(DLLName) Then // If this is the module we want...
Result:= Cardinal(xModule.modBaseAddr); // Save the base address it in result.
End;
CloseHandle(hSnap); // Free the handle.
end;
procedure Tmemview.FormShow(Sender: TObject);
begin
memview.Top := main.top + main.height + 25;
memview.Left := main.left + main.width - memview.Width;
ListUpdater.Enabled := true;
end;
procedure Tmemview.addbtnClick(Sender: TObject);
var
itm: TListItem;
begin
itm := addresseslist.Items.Add;
itm.Caption := IntToHex(StrToInt('$'+Trim(addressedit.text))+GetModuleBaseAddress(PID,Trim(moduleedit.Text)),8);
if typecombo.Text <> 'String'
then itm.SubItems.Add(typecombo.Text)
else itm.SubItems.Add(typecombo.Text+'['+Trim(lengthedit.text)+']');
itm.SubItems.Add(StringReplace(valuelabel.Caption,'= ','',[rfReplaceAll, rfIgnoreCase]));
addressedit.Text := '';
moduleedit.Text := '';
valuelabel.Caption := '= ???';
typecombo.ItemIndex := 0;
lengthedit.Visible := false;
label5.Visible := false;
end;
procedure Tmemview.addresseditChange(Sender: TObject);
var bytesread, addrs: cardinal;
intout, strlen: integer;
doubleout: real;
floatout: single;
charout: array [1..255] of char;
strout: string;
strptr: PChar;
begin
if (length(Trim(lengthedit.text)) > 0) and (length(Trim(lengthedit.text)) < 4) then
begin
strlen := StrToInt(Trim(lengthedit.text));
end
else begin
strlen := 0;
end;
if (length(Trim(addressedit.Text)) > 0) and (length(Trim(addressedit.Text)) < 8) then
begin
try
addrs := StrToInt(Trim('$'+addressedit.Text));
case typecombo.ItemIndex of
0: ReadprocessMemory(PHandle, Ptr(addrs), @intout, 1, bytesread);
1: ReadprocessMemory(PHandle, Ptr(addrs), @intout, 2, bytesread);
2: ReadprocessMemory(PHandle, Ptr(addrs), @intout, 4, bytesread);
3: ReadprocessMemory(PHandle, Ptr(addrs), @floatout, sizeof(floatout), bytesread);
4: ReadprocessMemory(PHandle, Ptr(addrs), @doubleout, sizeof(doubleout), bytesread);
5: ReadprocessMemory(PHandle, Ptr(addrs), @charout, strlen, bytesread);
end;
case typecombo.ItemIndex of
0: valuelabel.Caption := '= '+IntToStr(intout);
1: valuelabel.Caption := '= '+IntToStr(intout);
2: valuelabel.Caption := '= '+IntToStr(intout);
3: valuelabel.Caption := '= '+FormatFloat('0.###############', floatout);
4: valuelabel.Caption := '= '+FormatFloat('0.###############', doubleout);
5: begin
strptr := Addr(charout);
SetString(strout, strptr, bytesread);
valuelabel.Caption := '= '+strout;
end;
end;
except
valuelabel.Caption := '= ???';
end;
end;
end;
procedure Tmemview.FormHide(Sender: TObject);
begin
ListUpdater.Enabled := false;
end;
procedure Tmemview.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ListUpdater.Enabled := false;
end;
procedure Tmemview.typecomboChange(Sender: TObject);
begin
memview.addresseditChange(self);
if typecombo.ItemIndex = 5 then
begin
lengthedit.Visible := true;
label5.Visible := true;
end
else begin
lengthedit.Visible := false;
label5.Visible := false;
end;
end;
procedure Tmemview.delbtnClick(Sender: TObject);
begin
addresseslist.DeleteSelected;
end;
procedure Tmemview.ListUpdaterTimer(Sender: TObject);
var n, i: integer;
bytesread, addrs: cardinal;
intout: integer;
floatout: single;
doubleout: real;
strout, typestr, typestraux: string;
charout: array [1..255] of char;
strptr: PChar;
begin
n := addresseslist.Items.Count;
if n > 0 then
begin
for i:=n-1 downto 0 do
begin
typestr := '';
addrs := 0;
if i >= 0 then
begin
addrs := StrToInt('$'+addresseslist.Items.Item[i].Caption);
typestr := addresseslist.Items.Item[i].SubItems.Strings[0];
end
else begin
break;
end;
if typestr = 'Byte' then
begin
ReadprocessMemory(PHandle, Ptr(addrs), @intout, 1, bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1] := IntToStr(intout);
end;
if typestr = '2 Bytes' then
begin
ReadprocessMemory(PHandle, Ptr(addrs), @intout, 2, bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1] := IntToStr(intout);
end;
if typestr = '4 Bytes' then
begin
ReadprocessMemory(PHandle, Ptr(addrs), @intout, 4, bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1] := IntToStr(intout);
end;
if typestr = 'Float' then
begin
ReadprocessMemory(PHandle, Ptr(addrs), @floatout, sizeof(floatout), bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1]:= FormatFloat('0.###############', floatout);
end;
if typestr = 'Double' then
begin
ReadprocessMemory(PHandle, Ptr(addrs), @doubleout, sizeof(doubleout), bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1]:= FormatFloat('0.###############', doubleout);
end;
if typestr[1] = 'S' then
begin
typestraux := StringReplace(typestr,'String[','',[rfReplaceAll, rfIgnoreCase]);
typestraux := StringReplace(typestraux,']','',[rfReplaceAll, rfIgnoreCase]);
ReadprocessMemory(PHandle, Ptr(addrs), @charout, StrToInt(typestraux), bytesread);
strptr := Addr(charout);
SetString(strout, strptr, bytesread);
addresseslist.Items.Item[i].SubItems.Strings[1] := strout;
end;
end;
end;
end;
procedure Tmemview.moduleeditChange(Sender: TObject);
begin
memview.addresseditChange(self);
end;
procedure Tmemview.lengtheditChange(Sender: TObject);
begin
memview.addresseditChange(self);
end;
procedure Tmemview.addresseslistDblClick(Sender: TObject);
begin
if addresseslist.Items.Count > 0 then
begin
if addresseslist.Selected.Caption <> '' then
begin
memmod.address.text := addresseslist.Selected.Caption;
if addresseslist.Selected.SubItems.Strings[0] = 'Byte'
then memmod.vartype.ItemIndex := 0;
if addresseslist.Selected.SubItems.Strings[0] = '2 Bytes'
then memmod.vartype.ItemIndex := 1;
if addresseslist.Selected.SubItems.Strings[0] = '4 Bytes'
then memmod.vartype.ItemIndex := 2;
if addresseslist.Selected.SubItems.Strings[0] = 'Float'
then memmod.vartype.ItemIndex := 3;
if addresseslist.Selected.SubItems.Strings[0] = 'Double'
then memmod.vartype.ItemIndex := 4;
if addresseslist.Selected.SubItems.Strings[0] = 'String'
then memmod.vartype.ItemIndex := 5;
memmod.value.Text := addresseslist.Selected.SubItems.Strings[1];
memmod.Show;
end;
end;
end;
end.