-
Notifications
You must be signed in to change notification settings - Fork 13
/
Main.pas
430 lines (402 loc) · 12.2 KB
/
Main.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
unit Main;
interface
uses
Windows, SysUtils, Classes, Controls, Forms, Dialogs, StdCtrls, ComCtrls,
ExtCtrls, TntComCtrls, EnhListView, Buttons, ActnList, ImgList, ToolWin,
VirtualTrees, Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
OpenDialog1: TOpenDialog;
nameParent: TLabeledEdit;
img1: TImageList;
actList1: TActionList;
actImport: TAction;
actLoad: TAction;
actSave: TAction;
vtClass: TVirtualStringTree;
btnLoad: TBitBtn;
btnImport: TBitBtn;
btnSave: TBitBtn;
edFilter: TLabeledEdit;
findProc: TLabeledEdit;
dlgSave1: TSaveDialog;
popup1: TPopupMenu;
actCopy: TAction;
actCopy1: TMenuItem;
procedure actCopyExecute(Sender: TObject);
procedure actCopyUpdate(Sender: TObject);
procedure actImportExecute(Sender: TObject);
procedure actImportUpdate(Sender: TObject);
procedure actLoadExecute(Sender: TObject);
procedure actSaveExecute(Sender: TObject);
procedure actSaveUpdate(Sender: TObject);
procedure edFilterChange(Sender: TObject);
procedure edFilterMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure vtClassCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtClassFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
procedure vtClassFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtClassGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtClassLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
procedure vtClassMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure vtClassSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
private
{ Private declarations }
Procedure AddUnitClass (n:PVirtualNode;t:AnsiString;idx:Integer);
Procedure BPL_load (f:TFileName);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Dump, CommCtrl,Clipbrd;
procedure TForm1.actCopyExecute(Sender: TObject);
var
data:PClassNode;
s:AnsiString;
begin
data:=vtClass.GetNodeData(vtClass.FocusedNode);
s:='';
Case data.kind Of
ntGUID: s:=GUIDToString(data.gid);
ntUnit,ntClass: s:=data.Txt;
ntVProc,ntDProc,ntIProc: s:='('+IntToHex(data.ofs,4)+') '+data.Txt;
end;
if s<>'' Then
with Clipboard do
Begin
Open;
SetTextBuf(@s[1]);
Close;
end;
end;
procedure TForm1.actCopyUpdate(Sender: TObject);
begin
TAction(Sender).Enabled:=Assigned(vtClass.FocusedNode);
end;
procedure TForm1.AddUnitClass(n:PVirtualNode;t:AnsiString;idx:Integer);
var
node,Virt,Dyna:PVirtualNode;
data:PClassNode;
objInfo:TClass;
Begin
node:=vtClass.AddChild(n);
data:=vtClass.GetNodeData(node);
data.Txt:=t;
data.kind:=ntClass;
objInfo:=Pointer(bpl.ExportList.Items[idx].MappedAddress);
data.Ancestor:=GetAncestor(objInfo);
Virt:=AddVirt(vtClass,node,objInfo);
Dyna:=AddDyna(vtClass,node,objInfo);
AddInter(vtClass,node,Virt,Dyna,objInfo);
if node.ChildCount<>0 then vtClass.ReinitNode(node,False)
Else vtClass.DeleteNode(node);
end;
procedure TForm1.BPL_load(f:TFileName);
var
I,p:Integer;
s:String;
node:PVirtualNode;
data:PClassNode;
lst:TStringList;
Begin
lst:=Nil;
node:=Nil;
if vtClass.RootNodeCount<>0 then
if MessageDlg('Clear the tree before importing BPL ?',mtConfirmation,[mbYes,mbNo],0)=mrYes then vtClass.Clear;
bpl.FileName:=f;
bpl.ReadOnlyAccess:=True;
vtClass.BeginUpdate;
Screen.Cursor:=crHourGlass;
try
lst:=TStringList.Create;
lst.Sorted:=False;
for I:=0 to bpl.ExportList.FunctionCount-1 Do
begin
s:=bpl.ExportList.Items[I].Name;
if (s[1]='@')And(s[Length(s)]='@') then
lst.AddObject(uncode(s),Pointer(I));
end;
lst.Sort;
s:='';
for I:=0 to lst.Count-1 do
begin
p:=Pos('.',lst[I]);
If s=Copy(lst[I],1,p-1) then AddUnitClass(node,Copy(lst[I],p+1,250),Integer(lst.Objects[I]))
Else
begin
If Assigned(node) and (node.ChildCount=0) then vtClass.DeleteNode(node);
s:=Copy(lst[I],1,p-1);
node:=vtClass.AddChild(Nil);
data:=vtClass.GetNodeData(node);
data.Txt:=s;
data.kind:=ntUnit;
AddUnitClass(node,Copy(lst[I],p+1,250),Integer(lst.Objects[I]));
vtClass.ReinitNode(node,False)
end;
end;
If Assigned(node) And (node.ChildCount=0) then vtClass.DeleteNode(node);
Finally
lst.Free;
Screen.Cursor:=crDefault;
With vtClass do
begin
Header.SortColumn:=0;
SortTree(0,sdAscending);
EndUpdate;
SetFocus;
end;
end;
Caption:='VCL explorer - '+ExtractFileName(f);
nameParent.Text:='';
edFilter.Text:='';
end;
procedure TForm1.actImportExecute(Sender: TObject);
begin
OpenDialog1.Filter:='BPL files|*.bpl|All files|*.*';
if OpenDialog1.Execute Then BPL_load(OpenDialog1.FileName);
end;
procedure TForm1.actImportUpdate(Sender: TObject);
begin
TAction(Sender).Enabled:=True;
end;
procedure TForm1.actLoadExecute(Sender: TObject);
begin
OpenDialog1.Filter:='KB files|*.kb|All files|*.*';
if OpenDialog1.Execute Then
try
Screen.Cursor:=crHourGlass;
vtClass.LoadFromFile(OpenDialog1.FileName);
Finally
Screen.Cursor:=crDefault;
end;
end;
procedure TForm1.actSaveExecute(Sender: TObject);
begin
if dlgSave1.Execute Then
try
Screen.Cursor:=crHourGlass;
vtClass.SaveToFile(dlgSave1.FileName);
Finally
Screen.Cursor:=crDefault;
end;
end;
procedure TForm1.actSaveUpdate(Sender: TObject);
begin
TAction(Sender).Enabled:=vtClass.RootNodeCount<>0;
end;
procedure TForm1.edFilterChange(Sender: TObject);
var
P,S,Q:PVirtualNode;
D,D2:PClassNode;
v,empty:Boolean;
s_trim,s_up,p_trim,p_up:AnsiString;
begin
if vtClass.RootNodeCount=0 then Exit;
s_trim:=Trim(edFilter.Text);
s_up:=UpperCase(s_trim);
p_trim:=Trim(FindProc.Text);
p_up:=UpperCase(p_trim);
empty:=(s_trim='')and(p_trim='');
With vtClass Do
try
BeginUpdate;
P:=RootNode.FirstChild;
While Assigned(P) Do
Begin
if empty then IsVisible[P]:=True
else
begin
D:=GetNodeData(P);
Case D.kind Of
ntClass: if s_trim<>'' then v:=Pos(s_up,UpperCase(D.Txt))>0 else v:=False;
ntVProc,
ntDProc:
Begin
Q:=P.Parent.Parent; // class node
If p_trim='' then v:=IsVisible[Q]
else
Begin
v:=Pos(p_up,UpperCase(D.Txt))>0;
If v and (s_trim<>'') Then
Begin
D2:=GetNodeData(Q);
// filtering on both class & method
v:=Pos(s_up,UpperCase(D2.Txt))>0;
end;
end;
end;
ntIProc:
Begin
Q:=P.Parent.Parent.Parent; // class node
If p_trim='' then v:=IsVisible[Q]
else
Begin
v:=Pos(p_up,UpperCase(D.Txt))>0;
If v and (s_trim<>'') Then
Begin
D2:=GetNodeData(Q);
// filtering on both class & method
v:=Pos(s_up,UpperCase(D2.Txt))>0;
end;
end;
end;
ntGUID:
Begin
Q:=P.Parent.Parent; // class node
If p_trim='' then v:=IsVisible[Q]
else
Begin
v:=Pos(p_up,GUIDToString(D.gid))>0;
If v and (s_trim<>'') Then
Begin
D2:=GetNodeData(Q);
// filtering on both class & method
v:=Pos(s_up,UpperCase(D2.Txt))>0;
end;
End;
End;
Else v:=False;
end;
IsVisible[P]:=v;
if v Then
Begin
S:=P.Parent;
While Assigned(S) and (S<>RootNode) and not IsVisible[S] Do
Begin
IsVisible[S]:=True;
S:=S.Parent;
end;
end;
End;
P:=GetNext(P);
end;
Finally
EndUpdate;
End;
end;
procedure TForm1.edFilterMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if TWinControl(Sender).CanFocus then ActiveControl:=TWinControl(Sender);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
vtClass.NodeDataSize:=SizeOf(ClassNode);
end;
procedure TForm1.vtClassCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
D1,D2:PClassNode;
begin
D1:=vtClass.GetNodeData(Node1);
D2:=vtClass.GetNodeData(Node2);
// 1st column shows names
// 2nd column shows virtual offsets, dynamic IDs, interface offsets
case D1.kind of
ntGUID: Result:=lstrcmpA(PAnsiChar(GUIDToString(D1.gid)),PAnsiChar(GUIDToString(D2.gid)));
ntVirtualGrp,
ntDynamicGrp,
ntInterfaceGrp:
if D1.kind < D2.kind then Result:=-1
else if D1.kind > D2.kind then Result:=1
else Result:=0;
ntVProc,
ntIProc:
if D1.ofs < D2.ofs then Result:=-1
else if D1.ofs > D2.ofs then Result:=1
else Result:=0;
ntDProc:
if Word(D1.ofs) < Word(D2.ofs) then Result:=1
else if Word(D1.ofs) > Word(D2.ofs) then Result:=-1
else Result:=0;
else Result:=lstrcmpiA(PAnsiChar(D1.Txt),PAnsiChar(D2.Txt));
end;
end;
procedure TForm1.vtClassFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
var
data:PClassNode;
begin
if Assigned(node) Then
Begin
data:=Sender.GetNodeData(Node);
nameParent.Text:=data.Ancestor;
end
else nameParent.Text:='';
end;
procedure TForm1.vtClassFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
var
data:PClassNode;
begin
data:=Sender.GetNodeData(Node);
if Assigned(data) then Finalize(data^);
end;
procedure TForm1.vtClassGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
var
data:PClassNode;
begin
// 1st column shows - Units, Classes, Virtual/Dynamic/Interface groups, GUIDs
// 2nd column shows - virtual offsets, dynamic IDs, interface offsets
data:=Sender.GetNodeData(Node);
case Column Of
0:
Case data.kind of
ntGUID:
CellText:=GUIDToString(data.gid);
ntVirtualGrp:
CellText:='('+IntToStr(Node.ChildCount)+') Virtual methods';
ntDynamicGrp:
CellText:='('+IntToStr(Node.ChildCount)+') Dynamic methods';
ntInterfaceGrp:
CellText:='('+IntToStr(Node.ChildCount)+') Interfaces';
else CellText:=data.txt;
End;
1: if data.kind=ntDProc then CellText:=IntToHex(Word(data.ofs),4)
else if data.kind in [ntVProc,ntIProc] then CellText:=IntToHex(data.ofs,4)
Else CellText:='';
end;
end;
procedure TForm1.vtClassLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
var
data:PClassNode;
n:Integer;
begin
data:=Sender.GetNodeData(Node);
with Stream, data^ do
begin
Read(ofs,SizeOf(ofs));
Read(gid,SizeOf(gid));
Read(kind,SizeOf(kind));
Read(n,SizeOf(n));
SetLength(Txt,n);
Read(txt[1],n);
Read(n,SizeOf(n));
SetLength(Ancestor,n);
Read(ancestor[1],n);
end;
end;
procedure TForm1.vtClassMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
If vtClass.CanFocus then ActiveControl:=vtClass;
end;
procedure TForm1.vtClassSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
var
data:PClassNode;
n:Integer;
begin
data:=Sender.GetNodeData(Node);
with Stream, data^ do
begin
Write(ofs,SizeOf(ofs));
Write(gid,SizeOf(gid));
Write(kind,SizeOf(kind));
n:=Length(Txt);
Write(n,SizeOf(n));
Write(txt[1],n);
n:=Length(Ancestor);
Write(n,SizeOf(n));
Write(ancestor[1],n);
end;
end;
end.