-
Notifications
You must be signed in to change notification settings - Fork 20
/
TypeInfos.pas
1201 lines (1184 loc) · 38 KB
/
TypeInfos.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 TypeInfos;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Def_know,Def_main;
type
TFTypeInfo=class(TForm)
memDescription: TMemo;
Panel1: TPanel;
bSave: TButton;
procedure FormKeyDown(Sender : TObject; var Key:Word; Shift:TShiftState);
procedure bSaveClick(Sender : TObject);
private
{ Private declarations }
RTTIKind:LKind;
RTTIAdr:Integer;
RTTIName:AnsiString;
public
{ Public declarations }
Procedure ShowKbInfo(tInfo:MTypeInfo);
function GetRTTI(adr:Integer): AnsiString;
Procedure ShowRTTI(adr:Integer);
end;
var
FTypeInfo:TFTypeInfo;
implementation
{$R *.DFM}
uses Misc,Main,Def_info,Infos,TypInfo;
Procedure TFTypeInfo.ShowKbInfo (tInfo:MTypeInfo);
var
len:Word;
line:AnsiString;
p:PAnsiChar;
fInfo:FieldInfo;
mInfo:MethodInfo;
pInfo:PropInfo;
n:Integer;
Begin
memDescription.ReadOnly := True;
Panel1.Visible := False;
if tInfo.ModuleID <> $FFFF then
Caption := KBase.GetModuleName(tInfo.ModuleID) + '.';
Caption := Caption + tInfo.TypeName;
if tInfo.Size<>0 then
Caption := Caption + ' (size = ' + Val2Str(tInfo.Size) + ')';
memDescription.Clear;
if tInfo.Decl <> '' then memDescription.Lines.Add(tInfo.Decl);
if tInfo.FieldsNum<>0 then
begin
memDescription.Lines.Add('//FIELDS//');
p := tInfo.Fields;
for n := 1 to tInfo.FieldsNum do
begin
fInfo.Scope := Byte(p^);
Inc(p);
fInfo.Offset := PInteger(p)^;
Inc(p, 4);
fInfo._Case := PInteger(p)^;
Inc(p, 4);
Len := PWord(p)^;
Inc(p, 2);
fInfo.Name:=MakeString(p, Len);
Inc(p, Len + 1);
Len := PWord(p)^;
Inc(p, 2);
fInfo._Type := TrimTypeName(MakeString(p, Len));
Inc(p, Len + 1);
line := 'f' + Val2Str(fInfo.Offset) + ' ';
case fInfo.Scope of
FIELD_PRIVATE: line:=line + 'private';
FIELD_PROTECTED: line:=line + 'protected';
FIELD_PUBLIC: line:=line + 'public';
FIELD_PUBLISHED: line:=line + 'published';
end;
if fInfo._Case <> -1 then line:=line + ' case ' + IntToStr(fInfo._Case);
line:=line + ' ' + fInfo.Name + ':' + fInfo._Type;
memDescription.Lines.Add(line);
End;
End;
if tInfo.PropsNum<>0 then
begin
memDescription.Lines.Add('//PROPERTIES//');
p := tInfo.Props;
for n := 1 To tInfo.PropsNum do
begin
pInfo.Scope := Byte(p^);
Inc(p);
pInfo.Index := PInteger(p)^;
Inc(p, 4);
pInfo.DispID := PInteger(p)^;
Inc(p, 4);
Len := PWord(p)^;
Inc(p, 2);
pInfo.Name := MakeString(p, Len);
Inc(p, Len + 1);
Len := PWord(p)^;
Inc(p, 2);
pInfo.TypeDef := MakeString(p, Len);
Inc(p, Len + 1);
Len := PWord(p)^;
Inc(p, 2);
pInfo.ReadName := MakeString(p, Len);
Inc(p, Len + 1);
Len := PWORD(p)^;
Inc(p, 2);
pInfo.WriteName := MakeString(p, Len);
Inc(p, Len + 1);
Len := PWord(p)^;
Inc(p, 2);
pInfo.StoredName := MakeString(p, Len);
Inc(p, Len + 1);
line := '';
Case pInfo.Scope of
FIELD_PRIVATE: line:=line + 'private';
FIELD_PROTECTED: line:=line + 'protected';
FIELD_PUBLIC: line:=line + 'public';
FIELD_PUBLISHED: line:=line + 'published';
end;
line:=line + ' ' + pInfo.Name + ':' + pInfo.TypeDef
+ ' ' + pInfo.ReadName
+ ' ' + pInfo.WriteName
+ ' ' + pInfo.StoredName;
if pInfo.Index <> -1 then
Case (pInfo.Index and 6) of
2: line:=line + ' read';
4: line:=line + ' write';
end;
memDescription.Lines.Add(line);
End;
End;
if tInfo.MethodsNum<>0 then
begin
memDescription.Lines.Add('//METHODS//');
p := tInfo.Methods;
for n := 1 to tInfo.MethodsNum do
begin
mInfo.Scope := Byte(p^);
Inc(p);
mInfo.MethodKind := Byte(p^);
Inc(p);
Len := PWord(p)^;
Inc(p, 2);
mInfo.Prototype := MakeString(p, Len);
Inc(p, Len + 1);
line := '';
Case mInfo.Scope of
FIELD_PRIVATE: line:=line + 'private';
FIELD_PROTECTED: line:=line + 'protected';
FIELD_PUBLIC: line:=line + 'public';
FIELD_PUBLISHED: line:=line + 'published';
end;
line:=line + ' ' + mInfo.Prototype;
memDescription.Lines.Add(line);
end;
End;
if Assigned(tInfo.Dump) then
begin
memDescription.Lines.Add('//Dump//');
p := tInfo.Dump;
line := '';
for n := 0 to tInfo.DumpSz-1 do
begin
if n<>0 then line:=line + ' ';
line:=line + Val2Str(PByte(p)^,2);
Inc(p);
end;
memDescription.Lines.Add(line);
end;
ShowModal;
end;
Function GetVarTypeString(val:Integer):AnsiString;
Begin
Result:='';
Case val Of
0: Result:='Empty';
1: Result:='Null';
2: Result:='Smallint';
3: Result:='Integer';
4: Result:='Single';
5: Result:='Double';
6: Result:='Currency';
7: Result:='Date';
8: Result:='OleStr';
9: Result:='Dispatch';
10:Result:='Error';
11:Result:='Boolean';
12:Result:='Variant';
13:Result:='Unknown_0D';
14:Result:='Decimal';
15:Result:='Undef_0F';
16:Result:='ShortInt';
17:Result:='Byte';
18:Result:='Word';
19:Result:='LongWord';
20:Result:='Int64';
21:Result:='Word64';
$48:Result:='StrArg';
$100:Result:='String';
$101:Result:='Any';
$FFF:Result:='TypeMask';
$2000:Result:='Array';
$4000:Result:='ByRef';
End;
end;
Function TFTypeInfo.GetRTTI (adr:Integer):AnsiString;
var
found:Boolean;
paramFlags:TParamFlags;
_floatType, _methodKind, paramCount, numOps, ordType:Byte;
callConv, propFlags, flags, dimCount:Byte;
dw, propCount, methCnt:Word;
minValue, maxValue, minValueB, maxValueB:Integer;
i, m, n, vmtofs, _pos, posn, spos, _ap:Integer;
minInt64Value, maxInt64Value:Int64;
elSize, varType:Integer; //for tkDynArray
elType:Integer; //for tkDynArray
typeAdr, classVMT, parentAdr, Size, elNum, elOff, resultTypeAdr:Integer;
propType, getProc, setProc, storedProc, methAdr, procSig:Integer;
GUID:TGUID;
typname, _name, FldFileName:AnsiString;
stm:TFileStream;
proto:AnsiString;
recN:InfoRec;
len:Byte;
Begin
RTTIAdr := adr;
_ap := Adr2Pos(RTTIAdr);
_pos := _ap;
Inc(_pos, 4);
RTTIKind := LKind(Code[_pos]);
Inc(_pos);
len := Byte(Code[_pos]);
Inc(_pos);
RTTIName := MakeString(Code + _pos, len);
Inc(_pos, len);
Caption := RTTIName;
result := '';
Case RTTIKind of
ikInteger,
ikChar,
ikWChar:
begin
ordType := Byte(Code[_pos]);
Inc(_pos);
minValue := PInteger(Code + _pos)^;
Inc(_pos, 4);
maxValue := PInteger(Code + _pos)^;
if (ordType and 1)=0 then
//Signed type
result := IntToStr(minValue) + '..' + IntToStr(maxValue)
else
//Unsigned type
result := '$' + IntToHex(minValue, 0) + '..' + '$' + IntToHex(maxValue, 0);
end;
ikEnumeration:
begin
result := '(';
ordType := Byte(Code[_pos]);
Inc(_pos);
minValue := PInteger(Code + _pos)^;
Inc(_pos, 4);
maxValue := PInteger(Code + _pos)^;
Inc(_pos, 4);
//BaseTypeAdr
typeAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
if SameText(RTTIName, 'ByteBool') or
SameText(RTTIName, 'WordBool') or
SameText(RTTIName, 'LongBool') then
begin
minValue := 0;
maxValue := 1;
end;
//If BaseTypeAdr <> SelfAdr then fields extracted from BaseType
if typeAdr <> RTTIAdr then
begin
_pos := Adr2pos(typeAdr);
Inc(_pos, 4); //SelfPointer
Inc(_pos); //typeKind
len := Byte(Code[_pos]);
Inc(_pos);
Inc(_pos, len); //BaseClassName
Inc(_pos); //ordType
minValueB := PInteger(Code + _pos)^;
Inc(_pos, 4);
maxValueB := PInteger(Code + _pos)^;
Inc(_pos, 4);
Inc(_pos, 4); //BaseClassPtr
end
else
begin
minValueB := minValue;
maxValueB := maxValue;
end;
for i:= minValueB to maxValueB do
begin
len := Byte(Code[_pos]);
Inc(_pos);
if (i >= minValue) and (i <= maxValue) then
begin
_name := MakeString(Code + _pos, len);
if i <> minValue then result:=result + ', ';
result:=result + _name;
end;
Inc(_pos, len);
end;
result:=Result + ')';
//UnitName
len := Byte(Code[_pos]);
if IsValidName(len, _pos + 1) then
begin
Inc(_pos);
Caption := Trim(MakeString(Code + _pos, len)) + '.' + Caption;
End;
end;
ikFloat:
if SameText(RTTIName, 'Single') or
SameText(RTTIName, 'Double') or
SameText(RTTIName, 'Extended') or
SameText(RTTIName, 'Comp') or
SameText(RTTIName, 'Currency') then
result := RTTIName //'float'
else
begin
_floatType := Byte(Code[_pos]);
Inc(_pos);
result := 'type ';
case TFloatType(_floatType) of
FtSingle: result:=result + 'Single';
FtDouble: result:=result + 'Double';
FtExtended: result:=result + 'Extended';
FtComp: result:=result + 'Comp';
FtCurr: result:=result + 'Currency';
end;
End;
ikString: result := 'String';
ikSet:
begin
//result := 'set of ';
Inc(_pos); //skip ordType
typeAdr := PInteger(Code + _pos)^;
result := 'set of ' + GetTypeName(typeAdr);
end;
ikClass:
begin
result := 'class';
classVMT := PInteger(Code + _pos)^;
Inc(_pos,4);
parentAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
if parentAdr<>0 then result:=result + '(' + GetTypeName(parentAdr) + ')';
propCount := PWord(Code + _pos)^;
Inc(_pos, 2);
//UnitName
len := Byte(Code[_pos]);
Inc(_pos);
Caption := Trim(MakeString(Code + _pos, len)) + '.' + Caption;
Inc(_pos, len);
propCount := PWord(Code + _pos)^;
Inc(_pos, 2);
for i := 1 to propCount do
begin
propType := PInteger(Code + _pos)^;
Inc(_pos,4);
posn := Adr2pos(propType);
Inc(posn, 4);
Inc(posn); //property type
len := Byte(Code[posn]);
Inc(posn);
typname := MakeString(Code + posn, len);
getProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
setProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
storedProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
//idx
Inc(_pos,4);
//defval
Inc(_pos, 4);
//nameIdx
Inc(_pos, 2);
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
result:=result + #13 + _name + ':' + typname;
if (getProc and $FFFFFF00)<>0 then
begin
result:=result + #13+' read ';
if (getProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(getProc and $00FFFFFF)
else if (getProc and $FF000000) = $FE000000 then
begin
if (getProc and $00008000)<>0 then
vmtofs := -(getProc and $0000FFFF)
else
vmtofs := (getProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
getProc := PInteger(Code + posn)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(getProc);
recN := GetInfoRec(getProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(getProc);
recN := GetInfoRec(getProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
End;
end;
if (setProc and $FFFFFF00)<>0 then
begin
result:=result + #13+ ' write ';
if (setProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(setProc and $00FFFFFF)
else if (setProc and $FF000000) = $FE000000 then
begin
if (setProc and $00008000)<>0 then
vmtofs := -(setProc and $0000FFFF)
else
vmtofs := (setProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
setProc := PInteger(Code + posn)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(setProc);
recN := GetInfoRec(setProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(setProc);
recN := GetInfoRec(setProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
End;
end;
if (storedProc and $FFFFFF00)<>0 then
begin
result:=result + #13+ ' stored ';
if (storedProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(storedProc and $00FFFFFF)
else if (storedProc and $FF000000) = $FE000000 then
begin
if (storedProc and $00008000)<>0 then
vmtofs := -(storedProc and $0000FFFF)
else
vmtofs := (storedProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
storedProc := PInteger(Code + posn)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(storedProc);
recN := GetInfoRec(storedProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(storedProc);
recN := GetInfoRec(storedProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
End;
end;
end;
if DelphiVersion >= 2010 then
begin
propCount := PWord(Code + _pos)^;
Inc(_pos, 2);
for i :=1 to propCount do
begin
//Flags
propFlags := Byte(Code[_pos]);
Inc(_pos);
//PPropInfo
propType := PInteger(Code + _pos)^;
Inc(_pos, 4);
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
spos := _pos;
//PropInfo
_pos := Adr2pos(propType);
propType := PInteger(Code + _pos)^;
Inc(_pos,4);
if IsFlagSet([cfImport], Adr2pos(propType)) then
begin
recN := GetInfoRec(propType);
typname := recN.Name;
end
else
begin
posn := Adr2pos(propType);
Inc(posn, 4);
Inc(posn); //property type
len := Byte(Code[posn]);
Inc(posn);
typname := MakeString(Code + posn, len);
end;
getProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
setProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
storedProc := PInteger(Code + _pos)^;
Inc(_pos, 4);
//idx
Inc(_pos, 4);
//defval
Inc(_pos, 4);
//nameIdx
Inc(_pos, 2);
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
result:=result + #13+ _name + ':' + typname;
if (getProc and $FFFFFF00)<>0 then
begin
result:=result + #13+' read ';
if (getProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(getProc and $00FFFFFF)
else if (getProc and $FF000000) = $FE000000 then
begin
if (getProc and $00008000)<>0 then
vmtofs := -(getProc and $0000FFFF)
else
vmtofs := (getProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
getProc := PInteger(Code + _pos)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(getProc);
recN := GetInfoRec(getProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(getProc);
recN := GetInfoRec(getProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end;
End;
if (setProc and $FFFFFF00)<>0 then
begin
result:=result +#13+ ' write ';
if (setProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(setProc and $00FFFFFF)
else if (setProc and $FF000000) = $FE000000 then
begin
if (setProc and $00008000)<>0 then
vmtofs := -(setProc and $0000FFFF)
else
vmtofs := (setProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
setProc := PInteger(Code + _pos)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(setProc);
recN := GetInfoRec(setProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(setProc);
recN := GetInfoRec(setProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end;
end;
if (storedProc and $FFFFFF00)<>0 then
begin
result:=result +#13+ ' stored ';
if (storedProc and $FF000000) = $FF000000 then
result:=result + _name + ' f' + Val2Str(storedProc and $00FFFFFF)
else if (storedProc and $FF000000) = $FE000000 then
begin
if (storedProc and $00008000)<>0 then
vmtofs := -(storedProc and $0000FFFF)
else
vmtofs := (storedProc and $0000FFFF);
posn := Adr2pos(classVMT) + vmtofs;
storedProc := PInteger(Code + _pos)^;
result:=result + ' vmt' + Val2Str(vmtofs) + ' ' + Val2Str(storedProc);
recN := GetInfoRec(storedProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end
else
begin
result:=result + Val2Str(storedProc);
recN := GetInfoRec(storedProc);
if Assigned(recN) and recN.HasName then result:=result + ' ' + recN.Name;
end;
end;
_pos := spos;
End;
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
if DelphiVersion >= 2012 then
begin
//ArrayPropCount
propCount := PWord(Code + _pos)^;
Inc(_pos, 2);
for i := 1 to propCount do
begin
//Flags
Inc(_pos);
//ReadIndex
Inc(_pos, 2);
//WriteIndex
Inc(_pos, 2);
//Name
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
result:=result +#13+ _name;
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
end;
End;
End;
end;
ikMethod:
begin
_methodKind := Byte(Code[_pos]);
Inc(_pos);
case TMethodKind(_methodKind) of
MkProcedure: result := 'procedure';
MkFunction: result := 'function';
MkConstructor: result := 'constructor';
MkDestructor: result := 'destructor';
MkClassProcedure: result := 'class procedure';
MkClassFunction: result := 'class function';
mkSafeProcedure:
if DelphiVersion < 2009 then result := 'safeprocedure'
else result := 'class constructor';
mkSafeFunction:
if DelphiVersion < 2009 then result := 'safefunction'
else result := 'operator overload';
end;
paramCount := Byte(Code[_pos]);
Inc(_pos);
if paramCount > 0 then proto := '(';
for i:=1 to paramCount do
begin
paramFlags := TParamFlags(Code[_pos]);
Inc(_pos);
if pfVar in paramFlags then proto:=proto + 'var '
else if pfConst in paramFlags then proto:=proto + 'const '
else if pfArray in paramFlags then proto:=proto + 'array ';
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
proto:=proto + _name + ':';
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
proto:=proto + _name;
if i <> paramCount then proto:=proto + '; ';
End;
if paramCount > 0 then proto:=proto + ')';
if _methodKind<>0 then
begin
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
if DelphiVersion > 6 then
begin
typeAdr := PInteger(Code + _pos)^;
Inc(_pos,4);
_name := GetTypeName(typeAdr);
end;
proto:=proto + ':' + _name;
End;
if DelphiVersion > 6 then
begin
//CC
callConv := Byte(Code[_pos]);
Inc(_pos);
//ParamTypeRefs
Inc(_pos, 4*paramCount);
if DelphiVersion >= 2010 then
begin
//MethSig
procSig := PInteger(Code + _pos)^;
Inc(_pos,4);
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
//Procedure Signature
if procSig<>0 then
begin
if IsValidImageAdr(procSig) then
posn := Adr2pos(procSig)
else
posn := _ap + procSig;
//Flags
flags := Byte(Code[posn]);
Inc(posn);
if flags <> 255 then
begin
//CC
callConv := Byte(Code[posn]);
Inc(posn);
//ResultType
resultTypeAdr := PInteger(Code + posn)^;
Inc(posn, 4);
//ParamCount
paramCount := Byte(Code[posn]);
Inc(posn);
if paramCount > 0 then proto := '(';
for i:=1 To paramCount do
begin
paramFlags := TParamFlags(Code[posn]);
Inc(posn);
if pfVar in paramFlags then proto:=proto + 'var '
else if pfConst in paramFlags then proto:=proto + 'const '
else if pfArray in paramFlags then proto:=proto + 'array ';
typeAdr := PInteger(Code + posn)^;
Inc(posn,4);
len := Byte(Code[posn]);
Inc(posn);
_name := MakeString(Code + posn, len);
Inc(posn, len);
proto:=proto + _name + ':' + GetTypeName(typeAdr);
if i <> paramCount then proto:=proto + '; ';
//AttrData
dw := PWord(Code + posn)^;
Inc(posn, dw);//ATR!!
end;
if paramCount > 0 then proto:=proto + ')';
if resultTypeAdr<>0 then proto:=proto + ':' + GetTypeName(resultTypeAdr);
end;
end;
end;
end;
result:=result + proto + ' of object;';
End;
ikLString: result := 'String';
ikWString: result := 'WideString';
ikVariant: result := 'Variant';
ikArray:
begin
Size := PInteger(Code + _pos)^;
Inc(_pos,4);
elNum := PInteger(Code + _pos)^;
Inc(_pos,4);
resultTypeAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
result := 'array [1..' + IntToStr(elNum);
if DelphiVersion >= 2010 then
begin
result := 'array [';
//DimCount
dimCount := Byte(Code[_pos]);
Inc(_pos);
for i:= 1 to dimCount do
begin
typeAdr := PInteger(Code + _pos)^;
Inc(_pos,4);
if IsValidImageAdr(typeAdr) then result:=result + GetTypeName(typeAdr)
else
begin
if typeAdr=0 then
begin
if dimCount = 1 then result:=result + '1..' + IntToStr(elNum)
else result:=result + '1..?';
end
else result:=result + '1..' + IntToStr(typeAdr);
end;
if i <> dimCount Then result:=result + ',';
end;
end;
result:=result + '] of ' + GetTypeName(resultTypeAdr);
end;
ikRecord:
begin
Size := PInteger(Code + _pos)^;
Inc(_pos,4);
result := RTTIName + ' = record // size=' + Val2Str(Size);
elNum := PInteger(Code + _pos)^;
Inc(_pos,4); //FldCount
if elNum<>0 then
begin
for i:= 1 to elNum do
begin
typeAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
elOff := PInteger(Code + _pos)^;
Inc(_pos, 4);
result:=result +#13+ 'f' + Val2Str(elOff) + ':' + GetTypeName(typeAdr) + '; //f' + Val2Str(elOff);
End;
result:=result +#13+ 'end;';
End;
if DelphiVersion >= 2010 then
begin
//NumOps
numOps := Byte(Code[_pos]);
Inc(_pos);
for i := 1 to numOps do //RecOps
Inc(_pos, 4);
elNum := PInteger(Code + _pos)^;
Inc(_pos,4); //RecFldCnt
if elNum<>0 then
begin
for i := 1 to elNum do
begin
//TypeRef
typeAdr := PInteger(Code + _pos)^;
Inc(_pos,4);
//FldOffset
elOff := PInteger(Code + _pos)^;
Inc(_pos,4);
//Flags
Inc(_pos);
//Name
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos,len);
result:=result +#13+ _name + ':' + GetTypeName(typeAdr) + '; //f' + Val2Str(elOff);
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos,dw);//ATR!!
End;
result:=result +#13+ 'end;';
End;
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
if DelphiVersion >= 2012 then
begin
methCnt := PWord(Code + _pos)^;
Inc(_pos, 2);
if methCnt > 0 then result:=result +#13+ '//Methods:';
for m := 1 to methCnt do
begin
//Flags
Inc(_pos);
//Code
methAdr := PInteger(Code + _pos)^;
Inc(_pos,4);
//Name
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos,len);
result:=result + #13+ _name;
//ProcedureSignature
//Flags
flags := Byte(Code[_pos]);
Inc(_pos);
if flags <> 255 then
begin
//CC
Inc(_pos);
//ResultType
resultTypeAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
//ParamCnt
paramCount := Byte(Code[_pos]);
Inc(_pos);
if paramCount > 0 then result:=result + '(';
//Params
for n := 1 to paramCount do
begin
//Flags
Inc(_pos);
//ParamType
typeAdr := PInteger(Code + _pos)^;
Inc(_pos,4);
//Name
len := Byte(Code[_pos]);
Inc(_pos);
_name := MakeString(Code + _pos, len);
Inc(_pos, len);
result:=result + _name + ':' + GetTypeName(typeAdr);
if n <> paramCount then result:=result + ';';
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos,dw);//ATR!!
End;
if paramCount > 0 then result:=result + ')';
if resultTypeAdr<>0 Then result:=result + ':' + GetTypeName(resultTypeAdr);
result:=result + '; //' + Val2Str(methAdr,8);
End;
//AttrData
dw := PWord(Code + _pos)^;
Inc(_pos, dw);//ATR!!
End;
End;
end;
end;
ikInterface:
begin
result := 'interface';
//IntfParent
typeAdr := PInteger(Code + _pos)^;
Inc(_pos, 4);
if typeAdr<>0 then result:=result + '(' + GetTypeName(typeAdr) + ')';
//IntfFlags
Inc(_pos);
//GUID
MoveMemory(@GUID, @Code[_pos], SizeOf(TGUID));
Inc(_pos,16);
result:=result + '['''+GuidToString(GUID)+''']' + #13;
//UnitName
len := Byte(Code[_pos]);
Inc(_pos);
Caption := Trim(MakeString(Code + _pos, len)) + '.' + Caption;
Inc(_pos, len);
//Methods
propCount := PWord(Code + _pos)^;
Inc(_pos, 2);
result:=result + 'Methods Count = ' + IntToStr(propCount);
if DelphiVersion >= 6 then
begin
//RttiCount
dw := PWord(Code + _pos)^;
Inc(_pos, 2);
if dw <> $FFFF then
begin
if DelphiVersion >= 2010 then
begin
for i := 1 to propCount do
begin
//Name
len := Byte(Code[_pos]);
Inc(_pos);
result:=result + #13 + MakeString(Code + _pos, len);
Inc(_pos, len);
//Kind
_methodKind := Byte(Code[_pos]);
Inc(_pos);
//CallConv
Inc(_pos);
//ParamCount
paramCount := Byte(Code[_pos]);
Inc(_pos);
if paramCount<>0 then result:=result + '(';
for m := 1 to paramCount do
begin
if m<>1 then result:=result + ';';
//Flags
Inc(_pos);
//ParamName
len := Byte(Code[_pos]);
Inc(_pos);
result:=result + MakeString(Code + _pos, len);
Inc(_pos, len);
//TypeName
len := Byte(Code[_pos]);
Inc(_pos);
result:=result + ':' + MakeString(Code + _pos, len);
Inc(_pos, len);
//ParamType
Inc(_pos, 4);
End;
if paramCount<>0 then result:=result + ')';
if _methodKind<>0 then
begin
result:=result + ':';
//ResultTypeName
len := Byte(Code[_pos]);
Inc(_pos);
result:=result + MakeString(Code + _pos, len);
Inc(_pos, len);
if len<>0 then
begin
//ResultType
Inc(_pos, 4);
End;
End;
End;
end
else for i := 1 to propCount do
begin
//PropType
Inc(_pos, 4);
//GetProc
Inc(_pos, 4);
//SetProc
Inc(_pos, 4);
//StoredProc
Inc(_pos, 4);
//Index
Inc(_pos, 4);
//Default
Inc(_pos, 4);
//NameIndex
Inc(_pos, 2);
//Name
len := Byte(Code[_pos]);