-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathDCURecs.pas
6398 lines (5929 loc) · 150 KB
/
DCURecs.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 DCURecs;
(*
The DCU records module of the DCU32INT utility by Alexei Hmelnov.
It contains classes for representation of DCU declarations and
definitions in memory.
----------------------------------------------------------------------------
E-Mail: alex@icc.ru
http://hmelnov.icc.ru/DCU/
----------------------------------------------------------------------------
See the file "readme.txt" for more details.
------------------------------------------------------------------------
IMPORTANT NOTE:
This software is provided 'as-is', without any expressed or implied warranty.
In no event will the author be held liable for any damages arising from the
use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented, you must not
claim that you wrote the original software.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*)
interface
{$IFNDEF VER90}
{$IFNDEF VER100}
{$REALCOMPATIBILITY ON}
{$ENDIF}
{$ENDIF}
uses
SysUtils,Classes, DCU_In, DCU_Out, DasmDefs, FixUp
{$IFDEF UNICODE}, AnsiStrings{$ENDIF};
type
{ Auxiliary data types }
PLocVarRec = ^TLocVarRec;
TLocVarRec = record
sym: integer; //Symbol # in the symbol table, 0 - proc data end
ofs: integer; //Offset in procedure code
frame: integer; //-1(0x7f)-symbol end, else - symbol start 0-EAX, 1-EDX,
//2-ECX, 3-EBX, 4-ESI...
end ;
PLocVarTbl = ^TLocVarTbl;
TLocVarTbl = array[Word] of TLocVarRec;
TDeclListKind = (dlMain,dlMainImpl,dlArgs,dlArgsT,dlEmbedded,dlFields,
dlClass,dlInterface,dlDispInterface,dlUnitAddInfo,dlA6);
TDeclSecKind = (skNone,skLabel,skConst,skType,skVar,skThreadVar,skResStr,
skExport,skProc,skPrivate,skProtected,skPublic,skPublished);
type
TDCURec = class;
//for verD_XE - fix orphaned local types problem
TTypeUseAction = procedure(UseRec: TDCURec; hDT: TDefNDX; IP: Pointer);
PTDCURec = ^TDCURec;
TDCURec = class(TObject)
Next: TDCURec;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; virtual;
function NameIsUnique: boolean; virtual;
function GetName: PName; virtual;
procedure ShowName; virtual;
procedure Show; virtual;
procedure ShowDef(All: boolean); virtual;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); virtual;
//for verD_XE - fix orphaned local types problem
function GetSecKind: TDeclSecKind; virtual;
function IsVisible(LK: TDeclListKind): boolean; virtual;
function GetTag: TDCURecTag; virtual;
property Name: PName read GetName;
end ;
TBaseDef = class(TDCURec)
FName: PName;
Def: PDef;
hUnit: integer;
hDecl: integer;
constructor Create(AName: PName; ADef: PDef; AUnit: integer);
procedure ShowName; override;
procedure Show; override;
procedure ShowNamed(N: PName);
function GetName: PName; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
end ;
TImpKind=AnsiChar;
TImpDef = class(TBaseDef)
ik: TImpKind;
FNameIsUnique: boolean;
// ImpRec: TDCURec;
Inf: integer;
constructor Create(AIK: TImpKind; AName: PName; AnInf: integer; ADef: PDef; AUnit: integer);
procedure Show; override;
// procedure GetImpRec;
function NameIsUnique: boolean; override;
end ;
TUnitImpDef = class(TImpDef)
sPackage: String; //for .NET
procedure Show; override;
end ;
TDLLImpRec = class(TBaseDef{TImpDef})
NDX: integer;
constructor Create(AName: PName; ANDX: integer; ADef: PDef; AUnit: integer);
procedure Show; override;
end ;
TImpTypeDefRec = class(TImpDef{TBaseDef})
RTTIOfs,RTTISz: Cardinal; //L: Byte;
hImpUnit: integer;
ImpName: PName;
constructor Create(AName: PName; AnInf: integer; ARTTISz: Cardinal{AL: Byte}; ADef: PDef; AUnit: integer);
procedure Show; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
end ;
type
TConstValInfo = object
hDT: TDefNDX;
Kind: Cardinal; //Ver>4
//O - scalar, 1 - string (offset=8), 2 - resourcestring,
//3-float, 4 - set,
//[ver>=verD12] 5 - Unicode string (offset=12)
ValPtr: Pointer;
ValSz: Cardinal;
Val: integer;
procedure Read;
procedure Show;
end ;
{ Name Declaration Modifiers - store some important information from
drConstAddInfo records and other records like this if any }
type
TDeclModifierClass = class of TDeclModifier;
TDeclModifier = class
protected
FNext: TDeclModifier;
public
destructor Destroy; override;
procedure Show; virtual;
class function ShowBefore: Boolean; virtual;
function GetNextOfClass(Cl: TDeclModifierClass): TDeclModifier;
property Next: TDeclModifier read FNext;
end;
TStrDeclModifier = class(TDeclModifier)
protected
FMsg: TMemStrRef;
function GetMsg: AnsiString;
public
constructor Create(const AMsg: TMemStrRef);
property Msg: AnsiString read GetMsg;
end;
TDeprecatedDeclModifier = class(TStrDeclModifier)
procedure Show; override;
end;
TAttributeDeclAddrArg = record
hDT,hDTAddr: Integer;
end ;
TAttributeDeclArg = record
case Kind: Integer of
0: (C: TConstValInfo);
1: (A: TAttributeDeclAddrArg);
end ;
PAttributeDeclArgs = ^TAttributeDeclArgs;
TAttributeDeclArgs = array[Byte]of TAttributeDeclArg;
TAttributeDeclModifier = class(TDeclModifier)
hAttrDT,hMember,hAttrCtor,ArgCnt: integer;
Args: PAttributeDeclArgs;
constructor Read; //Attention! In contrast to the other modifiers the constructor reads the data
destructor Destroy; override;
procedure Show; override;
class function ShowBefore: Boolean; override;
end;
//.Net information (was observed in DCUIL but may be used somewhere else)
TGeneratedNameDeclModifier = class(TStrDeclModifier) //The value in the generated code
procedure Show; override;
end;
TExtraProcArg = record
Name: TMemStrRef;
V,V1, //Unknown
hDT: Integer;
end ;
PExtraProcArgs = ^TExtraProcArgs;
TExtraProcArgs = array[Byte]of TExtraProcArg;
TExtraArgsDeclModifier = class(TDeclModifier)
//In DCUIL aux records are used as an owner frame for embedded subroutines
//The records are passed as extra parameters of procedures and
//the table contains info about the parameters
ArgCnt: Integer;
Args: PExtraProcArgs;
constructor Read; //Attention! In contrast to the other modifiers the constructor reads the data
destructor Destroy; override;
procedure Show; override;
end;
{/ Name Declaration Modifiers}
type
PTNameDecl = ^TNameDecl;
TNameDecl = class(TDCURec)
protected
FModifiers: TDeclModifier;
procedure ShowModifiers(Before: Boolean);
procedure ShowConstAddInfo;
public
Def: PNameDef;
hDecl: integer;
ConstAddInfoFlags: Integer; //From the corresponding ConstAddInfo
constructor Create00;
constructor Create0;
constructor Create;
destructor Destroy; override;
procedure ShowName; override;
procedure Show; override;
procedure ShowDef(All: boolean); override;
function GetName: PName; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
{function GetSecKind: TDeclSecKind; override;}
function IsVisible(LK: TDeclListKind): boolean; override;
function GetTag: TDCURecTag; override;
procedure AddModifier(M: TDeclModifier);
function GetModifierOfClass(Cl: TDeclModifierClass): TDeclModifier;
property Modifiers: TDeclModifier read FModifiers;
end ;
TNameFDecl = class(TNameDecl)
F,F1: TNDX;
PkgNdx: TNDX;
Inf: integer;
B2: TNDX; //D8+
constructor Create(NoInf: boolean);
procedure Show; override;
function IsVisible(LK: TDeclListKind): boolean; override;
protected
procedure ReadPkgNdx;
end ;
TTypeDecl = class(TNameFDecl)
hDef: TDefNDX;
//PkgNdx: TNDX;
constructor Create(NoInf: boolean);
function IsVisible(LK: TDeclListKind): boolean; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function GetSecKind: TDeclSecKind; override;
function GetName: PName; override;
end ;
TVarDecl = class(TNameFDecl)
hDT: TDefNDX;
Ofs: Cardinal;
constructor Create;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetSecKind: TDeclSecKind; override;
end ;
TVarVDecl = class(TVarDecl)
//In DXE2 win64 an auxiliary variable __puiHead has memory image
Sz: Cardinal;
constructor Create;
procedure Show; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
end ;
TVarCDecl = class(TVarDecl)
Sz: Cardinal;
OfsR: Cardinal;
constructor Create(OfsValid: boolean);
procedure Show; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function GetSecKind: TDeclSecKind; override;
end ;
TAbsVarDecl = class(TVarDecl)
constructor Create;
procedure Show; override;
end ;
TTypePDecl = class(TVarCDecl{TTypeDecl})
{B1: Byte;
constructor Create;}
//PkgNdx: TNDX;
constructor Create;
procedure Show; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
TThreadVarDecl = class(TVarDecl)
function GetSecKind: TDeclSecKind; override;
end ;
TMemBlockRef = class(TNameFDecl)
//abstract base class - ancestor of TStrConstDecl and TProcDecl
Ofs: Cardinal;
Sz: Cardinal;
procedure MemRefFound; virtual; abstract;
end ;
//In Delphi>=8 they started to create this kind of records for string constants
//and other data blocks (instead of TProcDecl, which was used earlier)
TStrConstDecl = class({TVarCDecl}TMemBlockRef)
hDT: TDefNDX;
FX,FX1: Cardinal;
FMemUsed: Boolean;
constructor Create;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function GetSecKind: TDeclSecKind; override;
procedure MemRefFound; override;
function IsVisible(LK: TDeclListKind): boolean; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TLabelDecl = class(TNameDecl)
Ofs: Cardinal;
constructor Create;
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
TExportDecl = class(TNameDecl)
hSym,Index: TNDX;
constructor Create;
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
TLocalDecl = class(TNameDecl)
LocFlags: TNDX;
LocFlagsX: TNDX; //Ver>=8 private, protected, public, published
hDT: TDefNDX;
NDXB: TNDX;//B: Byte; //Interface only
//when LocFlagsX and lfauxPropField<>0 it is used to hold the actual
//field (TLocalDecl) of the reference
Ndx: TNDX;
constructor Create(LK: TDeclListKind);
procedure ShowName; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetLocFlagsSecKind: TDeclSecKind;
function GetSecKind: TDeclSecKind; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
TMethodDecl = class(TLocalDecl)
InIntrf: boolean;
hImport: TNDX; //for property P:X read Proc{virtual,Implemented in parent class}
//or VProc copy of the corresponding procedure
//VMTNDX: integer; //Offset in VMT of VM=VMTNDX*SizeOf(Pointer)
constructor Create(LK: TDeclListKind);
procedure Show; override;
//class definitions can't be local procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TClassVarDecl = class(TLocalDecl)
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
end ;
{TSetDeft struc pas
sd: Cardinal;
ends
}
TPropDecl = class(TNameDecl)
LocFlags: TNDX;
LocFlagsX: TNDX; //Ver>=8 private, protected, public, published
hDT: TNDX;
NDX: TNDX;
hIndex: TNDX;
hRead: TNDX;
hWrite: TNDX;
hStored: TNDX;
//It looks like the next two fields contain references
//to the class members specified in Pascal source for read and
//write when compiler had to change calling convention or something else,
//and hRead or hWrite point to the thunk methods created by the compiler
hReadOrig: TNDX;
hWriteOrig: TNDX;
hDeft: TNDX;
constructor Create;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetSecKind: TDeclSecKind; override;
end ;
TDispPropDecl = class(TLocalDecl)
procedure Show; override;
end ;
TConstDeclBase = class(TNameFDecl)
Value: TConstValInfo;
constructor Create;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetSecKind: TDeclSecKind; override;
end ;
TConstDecl = class(TConstDeclBase)
constructor Create;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
{
TResStrDef = class(TConstDeclBase)
NDX: TNDX;
NDX1: TNDX;
B1: Byte;
B2: Byte;
V: TNDX; //Data type again - AnsiString
RefOfs,RefSz: Cardinal;
constructor Create;
procedure Show; override;
procedure SetMem(MOfs,MSz: Cardinal); override;
end ;}
TResStrDef = class(TVarCDecl)
OfsR: Cardinal;
//PkgNdx: TNDX;
constructor Create;
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
end ;
TSetDeftInfo=class(TNameDecl{TDCURec, but it should be included into NameDecl list})
hConst,hArg: TDefNDX;
constructor Create;
procedure Show; override;
end ;
TCopyDecl = class(TNameDecl)
hBase: TDefNDX;
Base: TNameDecl; //Just in case and for convenience
constructor Create;
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
end ;
(*
TProcDeclBase = class(TNameDecl)
CodeOfs,AddrBase: Cardinal;
Sz: TDefNDX;
constructor Create;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function GetSecKind: TDeclSecKind; override;
end ;
*)
TProcCallKind = (pcRegister,pcCdecl,pcPascal,pcStdCall,pcSafeCall);
TMethodKind = (mkProc,mkMethod,mkConstructor,mkDestructor);
TRegDebugInfo = record
hDecl: Integer;
Ofs: Integer;
IsVar{is var parameter},InReg{In register}: Boolean;
end ;
TShowProcCtx = (spcMain,spcMainImpl,spcOther);
TProcDecl = class(TMemBlockRef{TNameFDecl{TProcDeclBase})
protected
function GetLocVars64Ofs: Integer;
function GetRegLocVar(ProcOfs,id{RegDebugInfoCode}: Integer): TNDX;
function GetDeclByStackOfs(Ofs: Integer; var DOfs: integer): TDCURec;
procedure ShowProc(Ctx: TShowProcCtx);
public
AddrBase: Cardinal;
{---}
B0: TNDX;
VProc: TNDX;
hDTRes: TNDX;
hClass: TNDX;
Args: TDCURec{TNameDecl};
Locals: TDCURec{TNameDecl};
Embedded: TDCURec{TNameDecl};
CallKind: TProcCallKind;
MethodKind: TMethodKind; //may be this information is encoded by some flag, but
//I can't detect it. May be it would be enough to analyse the structure of
//the procedure name, but this way it will be safer.
JustData: boolean; //This flag is turned on by Fixups from String typed consts
FProcLocVarTbl: PLocVarTbl;
FProcLocVarCnt: integer;
FTemplateArgs: TDCURec;
constructor Create(AnEmbedded: TDCURec{TNameDecl}; NoInf: boolean);
destructor Destroy; override;
function IsUnnamed: boolean;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function GetSecKind: TDeclSecKind; override;
procedure ShowArgs;
function IsProc: boolean;
procedure ShowDef(All: boolean); override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function IsVisible(LK: TDeclListKind): boolean; override;
procedure MemRefFound; override;
function GetRegDebugInfo(ProcOfs: integer; hReg: THBMName; Ofs,Size: integer; var Info: TRegDebugInfo): Boolean;
function GetRegDebugInfoStr(ProcOfs: integer; hReg: THBMName; Ofs,Size: integer; var hDecl: integer): AnsiString;
end ;
TSysProcDecl = class(TNameDecl{TProcDeclBase})
F: TNDX;
Ndx: TNDX;
// Ofs: Cardinal;
constructor Create;
procedure Show; override;
function GetSecKind: TDeclSecKind; override;
end ;
//Starting from Delphi 8 Borlands begin to give complete proc. defs to system
//procedures
TSysProc8Decl = class(TProcDecl)
F: TNDX;
Ndx: TNDX;
// Ofs: Cardinal;
constructor Create;
// procedure Show; override;
end ;
(*
TAtDecl = class(TNameDecl)
//May be start of implementation?
NDX: TNDX;
NDX1: TNDX;
constructor Create;
procedure Show; virtual;
end ;
*)
TUnitAddInfo = class(TNameFDecl)
//Ver 7.0 and higher, MSIL
B: TNDX;
Sub: TDCURec{TNameDecl};
constructor Create;
destructor Destroy; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end ;
TSpecVar = class(TVarDecl)
procedure Show; override;
end ;
(*
TAddInfo6 = class(TNameDecl)
V0,V1,V2,V3: TNDX;
Ofs: Cardinal;
Sz: Cardinal;
constructor Create;
procedure Show; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
end ;
*)
type
PQualInfo = ^TQualInfo;
TQualInfo = record //Aux record for and GetOfsQualifierEx and GetRefOfsQualifierEx
U: Pointer{TUnit};
hDT: TNDX;
hDTAddr: TNDX;
OfsRest: Integer;
IsVMT: Boolean;
end ;
TTypeDef = class(TBaseDef)
// hDecl: integer;
RTTISz: TNDX; //Size of RTTI for type, if available
Sz: TNDX; //Size of corresponding variable
FhDT: TNDX; //Aux field, to be able to get quickly the type index of the data type
hAddrDef: TNDX;
X: TNDX;
RTTIOfs: Cardinal;
constructor Create;
destructor Destroy; override;
procedure ShowBase;
procedure Show; override;
function SetMem(MOfs,MSz: Cardinal): Cardinal {Rest}; override;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; virtual;
function ValueAsString(DP: Pointer; DS: Cardinal): AnsiString;
function GetOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; virtual;
function GetOfsQualifier(Ofs: integer): AnsiString;
function GetRefOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; virtual;
function GetRefOfsQualifier(Ofs: integer): AnsiString;
end ;
TRangeBaseDef = class(TTypeDef)
hDTBase: TNDX;
LH: Pointer;
{Lo: TNDX;
Hi: TNDX;}
B: Byte;
procedure GetRange(var Lo,Hi: TInt64Rec);
function GetValCount: TInt64Rec;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TRangeDef = class(TRangeBaseDef)
constructor Create;
end ;
TEnumDef = class(TRangeBaseDef)
Ndx: TNDX;
CStart: TConstDecl;
NameTbl: TList;
HasEq: Boolean; //Some const was defined by Ñ=Ñprev and not included into NameTbl
constructor Create;
destructor Destroy; override;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
end ;
TFloatKind = (fkReal48, fkSingle, fkDouble, fkExtended, fkComp, fkCurrency);
TFloatDef = class(TTypeDef)
Kind: TFloatKind;
constructor Create;
function GetKindName: AnsiString;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
end ;
TPtrDef = class(TTypeDef)
hRefDT: TNDX;
constructor Create;
function ShowRefValue(Ndx: TNDX; Ofs: Cardinal): boolean;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetRefOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
end ;
TTextDef = class(TTypeDef)
procedure Show; override;
end ;
TFileDef = class(TTypeDef)
hBaseDT: TNDX;
constructor Create;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TSetDef = class(TTypeDef)
BStart: Byte; //0-based start byte number
hBaseDT: TNDX;
constructor Create;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TArrayDef0 = class(TTypeDef)
{This type is required to make it parent of TStringDef}
B1: Byte;
hDTNdx: TNDX;
hDTEl: TNDX;
constructor Create(IsStr: boolean);
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TArrayDef = class(TArrayDef0)
function GetOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
end ;
TShortStrDef = class(TArrayDef)
CP: Integer; //for Ver>=VerD12 - Code page
constructor Create;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
end ;
TStringDef = class(TArrayDef0)
CP: Integer; //for Ver>=VerD12 - Code page
constructor Create;
function ShowRefValue(Ndx: TNDX; Ofs: Cardinal): boolean;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
function GetRefOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
end ;
TVariantDef = class(TTypeDef)
B: byte;
constructor Create;
procedure Show; override;
end ;
TObjVMTDef = class(TTypeDef)
hObjDT: TNDX;
VMTSz: TNDX; //The total size of all the VMT memory block
constructor Create;
procedure Show; override;
end ;
TRecBaseDef = class(TTypeDef)
protected
function GetFldByOfs(Ofs,QSz: integer; TotSize: integer; Sorted: boolean): TLocalDecl;
function GetFldOfsQualifier(Ofs,QSz: integer; QI: PQualInfo; TotSize: integer;
Sorted: boolean; QS: PAnsiString): Integer{<0 => field not found, =0 => bad qualifief, >0 = Ok};
function GetMethodByVMTNDX(VMTNDX,VMTCnt: integer): TMethodDecl;
public
Fields: TDCURec{TNameDecl};
procedure ReadFields(LK: TDeclListKind);
function ShowFieldValues(DP: Pointer; DS: Cardinal): integer {Size used};
destructor Destroy; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
function GetParentType: TNDX; virtual;
function GetFldProperty(Fld: TNameDecl; hDT: TNDX): TPropDecl;
function GetMemberByNum(Num: Integer): TDCURec;
end ;
TRecDef = class(TRecBaseDef)
B2: Byte;
constructor Create;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
function GetOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
end ;
TProcTypeDef = class(TRecBaseDef)
NDX0: TNDX;//B0: Byte; //Ver>2
hDTRes: TNDX;
AddStart: Pointer;
AddSz: Cardinal; //Ver>2
CallKind: TProcCallKind;
AddInfo: TDCURec; //for Ver>=verD2009
constructor Create;
destructor Destroy; override;
function IsProc: boolean;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
function ProcStr: AnsiString;
procedure ShowDecl(Braces: PAnsiChar; ForIntf: Boolean);
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TOOTypeDef = class(TRecBaseDef)
protected
function HasVMT: Boolean; virtual;
public
hParent: TNDX;
VMCnt: TNDX;//number of virtual methods
function GetMethodByVMTOfs(Ofs: Integer): TMethodDecl;
end ;
TObjDef = class(TOOTypeDef)
protected
function HasVMT: Boolean; override;
public
//hParent: TNDX;
//VMCnt: TNDX;
B03: Byte;
VMTOfs: TNDX;
hVMT: TNDX; //the TTypePDecl, which contains VMT
constructor Create;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
function GetParentType: TNDX; override;
function GetOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
end ;
TClassDef = class(TOOTypeDef)
protected
function GetObjFldByOfs(Ofs,QSz: integer; var ObjUnit: Pointer{TUnit}): TLocalDecl;
procedure MarkAuxFields;
public
// hParent: TNDX;
// VMCnt: TNDX;
// InstBase: TTypeDef;
InstBaseRTTISz: TNDX; //Size of RTTI for the type, if available
InstBaseSz: TNDX; //Size of corresponding variable
InstBaseV: TNDX; //hAddr of VMT
NdxFE: TNDX;//BFE: Byte
PropCnt: TNDX;//Ndx00a B00a: Byte
B04: TNDX;
//%$IF Ver>2;
ICnt: TNDX;
// DAdd: case @.B00b=0 of
{DAddB0: Byte;
DAddB1: Byte;}
ITbl: PNDXTbl;
// endc
//$END
constructor Create;
destructor Destroy; override;
function ShowValue(DP: Pointer; DS: Cardinal): integer {Size used}; override;
procedure Show; override;
function GetParentType: TNDX; override;
function GetRefOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
procedure ReadBeforeIntf; virtual;
end ;
TMetaClassDef = class(TClassDef)
hCl: TNDX;
procedure ReadBeforeIntf; override;
end ;
TInterfaceDef = class(TOOTypeDef)
// hParent: TNDX;
// VMCnt: TNDX;
GUID: PGUID;
B: Byte;
constructor Create;
procedure Show; override;
end ;
TVoidDef = class(TTypeDef)
constructor Create;
procedure Show; override;
end ;
TA6Def = class(TDCURec)
Args: TDCURec{TNameDecl};
constructor Create;
destructor Destroy; override;
procedure Show; override;
end ;
TA7Def = class(TDCURec)
hClass: TNDX;
Cnt: Integer;
Tbl: PNDXTbl;
constructor Create;
destructor Destroy; override;
procedure Show; override;
end ;
TDelayedImpRec = class(TNameDecl)
Inf: integer;
F: TNDX;
constructor Create;
procedure Show; override;
end ;
TORecDecl = class(TNameDecl)
DW: integer;
B0,B1: Byte;
Args: TDCURec{TNameDecl};
constructor Create;
destructor Destroy; override;
procedure Show; override;
end ;
TDynArrayDef = class(TPtrDef) //for Ver>=VerD12
procedure Show; override;
function GetRefOfsQualifierEx(Ofs,QSz: integer; QI: PQualInfo; QS: PAnsiString): Boolean; override;
end ;
TTemplateArgDef = class(TTypeDef) //for Ver>=VerD12 - template support
Cnt,V5: Integer;
Tbl: PNDXTbl;
constructor Create;
destructor Destroy; override;
procedure Show; override;
end ;
TTemplateCall = class(TTypeDef) //for Ver>=VerD12 - template support
hDT: TNDX;
Cnt: Integer;
Args: PNDXTbl;
hDTFull: TNDX;
//---
OldName: PName; //The Name of hDT as it was shown in DCU
FixedName: PName; //The fixed name of hDT - should be freed by this object
constructor Create;
destructor Destroy; override;
procedure Show; override;
procedure EnumUsedTypes(Action: TTypeUseAction; IP: Pointer); override;
procedure FixDTName;
end ;
{TStrConstTypeDef = class(TTypeDef)
hBase: TNDX;
constructor Create;
procedure Show; override;
end ;}
PulongTbl = ^TulongTbl;
TulongTbl = array[Word]of ulong;
TAssemblyData = class(TDCURec)
HdrSz: TNDX;
F: ulong;
SzPublicKey: ulong;
PublicKey: Pointer;
SzPublicKeyToken: ulong;
PublicKeyToken: Pointer;
Y: ulong;
AssemblyName: PAnsiChar;
SomeData: Pointer;
Descr: PShortName;
Cnt1: TNDX;
Tbl1: PulongTbl;
Tbl2: PulongTbl;
Cnt2: TNDX;
Tbl3,Tbl4,Tbl5: PulongTbl;
Cnt3: TNDX;
Tbl6: PulongTbl;
constructor Create;
destructor Destroy; override;
procedure Show; override;
function IsVisible(LK: TDeclListKind): boolean; override;
end;
const
NoName: String[1]='?';
type
TRegName = String[3];
PRegNameTbl = ^TRegNameTbl;
TRegNameTbl = array[byte]of TRegName;
const
{Register, where register variable is located,
I am not sure that it is valid for smaller than 4 bytes variables}
RegName: array[0..6] of TRegName =
('EAX','EDX','ECX','EBX','ESI','EDI','EBP');
RegName64: array[0..15] of TRegName =
('RAX','RCX','RDX','RBX','RSP','RBP','RSI','RDI',
'R8','R9','R10','R11','R12','R13','R14','R15');
procedure FreeDCURecList(L: TDCURec);
function GetDCURecListEnd(var L: TDCURec): PTDCURec;
function GetDCURecListItemByNum(L: TDCURec; Num: Integer): TDCURec;
procedure EnumUsedTypeList(L: TDCURec; Action: TTypeUseAction; IP: Pointer);
//for verD_XE - fix orphaned local types problem
implementation
uses
DCU32, op, TypInfo{GetEnumName}, DCUTbl{GetDCUOfMemory};
procedure FreeDCURecList(L: TDCURec);
var
Tmp: TDCURec;
begin
while L<>Nil do begin
Tmp := L;
L := L.Next;
Tmp.Free;
end ;
end ;
function GetDCURecListEnd(var L: TDCURec): PTDCURec;
begin
Result := @L;
while Result^<>Nil do
Result := @Result^.Next;
end ;
function GetDCURecListItemByNum(L: TDCURec; Num: Integer): TDCURec;
//For .Net fixups
begin
if Num<0 then begin
Result := Nil;
Exit;
end ;
while (Num>0)and(L<>Nil) do begin
Dec(Num);
L := L.Next;
end ;
Result := L;
end;
procedure EnumUsedTypeList(L: TDCURec; Action: TTypeUseAction; IP: Pointer);
begin
while L<>Nil do begin