-
Notifications
You must be signed in to change notification settings - Fork 20
/
Main.pas
20149 lines (19334 loc) · 643 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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,Types,
Controls, Forms, Dialogs, StdCtrls,Menus, ActnList, ComCtrls, Grids,
ExtCtrls, Disasm, KnowledgeBase, Resources, Infos, UFileDropper,
Def_main,Def_info,Def_know,SyncObjs, VirtualTrees, Registry;
Type
TFMain=class(TForm)
miFile: TMenuItem;
miLoadFile: TMenuItem;
miExit: TMenuItem;
miSaveProject: TMenuItem;
OpenDlg: TOpenDialog;
MainMenu: TMainMenu;
miTools: TMenuItem;
pcInfo: TPageControl;
tsUnits: TTabSheet;
tsRTTIs: TTabSheet;
miOpenProject: TMenuItem;
pcWorkArea: TPageControl;
tsCodeView: TTabSheet;
lbCode: TListBox;
pmCode: TPopupMenu;
miGoTo: TMenuItem;
miExploreAdr: TMenuItem;
SaveDlg: TSaveDialog;
SplitterH1: TSplitter;
SplitterV1: TSplitter;
miViewProto: TMenuItem;
CodePanel: TPanel;
bEP: TButton;
bCodePrev: TButton;
tsClassView: TTabSheet;
tvClassesFull: TTreeView;
tsStrings: TTabSheet;
Panel1: TPanel;
pmUnits: TPopupMenu;
miSearchUnit: TMenuItem;
pmRTTIs: TPopupMenu;
pmVMTs: TPopupMenu;
miSearchRTTI: TMenuItem;
miSearchVMT: TMenuItem;
miCopyCode: TMenuItem;
miRenameUnit: TMenuItem;
pmUnitItems: TPopupMenu;
miSearchItem: TMenuItem;
tsForms: TTabSheet;
Panel2: TPanel;
rgViewFormAs: TRadioGroup;
lbForms: TListBox;
sb:TStatusBar;
pb:TProgressBar;
miCollapseAll: TMenuItem;
lbCXrefs: TListBox;
ShowCXrefs: TPanel;
tvClassesShort: TTreeView;
rgViewerMode: TRadioGroup;
miClassTreeBuilder: TMenuItem;
miMRF: TMenuItem;
miExe1: TMenuItem;
miExe2: TMenuItem;
miExe3: TMenuItem;
miExe4: TMenuItem;
miIdp1: TMenuItem;
miIdp2: TMenuItem;
miIdp3: TMenuItem;
miIdp4: TMenuItem;
N1: TMenuItem;
tsItems: TTabSheet;
sgItems: TStringGrid;
miExe5: TMenuItem;
miExe6: TMenuItem;
miExe7: TMenuItem;
miExe8: TMenuItem;
miIdp5: TMenuItem;
miIdp6: TMenuItem;
miIdp7: TMenuItem;
miIdp8: TMenuItem;
miEditFunctionC: TMenuItem;
miMapGenerator: TMenuItem;
miAutodetectVersion: TMenuItem;
miDelphi2: TMenuItem;
miDelphi3: TMenuItem;
miDelphi4: TMenuItem;
miDelphi5: TMenuItem;
miDelphi6: TMenuItem;
miDelphi7: TMenuItem;
miDelphi2006: TMenuItem;
miDelphi2007: TMenuItem;
miKBTypeInfo: TMenuItem;
miName: TMenuItem;
miLister: TMenuItem;
bCodeNext: TButton;
lProcName: TLabel;
miInformation: TMenuItem;
miEditFunctionI: TMenuItem;
pmStrings: TPopupMenu;
miSearchString: TMenuItem;
miViewClass: TMenuItem;
miDelphi2009: TMenuItem;
miDelphi2010: TMenuItem;
Panel3: TPanel;
lbSXrefs: TListBox;
ShowSXrefs: TPanel;
miAbout: TMenuItem;
miHelp: TMenuItem;
miEditClass: TMenuItem;
miCtdPassword: TMenuItem;
pmCodePanel: TPopupMenu;
miEmptyHistory: TMenuItem;
miTabs: TMenuItem;
Units1: TMenuItem;
RTTI1: TMenuItem;
Forms1: TMenuItem;
CodeViewer1: TMenuItem;
ClassViewer1: TMenuItem;
Strings1: TMenuItem;
miUnitDumper: TMenuItem;
tsNames: TTabSheet;
Names1: TMenuItem;
Panel4: TPanel;
Splitter1: TSplitter;
lbAliases: TListBox;
pnlAliases: TPanel;
lClassName: TLabel;
cbAliases: TComboBox;
bApplyAlias: TButton;
bCancelAlias: TButton;
miLegend: TMenuItem;
miFuzzyScanKB: TMenuItem;
miCopyList: TMenuItem;
miDelphi2005: TMenuItem;
miCommentsGenerator: TMenuItem;
miIDCGenerator: TMenuItem;
miSaveDelphiProject: TMenuItem;
tsSourceCode: TTabSheet;
lbSourceCode: TListBox;
SourceCode1: TMenuItem;
Panel5: TPanel;
ShowNXrefs: TPanel;
lbNXrefs: TListBox;
miHex2Double: TMenuItem;
alMain: TActionList;
acOnTop: TAction;
acShowBar: TAction;
acShowHoriz: TAction;
acDefCol: TAction;
FontsDlg: TFontDialog;
Appearance2: TMenuItem;
Colorsall2: TMenuItem;
Colorsthis2: TMenuItem;
Fontall2: TMenuItem;
Defaultcolumns2: TMenuItem;
Showhorizontalscroll2: TMenuItem;
Showbar2: TMenuItem;
bDecompile: TButton;
miCopyStrings: TMenuItem;
miCopyAddressI: TMenuItem;
miCopyAddressCode: TMenuItem;
pmSourceCode: TPopupMenu;
miCopySource2Clipboard: TMenuItem;
miDelphiXE1: TMenuItem;
miXRefs: TMenuItem;
miDelphiXE2: TMenuItem;
miPlugins: TMenuItem;
miViewAll: TMenuItem;
cbMultipleSelection: TCheckBox;
miSwitchSkipFlag: TMenuItem;
miSwitchFrameFlag: TMenuItem;
miSwitchFlag: TMenuItem;
cfTry1: TMenuItem;
miDelphiXE3: TMenuItem;
miDelphiXE4: TMenuItem;
vtUnit: TVirtualStringTree;
vtRTTI: TVirtualStringTree;
vtName: TVirtualStringTree;
vtString: TVirtualStringTree;
vtProc: TVirtualStringTree;
pmNames: TPopupMenu;
miSetLvartype: TMenuItem;
miCopytoClipboardNames: TMenuItem;
tsMap: TTabSheet;
vtMap: TVirtualStringTree;
pmMap: TPopupMenu;
miHiewGenerator: TMenuItem;
Map1: TMenuItem;
mniShellintegration: TMenuItem;
N2: TMenuItem;
Copy1: TMenuItem;
CopyLines1: TMenuItem;
Copyalltoclipboard1: TMenuItem;
procedure miExitClick(Sender : TObject);
procedure miAutodetectVersionClick(Sender : TObject);
procedure FormCreate(Sender : TObject);
procedure FormDestroy(Sender : TObject);
procedure miSaveProjectClick(Sender : TObject);
procedure miOpenProjectClick(Sender : TObject);
procedure lbCodeDblClick(Sender : TObject);
procedure bEPClick(Sender : TObject);
procedure miGoToClick(Sender : TObject);
procedure miExploreAdrClick(Sender : TObject);
procedure miNameClick(Sender : TObject);
procedure miViewProtoClick(Sender : TObject);
procedure lbXrefsDblClick(Sender : TObject);
procedure bCodePrevClick(Sender : TObject);
procedure tvClassesDblClick(Sender : TObject);
procedure miSearchUnitClick(Sender : TObject);
procedure miSearchVMTClick(Sender : TObject);
procedure miSearchRTTIClick(Sender : TObject);
procedure miCopyCodeClick(Sender : TObject);
procedure miRenameUnitClick(Sender : TObject);
procedure FormClose(Sender : TObject; Var Action:TCloseAction);
procedure lbFormsDblClick(Sender : TObject);
procedure FormKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
procedure lbCodeKeyDown(Sender : TObject; Var Key:Word; Shift:TShiftState);
procedure miCollapseAllClick(Sender : TObject);
procedure NamePosition;
procedure GoToAddress;
procedure FindText(str:AnsiString);
procedure miSearchItemClick(Sender : TObject);
procedure ShowCXrefsClick(Sender : TObject);
procedure lbFormsMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure lbCodeMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure tvClassesFullMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure lbXrefsMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure rgViewerModeClick(Sender : TObject);
procedure tvClassesShortMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure miClassTreeBuilderClick(Sender : TObject);
procedure tvClassesShortClick(Sender : TObject);
procedure tvClassesFullClick(Sender : TObject);
procedure miExe1Click(Sender : TObject);
procedure miExe2Click(Sender : TObject);
procedure miExe3Click(Sender : TObject);
procedure miExe4Click(Sender : TObject);
procedure miIdp1Click(Sender : TObject);
procedure miIdp2Click(Sender : TObject);
procedure miIdp3Click(Sender : TObject);
procedure miIdp4Click(Sender : TObject);
procedure FormShow(Sender : TObject);
procedure miKBTypeInfoClick(Sender : TObject);
procedure miExe5Click(Sender : TObject);
procedure miExe6Click(Sender : TObject);
procedure miExe7Click(Sender : TObject);
procedure miExe8Click(Sender : TObject);
procedure miIdp5Click(Sender : TObject);
procedure miIdp6Click(Sender : TObject);
procedure miIdp7Click(Sender : TObject);
procedure miIdp8Click(Sender : TObject);
procedure FormResize(Sender : TObject);
procedure miEditFunctionCClick(Sender : TObject);
procedure lbXrefsDrawItem(Control: TWinControl; Index:Integer; Rect:TRect; State:TOwnerDrawState);
procedure miMapGeneratorClick(Sender : TObject);
procedure pmUnitsPopup(Sender : TObject);
procedure lbCodeDrawItem(Control: TWinControl; Index:Integer; Rect:TRect; State:TOwnerDrawState);
procedure miDelphi2Click(Sender : TObject);
procedure miDelphi3Click(Sender : TObject);
procedure miDelphi4Click(Sender : TObject);
procedure miDelphi5Click(Sender : TObject);
procedure miDelphi6Click(Sender : TObject);
procedure miDelphi7Click(Sender : TObject);
procedure miDelphi2005Click(Sender : TObject);
procedure miDelphi2006Click(Sender : TObject);
procedure miDelphi2007Click(Sender : TObject);
procedure lbXrefsKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
procedure lbFormsKeyDown(Sender : TObject; Var Key:Word; Shift:TShiftState);
procedure tvClassesShortKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
procedure miListerClick(Sender : TObject);
procedure bCodeNextClick(Sender : TObject);
procedure miEditFunctionIClick(Sender : TObject);
procedure miSearchStringClick(Sender : TObject);
procedure miViewClassClick(Sender : TObject);
procedure pmVMTsPopup(Sender : TObject);
procedure ShowSXrefsClick(Sender : TObject);
procedure miAboutClick(Sender : TObject);
procedure miHelpClick(Sender : TObject);
procedure FormCloseQuery(Sender : TObject; Var CanClose:Boolean);
procedure miEditClassClick(Sender : TObject);
procedure miCtdPasswordClick(Sender : TObject);
procedure pmCodePanelPopup(Sender : TObject);
procedure miEmptyHistoryClick(Sender : TObject);
procedure Units1Click(Sender : TObject);
procedure RTTI1Click(Sender : TObject);
procedure Forms1Click(Sender : TObject);
procedure CodeViewer1Click(Sender : TObject);
procedure ClassViewer1Click(Sender : TObject);
procedure Strings1Click(Sender : TObject);
procedure Names1Click(Sender : TObject);
procedure miUnitDumperClick(Sender : TObject);
procedure miFuzzyScanKBClick(Sender : TObject);
procedure miDelphi2009Click(Sender : TObject);
procedure miDelphi2010Click(Sender : TObject);
procedure bApplyAliasClick(Sender : TObject);
procedure bCancelAliasClick(Sender : TObject);
procedure lbAliasesDblClick(Sender : TObject);
procedure miLegendClick(Sender : TObject);
procedure miCopyListClick(Sender : TObject);
procedure miCommentsGeneratorClick(Sender : TObject);
procedure miIDCGeneratorClick(Sender : TObject);
procedure miSaveDelphiProjectClick(Sender : TObject);
procedure bDecompileClick(Sender : TObject);
procedure SourceCode1Click(Sender : TObject);
procedure miHex2DoubleClick(Sender : TObject);
procedure acFontAllExecute(Sender : TObject);
procedure pmUnitItemsPopup(Sender : TObject);
procedure miCopyAddressIClick(Sender : TObject);
procedure miCopyAddressCodeClick(Sender : TObject);
procedure miCopySource2ClipboardClick(Sender : TObject);
procedure miDelphiXE1Click(Sender : TObject);
procedure pmCodePopup(Sender : TObject);
procedure lbFormsClick(Sender : TObject);
procedure lbCodeClick(Sender : TObject);
procedure pcInfoChange(Sender : TObject);
procedure pcWorkAreaChange(Sender : TObject);
procedure miPluginsClick(Sender : TObject);
procedure miCopyStringsClick(Sender : TObject);
procedure miViewAllClick(Sender : TObject);
procedure lbSourceCodeMouseMove(Sender : TObject; Shift:TShiftState; X,Y:Integer);
procedure cbMultipleSelectionClick(Sender : TObject);
procedure lbSourceCodeDrawItem(Control: TWinControl; Index:Integer; Rect:TRect; State:TOwnerDrawState);
procedure miSwitchSkipFlagClick(Sender : TObject);
procedure miSwitchFrameFlagClick(Sender : TObject);
procedure cfTry1Click(Sender : TObject);
procedure Copy1Click(Sender: TObject);
procedure Copyalltoclipboard1Click(Sender: TObject);
procedure CopyLines1Click(Sender: TObject);
procedure miHiewGeneratorClick(Sender: TObject);
procedure lbSourceCodeClick(Sender: TObject);
procedure Map1Click(Sender: TObject);
procedure miCopytoClipboardNamesClick(Sender: TObject);
procedure miDelphiXE3Click(Sender : TObject);
procedure miDelphiXE4Click(Sender : TObject);
Procedure miProcessDumperClick(Sender:TObject);
procedure miDelphiXE2Click(Sender: TObject);
procedure pmSourceCodePopup(Sender: TObject);
procedure SetLvartypeClick(Sender: TObject);
procedure mniShellintegrationClick(Sender: TObject);
procedure vtMapFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtMapNodeDblClick(Sender: TBaseVirtualTree; const HitInfo: THitInfo);
procedure vtProcClick(Sender: TObject);
procedure vtNameClick(Sender: TObject);
procedure vtNameCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtNameFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
procedure vtNameFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtNameGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtProcCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtProcDblClick(Sender: TObject);
procedure vtProcFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtProcGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtProcPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
procedure vtRTTIClick(Sender: TObject);
procedure vtRTTICompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtRTTIDblClick(Sender: TObject);
procedure vtRTTIFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtRTTIGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: WideString);
procedure vtRTTIGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtStringClick(Sender: TObject);
procedure vtStringCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtStringDblClick(Sender: TObject);
procedure vtStringFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex);
procedure vtStringFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtStringGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtStringPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
procedure vtUnitClick(Sender: TObject);
procedure vtUnitCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
procedure vtUnitDblClick(Sender: TObject);
procedure vtUnitFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure vtUnitGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: WideString);
procedure vtUnitKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure vtUnitMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure vtUnitPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
private
ProjectLoaded:Boolean;
dragdropHelper:TDragDropHelper;
//typedef std::map<const String, TTreeNode*> TTreeNodeNameMap;
tvClassMap:TStringList;
Procedure Init;
Procedure AnalyzeThreadDone(Sender:TObject);
Function IsExe(FileName:AnsiString):Boolean;
Function IsIdp(FileName:AnsiString):Boolean;
Procedure LoadFile(FileName:AnsiString; version:Integer);
Procedure LoadDelphiFile(version:Integer);
Procedure LoadDelphiFile1(FileName:AnsiString; version:Integer; loadExp, loadImp:Boolean);
Procedure ReadNode(stream:TStream; node:TTreeNode; buf:PAnsiChar);
Procedure OpenProject(FileName:AnsiString);
Function ImportsValid(ImpRVA,ImpSize:Integer):Boolean;
function LoadImage(f:TFileStream; version:Integer; loadExp, loadImp:Boolean): Integer;
Procedure FindExports;
Procedure FindImports;
Function GetDelphiVersion:Integer;
Procedure InitSysProcs;
Function IsExtendedInitTab(var unitsTab:Integer):Boolean;
Function GetUnits2(dprName:AnsiString):Integer; //For Delphi2 (other structure!)
Function GetUnits(dprName:AnsiString):Integer;
Function GetBCBUnits(dprName:AnsiString):Integer;
Function IsValidCode(fromAdr:Integer):Integer;
Procedure CodeHistoryPush(rec:PPROCHISTORYREC);
Function CodeHistoryPop:PPROCHISTORYREC;
Procedure ShowCodeXrefs(Adr:Integer; selIdx:Integer);
Procedure ShowStringXrefs(Adr:Integer; selIdx:Integer);
Procedure ShowNameXrefs(Adr:Integer; selIdx:Integer);
Procedure StartProgress(text0, text1:AnsiString; steps:Integer);
Procedure WriteNode(stream:TStream; node:TTreeNode);
Procedure SaveProject(FileName:AnsiString);
Procedure CloseProject;
Procedure CleanProject;
Procedure IniFileRead;
Procedure IniFileWrite;
Procedure AddExe2MRF(FileName:AnsiString);
Procedure AddIdp2MRF(FileName:AnsiString);
Function GetSegmentNo(Adr:Integer):Integer;
function CodeGetTargetAdr(line:AnsiString; trgAdr:PInteger): Integer;
procedure OutputLine(Var outF:TextFile; flag:Byte; adr:Integer; content:AnsiString);
procedure OutputCode(Var outF:TextFile; fromAdr:Integer; prototype:AnsiString; onlyComments:Boolean);
//Drag & Drop
procedure wm_dropFiles(Var Msg:TWMDropFiles); message WM_DROPFILES;
Procedure DoOpenProjectFile(FileName:AnsiString);
Function ContainsUnexplored(recU:PUnitRec):Boolean;
//GUI update from thread
Procedure wm_updAnalysisStatus(var msg:TMessage); Message WM_UPDANALYSISSTATUS;
Procedure wm_dfmClosed(Var msg:TMessage); Message WM_DFMCLOSED;
//Tree view booster
Procedure ClearTreeNodeMap;
Procedure SetupAllFonts(font:TFont);
procedure miSearchFormClick(Sender:TObject);
procedure miSearchNameClick(Sender:TObject);
public
AppDir:AnsiString;
WrkDir:AnsiString;
SourceFile:AnsiString;
SysProcsNum:Integer; //Number of elements in SysProcs array
WhereSearch:TSearchPlace;
//UNITS
UnitsSearchFrom:PVirtualNode;
UnitsSearchList:TStringList;
UnitsSearchText:AnsiString;
//RTTIS
RTTIsSearchFrom:PVirtualNode;
RTTIsSearchList:TStringList;
RTTIsSearchText:AnsiString;
//UNITITEMS
UnitItemsSearchFrom:PVirtualNode;
UnitItemsSearchList:TStringList;
UnitItemsSearchText:AnsiString;
//FORMS
FormsSearchFrom:Integer;
FormsSearchList:TStringList;
FormsSearchText:AnsiString;
//VMTS
TreeSearchFrom:TTreeNode;
BranchSearchFrom:TTreeNode;
VMTsSearchList:TStringList;
VMTsSearchText:AnsiString;
//STRINGS
StringsSearchFrom:PVirtualNode;
StringsSearchList:TStringList;
StringsSearchText:AnsiString;
//NAMES
NamesSearchFrom:PVirtualNode;
NamesSearchList:TStringList;
NamesSearchText:AnsiString;
Constructor Create(Owner:TComponent); Override;
Destructor Free;
Procedure DoOpenDelphiFile(version:Integer; FileName:AnsiString; loadExp, loadImp:Boolean);
Procedure ClearPassFlags;
Function EstimateProcSize(fromAdr:Integer):Integer;
function EvaluateInitTable(Data:PAnsiChar; Size, Base:Integer): Integer;
function GetField(TypeName:AnsiString; Offset:Integer; var vmt:Boolean; var vmtAdr:Integer;Prefix:AnsiString): FieldInfo;
Function AddField(ProcAdr:Integer; ProcOfs:Integer; TypeName:AnsiString; Scope:Byte; Offset, _Case:Integer; Name, _Type:AnsiString):FieldInfo;
Function GetMethodOfs(rec:InfoRec; procAdr:Integer):Integer;
function GetMethodInfo(rec:InfoRec; _name:AnsiString): PMethodRec; overload;
Function GetMethodInfo(adr:Integer; kind:Char; methodOfs:Integer):PMethodRec; Overload;
Function GetImportRec(adr:Integer):PImportNameRec;
procedure StrapProc(_pos, ProcIdx:Integer; ProcInfo:PMProcInfo; useFixups:Boolean; procSize:Integer);
Procedure ShowUnits(showUnk:Boolean);
procedure ShowUnitItems(recU:PUnitRec; topIdx, itemIdx:Cardinal);
Procedure ShowRTTIs;
Procedure FillVmtList;
Procedure ShowClassViewer(VmtAdr:Integer);
function IsUnitExist(_Name:AnsiString): Boolean;
Procedure SetVmtConsts(version:Integer);
Function GetUnit(Adr:Integer):PUnitRec;
Function GetUnitName(recU:PUnitRec):AnsiString; Overload;
Function GetUnitName(Adr:Integer):AnsiString; Overload;
procedure SetUnitName(recU:PUnitRec; _name:AnsiString);
Function InOneUnit(Adr1, Adr2:Integer):Boolean;
procedure StrapVMT(_pos, ConstId:Integer; ConstInfo:PMConstInfo);
function StrapCheck(_pos:Integer; ProcInfo:PMProcInfo): Boolean;
Function GetNodeByName(AName:AnsiString):TTreeNode;
Procedure ScanIntfTable(adr:Integer);
Procedure ScanAutoTable(adr:Integer);
Procedure ScanInitTable(adr:Integer);
Procedure ScanFieldTable(adr:Integer);
Procedure ScanMethodTable(adr:Integer; clasName:AnsiString);
Procedure ScanDynamicTable(adr:Integer);
Procedure ScanVirtualTable(adr:Integer);
Function GetClassHeight(adr:Integer):Integer;
Function GetCommonType(Name1, Name2:AnsiString):AnsiString;
Procedure PropagateVMTNames(adr:Integer);
Procedure ShowStrings;
procedure ShowNames;
//Procedure ScanImports;
Procedure RedrawCode;
function AddAsmLine(adr:Integer; _text:AnsiString; Flags:Byte): Integer;
Procedure ShowCode(fromAdr:Integer; SelectedIdx, XrefIdx, topIdx:Integer);
Procedure AnalyzeProc(pass:Integer; procAdr:Integer);
Procedure AnalyzeMethodTable(pass:Integer; adr:Integer; var Terminated:Boolean);
Procedure AnalyzeDynamicTable(pass:Integer; adr:Integer; var Terminated:Boolean);
Procedure AnalyzeVirtualTable(pass:Integer; adr:Integer; Var Terminated:Boolean);
Function AnalyzeProcInitial(fromAdr:Integer):Integer;
Procedure AnalyzeProc1(fromAdr:Integer; xrefType:Char; xrefAdr:Integer; xrefOfs:Integer; maybeEmb:Boolean);
Procedure AnalyzeProc2(fromAdr:Integer; addArg, AnalyzeRetType:Boolean); Overload;
Function AnalyzeProc2(fromAdr:Integer; addArg, AnalyzeRetType:Boolean; sctx:TList):Boolean; Overload;
function AnalyzeTypes(parentAdr:Integer; callPos:Integer; callAdr:Integer; var registers:RegList): AnsiString;
Function AnalyzeArguments(fromAdr:Integer):AnsiString;
Function LoadIntfTable(adr:Integer; dstList:TStringList):Integer;
Function LoadAutoTable(adr:Integer; dstList:TStringList):Integer;
Function LoadFieldTable(adr:Integer; dstList:TList):Integer;
Function LoadMethodTable(adr:Integer; dstList:TList):Integer; Overload;
Function LoadMethodTable(adr:Integer; dstList:TStringList):Integer; Overload;
Function LoadDynamicTable(adr:Integer; dstList:TList):Integer; Overload;
Function LoadDynamicTable(adr:Integer; dstList:TStringList):Integer; Overload;
Function LoadVirtualTable(adr:Integer; dstList:TList):Integer; Overload;
Function LoadVirtualTable(adr:Integer; dstList:TStringList):Integer; Overload;
Procedure FillClassViewerOne(n:Integer; tmpList:TStringList; Var terminated:Boolean);
function AddClassTreeNode(node:TTreeNode; nodeText:AnsiString): TTreeNode;
//Function
Procedure EditFunction(Adr:Integer);
Function MakeComment(code:PPICODE):AnsiString;
Procedure InitAliases(find:Boolean);
procedure CopyAddress(adr:Integer);
Procedure GoToXRef(Sender:TObject);
//Procedure ChangeDelphiHighlightTheme(Sender:TObject);
// Map
procedure MapGenerator;
procedure GoToAddressMap(cmdAdr:AnsiString);
procedure ExploreAdrMap(cmdAdr:AnsiString);
procedure ExpGotoAddressMap(FlagGo:Boolean);
//Treenode booster for analysis
procedure AddTreeNodeWithName(node:TTreeNode; Const Aname:AnsiString);
function FindTreeNodeByName(Const Aname:AnsiString): TTreeNode;
//show Form by its dfm object
Procedure ShowDfm(dfm:TDfm);
end;
function FindClassAdrByName(const AName:AnsiString):Integer;
procedure AddClassAdr(Adr:Integer; const AName:AnsiString);
Var
SysProcs:Array[0..6] of SysProcInfo = (
(name:'@HandleFinally'; impAdr:0),
(name:'@HandleAnyException'; impAdr:0),
(name:'@HandleOnException'; impAdr:0),
(name:'@HandleAutoException'; impAdr:0),
(name:'@RunError'; impAdr:0),
(name:'@Halt0'; impAdr:0),
(name:'@AbstractError'; impAdr:0)
);
SysInitProcs:Array[0..1] Of SysProcInfo = (
(name:'@InitExe'; impAdr:0),
(name:'@InitLib'; impAdr:0)
);
cmdAdr:string;
dummy:Integer; //for debugging purposes!!!
FMain: TFMain;
ProjectModified:Boolean;
frmDisasm:MDisasm; //Äèçàññåìáëåð äëÿ àíàëèçàòîðà êîäà
KBase:MKnowledgeBase;
ResInfo:TResourceInfo; //Information about forms
Code:PAnsiChar;
CodeSize:Integer;
ImageSize:Integer;
Image:PAnsiChar;
CurProcAdr:Integer;
CurUnitAdr:Integer;
VmtList:TList; //VMT list
CodeBase:PAnsiChar;
DelphiVersion:Integer;
InfoList:array of InfoRec; //Array of pointers to store items data
BSSInfos:TStringList; //Data from BSS
SegmentList:TList; //Information about Image Segments
TotalSize:Integer; //Size of sections CODE + DATA
FlagList:array of TCflagSet; //flags for used data
OwnTypeList:TList;
SelectedAsmItem:AnsiString; //Selected item in Asm Listing
SelectedSourceItem:AnsiString; //Selected item in Source Code
CrtSection:TCriticalSection;
MaxBufLen:Integer; //Ìàêñèìàëüíàÿ äëèíà áóôåðà (äëÿ çàãðóçêè)
HInstanceVarAdr:Integer;
EP:Integer;
UnitsNum:Integer;
Units:TList;
LastResStrNo:Integer; //Last ResourceStringNo
ClassTreeDone:Boolean;
SplitIDC:Boolean;
BCB:Boolean;
SplitSize:Integer;
implementation
{$R *.DFM}
Uses Threads,Misc,StrUtils,Def_disasm,Heuristic,{Highlight,}ActiveX,ShlObj,
StringInfo, Explorer, FindDlg, EditFieldsDlg,Def_res,IniFiles,TypeInfos,
InputDlg,Def_thread, EditFunctionDlg,IDCGen,AboutDlg,ShellAPI,Contnrs,
KBViewer, Legend,Decompiler, Hex2Double,Clipbrd, Plugins,ActiveProcesses,
Scanf,TypInfo,Math,IdcSplitSize{,CodeSiteLogging};
Var
//Dest:TCodeSiteDestination;
DelphiLbId:Cardinal;
DelphiThemesCount:Integer;
//Image Code
//|===========|======================================|
//ImageBase CodeBase
CodeHistorySize:Integer; //Current size of Code navigation History Array
CodeHistoryPtr:Integer; //Curent pointer of Code navigation History Array
CodeHistoryMax:Integer; //Max pointer position of Code navigation History Array (for ->)
CodeHistory:Array of PROCHISTORYREC; //Code navigation History Array
AnalyzeThread:TAnalyzeThread; //Ïîòîê äëÿ ôîíîâîãî àíàëèçà êîäà
AnalyzeThreadRetVal:Integer;
SourceIsLibrary:Boolean;
UserKnowledgeBase:Boolean;
//Common variables
IDPFile:AnsiString;
ImageBase:Integer;
CodeStart:Integer;
DataBase:Integer;
DataSize:Integer;
DataStart:Integer;
Data:Pointer;
ExpFuncList:TList; //Exported functions list (temporary)
ImpFuncList:TList; //Imported functions list (temporary)
ImpModuleList:TStringList; //Imported modules list (temporary)
CurProcSize:Integer;
LastTls:Integer; //Ïîñëåäíèé çàíÿòûé èíäåêñ Tls, ïîêàçûâàåò, ñêîëüêî ThreadVars â ïðîãðàììå
Reserved:Integer;
CtdRegAdr:Integer; //Àäðåñ ïðîöåäóðû CtdRegAdr
//class addresses cache
//typedef std::map<const String, DWORD> TClassAdrMap;
classAdrMap:TStringList;
Procedure ClearClassAdrMap; Forward;
Constructor TFMain.Create(Owner:TComponent);
Begin
Inherited;
dragdropHelper:=TDragDropHelper.Create(Handle);
CrtSection:=TCriticalSection.Create;
end;
Destructor TFMain.Free;
Begin
CrtSection.Free;
end;
procedure TFMain.FormClose(Sender : TObject; Var Action:TCloseAction);
begin
ModalResult:=mrCancel;
end;
procedure TFMain.FormKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
begin
case Key of
Ord('G'): GoToAddress;
Ord('N'): NamePosition;
Ord('F'): //CTRL + F (1st search on different areas)
if ssCtrl in Shift then case WhereSearch of
SEARCH_UNITS: miSearchUnitClick(Sender);
SEARCH_UNITITEMS: miSearchItemClick(Sender);
SEARCH_RTTIS: miSearchRTTIClick(Sender);
SEARCH_FORMS: miSearchFormClick(Sender);
SEARCH_CLASSVIEWER: miSearchVMTClick(Sender);
SEARCH_STRINGS: miSearchStringClick(Sender);
SEARCH_NAMES: miSearchNameClick(Sender);
//todo rest of locations
End;
VK_F3: // F3 - (2nd search, continue search with same text)
case WhereSearch of
SEARCH_UNITS: FindText(UnitsSearchText);
SEARCH_UNITITEMS: FindText(UnitItemsSearchText);
SEARCH_RTTIS: FindText(RTTIsSearchText);
SEARCH_FORMS: FindText(FormsSearchText);
SEARCH_CLASSVIEWER: FindText(VMTsSearchText);
SEARCH_STRINGS: FindText(StringsSearchText);
SEARCH_NAMES: FindText(NamesSearchText);
End;
End;
end;
procedure TFMain.Units1Click(Sender : TObject);
begin
//if tsUnits.Enabled then
//begin
pcInfo.ActivePage := tsUnits;
if vtUnit.CanFocus then ActiveControl := vtUnit;
//end;
end;
procedure TFMain.RTTI1Click(Sender : TObject);
begin
//if tsRTTIs.Enabled then
//begin
pcInfo.ActivePage := tsRTTIs;
if vtRTTI.CanFocus then ActiveControl := vtRTTI;
//end;
end;
procedure TFMain.Forms1Click(Sender : TObject);
begin
//if tsForms.Enabled then
//begin
pcInfo.ActivePage := tsForms;
if lbForms.CanFocus then ActiveControl := lbForms;
//end;
end;
procedure TFMain.CodeViewer1Click(Sender : TObject);
begin
//if tsCodeView.Enabled then
//begin
pcWorkArea.ActivePage := tsCodeView;
if lbCode.CanFocus then ActiveControl := lbCode;
//end;
end;
procedure TFMain.ClassViewer1Click(Sender : TObject);
begin
//if tsClassView.Enabled then
//begin
pcWorkArea.ActivePage := tsClassView;
if rgViewerMode.ItemIndex=0 then
if tvClassesFull.CanFocus then ActiveControl := tvClassesFull
else if tvClassesShort.CanFocus then ActiveControl := tvClassesShort;
//end;
end;
procedure TFMain.Strings1Click(Sender : TObject);
begin
//if tsStrings.Enabled then
//begin
pcWorkArea.ActivePage := tsStrings;
if vtString.CanFocus then ActiveControl := vtString;
//end;
end;
procedure TFMain.Names1Click(Sender : TObject);
begin
//if tsNames.Enabled then
//begin
pcWorkArea.ActivePage := tsNames;
if vtName.CanFocus then ActiveControl := vtName;
//end;
end;
procedure TFMain.SourceCode1Click(Sender : TObject);
begin
//if tsSourceCode.Enabled then
//begin
pcWorkArea.ActivePage := tsSourceCode;
if lbSourceCode.CanFocus then ActiveControl := lbSourceCode;
//end;
end;
procedure TFMain.miExitClick(Sender : TObject);
begin
Close;
end;
Procedure TFMain.Init;
Begin
IDPFile := '';
UnitsNum := 0;
CurProcAdr := 0;
CurProcSize := 0;
SelectedAsmItem := '';
SelectedSourceItem:='';
CurUnitAdr := 0;
CodeHistoryPtr := -1;
CodeHistorySize := 0; //HISTORY_CHUNK_LENGTH;
SetLength(CodeHistory,0);
CodeHistoryMax := CodeHistoryPtr;
DelphiVersion := -1;
Caption := 'Interactive Delphi Reconstructor by crypto';
HInstanceVarAdr := -1;
LastTls := 0;
CtdRegAdr := 0;
WhereSearch := SEARCH_UNITS;
UnitsSearchFrom := Nil;
UnitsSearchText := '';
RTTIsSearchFrom := Nil;
RTTIsSearchText := '';
FormsSearchFrom := -1;
FormsSearchText := '';
UnitItemsSearchFrom := Nil;
UnitItemsSearchText := '';
TreeSearchFrom := Nil;
BranchSearchFrom := Nil;
VMTsSearchText := '';
StringsSearchFrom := Nil;
StringsSearchText := '';
NamesSearchFrom := Nil;
NamesSearchText := '';
//Init Menu
miLoadFile.Enabled := true;
miOpenProject.Enabled := true;
miMRF.Enabled := true;
miSaveProject.Enabled := false;
miSaveDelphiProject.Enabled := false;
miExit.Enabled := true;
miMapGenerator.Enabled := false;
miCommentsGenerator.Enabled := false;
miIDCGenerator.Enabled := false;
miHiewGenerator.Enabled := false;
miLister.Enabled := false;
miClassTreeBuilder.Enabled := false;
miKBTypeInfo.Enabled := false;
miCtdPassword.Enabled := false;
miHex2Double.Enabled := false;
//Init Units
vtUnit.Clear;
miRenameUnit.Enabled := false;
miSearchUnit.Enabled := false;
miCopyList.Enabled := false;
vtUnit.Header.SortColumn := 0;
tsUnits.Enabled := false;
//Init RTTIs
vtRTTI.Clear;
miSearchRTTI.Enabled := false;
tsRTTIs.Enabled := false;
//Init Forms
lbForms.Clear;
lbAliases.Clear;
lClassName.Caption := '';
cbAliases.Clear;
rgViewFormAs.ItemIndex := 0;
tsForms.Enabled := false;
//Init Code
lProcName.Caption := '';
lbCode.Clear;
lbCode.ScrollWidth := 0;
miGoTo.Enabled := false;
miExploreAdr.Enabled := false;
miName.Enabled := false;
miViewProto.Enabled := false;
miEditFunctionC.Enabled := false;
miXRefs.Enabled := false;
miSwitchFlag.Enabled := false;
bEP.Enabled := false;
bDecompile.Enabled := false;
bCodePrev.Enabled := false;
bCodeNext.Enabled := false;
tsCodeView.Enabled := false;
lbCXrefs.Clear;
lbCXrefs.Visible := true;
//Init Strings
vtString.Clear;
miSearchString.Enabled := false;
tsStrings.Enabled := false;
//Init Map
vtMap.Clear;
tsMap.Enabled := false;
//Init Names
vtName.Clear;
tsNames.Enabled := false;
//Xrefs
lbSXrefs.Clear;
lbSXrefs.Visible := true;
//Init Unit Items
vtProc.Clear;
miEditFunctionI.Enabled := false;
miFuzzyScanKB.Enabled := false;
miSearchItem.Enabled := false;
//Init ClassViewer
ClassTreeDone := false;
tvClassesFull.Items.Clear;
tvClassesShort.Items.Clear;
tvClassesShort.BringToFront;
rgViewerMode.ItemIndex := 1; //Short View
tsClassView.Enabled := false;
ClearTreeNodeMap;
ClearClassAdrMap;
{
pb.Position := 0;
pb.Visible := false;
sb.Panels[0].Width := Width div 2;
sb.Panels[0].Text := '';
sb.Panels[1].Text := '';
}
Update;
Sleep(0);
ProjectLoaded := false;
ProjectModified := false;
UserKnowledgeBase := false;
SourceIsLibrary := false;
end;
Function TFMain.GetImportRec (adr:Integer):PImportNameRec;
var
n:Integer;
Begin
for n := 0 to ImpFuncList.Count-1 do
begin
Result:= ImpFuncList[n];
if adr = Result.address Then Exit;
end;
Result:=Nil;
end;
Procedure TFMain.FindExports;
var
_pos,i,Adr:Integer;
recE:PExportNameRec;
recN:InfoRec;
Begin
for i := 0 to ExpFuncList.Count-1 do
begin
recE := ExpFuncList[i];
Adr := recE.address;
if IsValidImageAdr(Adr) then
begin
_pos :=Adr2Pos(Adr);
if _pos <> -1 then
begin
recN := InfoRec.Create(_pos, ikRefine);
recN.Name:=recE.name;
recN.procInfo.call_kind := 3; // stdcall
recN.procInfo.flags:=[];
InfoList[_pos] := recN; // probably needless, since InfoRec.Create already did it
SetFlag([cfProcStart, cfExport], _pos);
end;
End;
end;
end;
Procedure TFMain.FindImports;
var
_pos,i,n,Adr,b,e:Integer;
recI:PImportNameRec;
recN:InfoRec;
Begin
for i := 0 to TotalSize - 7 do
Begin
if (Code[i] = #255) and (Code[i + 1] = #$25) then
Begin
adr := PInteger(Code + i + 2)^;
recI := GetImportRec(adr);
if Assigned(recI) then
Begin
//name := UnmangleName(recI.name);
if not Assigned(InfoList[i]) then
Begin
recN := InfoRec.Create(i, ikRefine);
recN.procInfo.procSize:=6;
SetFlag([cfProcStart],i);
SetFlag([cfProcEnd],i+6);
if (Pos('@Initialization$',recI.name)<>0) or (Pos('@Finalization$',recI.name)<>0) then