-
Notifications
You must be signed in to change notification settings - Fork 20
/
IDCGen.pas
1546 lines (1476 loc) · 37.3 KB
/
IDCGen.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 IDCGen;
Interface
Uses Windows,Messages,Classes,Def_main,Infos,Dialogs;
Type
TIDCGen = class
public
idcF:TFileStream;
unitName:AnsiString;
itemName:AnsiString;
names:TStringList;
repeated:TList;
SplitSize:Integer; // Maximum output bytes if IDC splitted
CurrentPartNo:Integer; // current part number (filename looks like XXX_NN.idc)
CurrentBytes:Integer; // current part output bytes
constructor Create(f:TFileStream;AsplitSize:Integer);
Destructor Destroy; Override;
procedure NewIDCPart(f:TFileStream);
Procedure DeleteName(_pos:Integer);
Function MakeByte(_pos:Integer):Integer;
Function MakeWord(_pos:Integer):Integer;
Function MakeDword(_pos:Integer):Integer;
Function MakeQword(_pos:Integer):Integer;
Function MakeArray(_pos:Integer; num:Integer):Integer;
Function MakeShortString(_pos:Integer):Integer;
Function MakeCString(_pos:Integer):Integer;
Procedure MakeLString(_pos:Integer);
Procedure MakeWString(_pos:Integer);
Procedure MakeUString(_pos:Integer);
Function MakeCode(_pos:Integer):Integer;
Procedure MakeFunction(adr:Integer);
Procedure MakeComment(_pos:Integer; text:AnsiString);
Function OutputAttrData(_pos:Integer):Integer;
Procedure OutputHeaderFull;
Procedure OutputHeaderShort;
Function OutputRTTIHeader(kind:LKind; _pos:Integer):Integer;
Procedure OutputRTTIInteger(kind:LKind; _pos:Integer);
Procedure OutputRTTIChar(kind:LKind; _pos:Integer);
Procedure OutputRTTIEnumeration(kind:LKind; _pos:Integer; adr:Integer);
Procedure OutputRTTIFloat(kind:LKind; _pos:Integer);
Procedure OutputRTTIString(kind:LKind; _pos:Integer);
Procedure OutputRTTISet(kind:LKind; _pos:Integer);
Procedure OutputRTTIClass(kind:LKind; _pos:Integer);
Procedure OutputRTTIMethod(kind:LKind; _pos:Integer);
Procedure OutputRTTIWChar(kind:LKind; _pos:Integer);
Procedure OutputRTTILString(kind:LKind; _pos:Integer);
Procedure OutputRTTIWString(kind:LKind; _pos:Integer);
Procedure OutputRTTIVariant(kind:LKind; _pos:Integer);
Procedure OutputRTTIArray(kind:LKind; _pos:Integer);
procedure OutputRTTIRecord(kind:LKind; _pos:Integer);
procedure OutputRTTIInterface(kind:LKind; _pos:Integer);
procedure OutputRTTIInt64(kind:LKind; _pos:Integer);
procedure OutputRTTIDynArray(kind:LKind; _pos:Integer);
procedure OutputRTTIUString(kind:LKind; _pos:Integer);
procedure OutputRTTIClassRef(kind:LKind; _pos:Integer);
procedure OutputRTTIPointer(kind:LKind; _pos:Integer);
procedure OutputRTTIProcedure(kind:LKind; _pos:Integer);
procedure OutputVMT(_pos:Integer; recN:InfoRec);
Function OutputVMTHeader(_pos:Integer; vmtName:AnsiString):Integer;
procedure OutputIntfTable(_pos:Integer);
procedure OutputIntfVTable(_pos:Integer; stopAdr:Integer);
procedure OutputAutoTable(_pos:Integer);
procedure OutputAutoPTable(_pos:Integer);
procedure OutputInitTable(_pos:Integer);
procedure OutputFieldTable(_pos:Integer);
procedure OutputFieldTTable(_pos:Integer);
procedure OutputMethodTable(_pos:Integer);
procedure OutputVmtMethodEntry(_pos:Integer);
Function OutputVmtMethodEntryTail(_pos:Integer):Integer;
procedure OutputDynamicTable(_pos:Integer);
procedure OutputResString(_pos:Integer; recN:InfoRec);
Function OutputProc(_pos:Integer; recN:InfoRec; imp:Boolean):Integer;
procedure OutputData(_pos:Integer; recN:InfoRec);
Function GetNameInfo(idx:Integer):PRepNameInfo;
end;
TSaveIDCDialog = class(TOpenDialog)
Constructor Create(AOwner:TComponent);
procedure WndProc(var Msg:TMessage); Override;
end;
Implementation
Uses Misc,SysUtils,Main,Def_disasm;
Const
chkSplit_ID = 101;
constructor TIDCGen.Create(f:TFileStream;AsplitSize:Integer);
Begin
idcF:=f;
names:=TStringList.Create;
repeated:=TList.Create;
splitSize:=AsplitSize;
CurrentPartNo:=1;
CurrentBytes:=0;
end;
Destructor TIDCGen.Destroy;
Begin
names.Free;
repeated.Free;
inherited;
end;
procedure TIDCGen.NewIDCPart(f:TFileStream);
Begin
idcF:=f;
CurrentBytes:=0;
Inc(CurrentPartNo);
end;
Procedure TIDCGen.DeleteName (_pos:Integer);
var
adr:Integer;
s:AnsiString;
Begin
adr := Pos2Adr(_pos);
s:=Format('MakeUnkn(0x%x, 1);'+#13+'MakeNameEx(0x%x, "", 0);'+#13,[adr,adr]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
end;
Function TIDCGen.MakeByte (_pos:Integer):Integer;
var
s:AnsiString;
Begin
s:=Format('MakeByte(0x%x);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + 1;
end;
Function TIDCGen.MakeWord (_pos:Integer):Integer;
var
s:AnsiString;
Begin
s:=Format('MakeWord(0x%x);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + 2;
end;
Function TIDCGen.MakeDword (_pos:Integer):Integer;
var
s:AnsiString;
Begin
s:=Format('MakeDword(0x%x);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + 4;
end;
Function TIDCGen.MakeQword (_pos:Integer):Integer;
var
s:AnsiString;
Begin
s:=Format('MakeQword(0x%x);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + 8;
end;
Function TIDCGen.MakeArray (_pos:Integer; num:Integer):Integer;
Var
s:AnsiString;
adr:Integer;
Begin
adr:=Pos2Adr(_pos);
s:=Format('MakeByte(0x%x);'+#13+'MakeArray(0x%x, %d);'+#13,[adr,adr,num]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + num;
end;
Function TIDCGen.MakeShortString (_pos:Integer):Integer;
var
adr:Integer;
s:AnsiString;
len:Byte;
Begin
len := Byte(Code[_pos]);
//Empty String
if len=0 then Result:=_pos + 1
Else if Not IsValidName(len, _pos + 1) Then Result:=_pos
Else
begin
adr:=Pos2Adr(_pos);
s:=Format('SetLongPrm(INF_STRTYPE, ASCSTR_PASCAL);'+#13+'MakeStr(0x%x, 0x%x);'+#13,[adr,adr+len+1]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + len + 1;
End;
end;
Function TIDCGen.MakeCString (_pos:Integer):Integer;
var
len:Integer;
s:AnsiString;
adr:Integer;
Begin
adr:=Pos2Adr(_pos);
len:=StrLen(Code + _pos);
s:=Format('SetLongPrm(INF_STRTYPE, ASCSTR_TERMCHR);'+#13+'MakeStr(0x%x, 0x%x);'+#13,[adr,adr+len+1]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result:=_pos + len + 1;
end;
Procedure TIDCGen.MakeLString (_pos:Integer);
var
s:AnsiString;
Begin
s:=Format('SetLongPrm(INF_STRTYPE, ASCSTR_TERMCHR);'+#13+'MakeStr(0x%x, -1);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
//Length
MakeDword(_pos - 4);
//RefCount
MakeDword(_pos - 8);
end;
Procedure TIDCGen.MakeWString (_pos:Integer);
var
s:AnsiString;
Begin
s:=Format('SetLongPrm(INF_STRTYPE, ASCSTR_UNICODE);'+#13+'MakeStr(0x%x, -1);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
//Length
MakeDword(_pos - 4);
end;
Procedure TIDCGen.MakeUString (_pos:Integer);
var
s:AnsiString;
Begin
s:=Format('SetLongPrm(INF_STRTYPE, ASCSTR_UNICODE);'+#13+'MakeStr(0x%x, -1);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
//Length
MakeDword(_pos - 4);
//RefCount
MakeDword(_pos - 8);
//Word
MakeWord(_pos - 10);
//CodePage
MakeWord(_pos - 12);
end;
Function TIDCGen.MakeCode (_pos:Integer):Integer;
var
s:AnsiString;
Begin
s:=Format('MakeCode(0x%x);'+#13,[Pos2Adr(_pos)]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
Result := frmDisasm.Disassemble(Code + _pos, Pos2Adr(_pos),Nil, Nil);
if Result=0 then Result := 1;
end;
Procedure TIDCGen.MakeFunction (adr:Integer);
var
s:AnsiString;
Begin
If adr<>0 then
Begin
s:=Format('MakeFunction(0x%x, -1);'+#13,[adr]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
MakeCode(Adr2Pos(adr));
end;
end;
Procedure TIDCGen.MakeComment (_pos:Integer; text:AnsiString);
Var
s:AnsiString;
Begin
s:=Format('MakeComm(0x%x, "%s");'+#13,[Pos2Adr(_pos), text]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
end;
Function TIDCGen.OutputAttrData (_pos:Integer):Integer;
var
dw:Word;
Begin
dw:=PWord(Code + _pos)^;
_pos:=MakeWord(_pos);
Result:=_pos;
end;
Procedure TIDCGen.OutputHeaderFull;
var
s:AnsiString;
Begin
s:=Format('#include <idc.idc>'+#13
+'static clear(from){'+#13
+'auto ea;'+#13
+'ea = from;'+#13
+'while (1){'+#13
+'ea = NextFunction(ea);'+#13
+'if (ea == -1) break;'+#13
+'DelFunction(ea);'+#13
+'MakeNameEx(ea, "", 0);}'+#13
+'ea = from;'+#13
+'while (1){'+#13
+'ea = FindExplored(ea, SEARCH_DOWN | SEARCH_NEXT);'+#13
+'if (ea == -1) break;'+#13
+'MakeUnkn(ea, 1);}'+#13
+'}'+#13
+'static main(){'+#13
+'clear(0x%lX);'
,[CodeBase]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
end;
procedure TIDCGen.OutputHeaderShort;
var
s:AnsiString;
Begin
s:='#include <idc.idc>'+#13+'static main(){'+#13;
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
end;
function TIDCGen.OutputRTTIHeader(kind:LKind; _pos:Integer): Integer;
var
s:AnsiString;
from,adr:Integer;
len:Byte;
Begin
from:=_pos;
len := Byte(Code[_pos + 5]);
SetLength(itemName,len);
StrLCopy(PAnsiChar(itemName),Code + _pos + 6, len);
adr := Pos2Adr(_pos);
s:=Format('MakeUnkn(0x%x, 1);'+#13+'MakeNameEx(0x%x, "RTTI_%x_%s_%s", 0);',[adr,adr,adr,TypeKind2Name(kind),itemName]);
idcF.Write(s[1],Length(s));
Inc(CurrentBytes,Length(s));
//Selfptr
_pos := MakeDword(_pos);
//Kind
//Delete name (often presents)
DeleteName(_pos);
_pos := MakeByte(_pos);
//Name
_pos := MakeShortString(_pos);
result:= _pos - from;
end;
procedure TIDCGen.OutputRTTIInteger(kind:LKind; _pos:Integer);
Begin
_pos:=_pos+OutputRTTIHeader(kind,_pos);
//ordType
_pos := MakeByte(_pos);
//minValue
_pos := MakeDword(_pos);
//maxValue
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIChar(kind:LKind; _pos:Integer);
Begin
_pos :=_pos + OutputRTTIHeader(kind, _pos);
//ordType
_pos := MakeByte(_pos);
//minValue
_pos := MakeDword(_pos);
//maxValue
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIEnumeration(kind:LKind; _pos:Integer; adr:Integer);
var
n,minValue,maxValue,baseTypeAdr:Integer;
Begin
_pos :=_pos+ OutputRTTIHeader(kind, _pos);
//ordType
_pos := MakeByte(_pos);
//minValue
minValue := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
//maxValue
maxValue := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
//baseTypeAdr
baseTypeAdr := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
if baseTypeAdr = adr then
begin
if SameText(itemName, 'ByteBool') or
SameText(itemName, 'WordBool') or
SameText(itemName, 'LongBool') then
begin
minValue := 0;
maxValue := 1;
End;
for n := minValue to maxValue do
_pos := MakeShortString(_pos);
End;
//UnitName
//_pos := MakeShortString(_pos);
//if DelphiVersion = 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIFloat(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//FloatType
_pos := MakeByte(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIString(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//MaxLength
_pos := MakeByte(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTISet(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//OrdType
_pos := MakeByte(_pos);
//CompType
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIClass(kind:LKind; _pos:Integer);
var
count:Word;
n,m,TypeInfo:Integer;
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//classVMT
_pos := MakeDword(_pos);
//ParentInfo
_pos := MakeDword(_pos);
//PropCount
_pos := MakeWord(_pos);
//UnitName
_pos := MakeShortString(_pos);
//PropData
Count := PWord(Code + _pos)^;
_pos := MakeWord(_pos);
for n := 1 to Count do
begin
//TPropInfo
for m := 0 to 5 do _pos := MakeDword(_pos);
_pos := MakeWord(_pos);
_pos := MakeShortString(_pos);
end;
if DelphiVersion >= 2010 then
begin
//PropDataEx
Count := PWord(Code + _pos)^;
_pos := MakeWord(_pos);
for n := 1 To count do
begin
//Flags
_pos := MakeByte(_pos);
//Info
typeInfo := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
for m := 0 to 5 do
begin
MakeDword(Adr2pos(typeInfo));
Inc(typeInfo, 4);
end;
MakeWord(Adr2pos(typeInfo));
Inc(typeInfo, 2);
MakeShortString(Adr2pos(typeInfo));
//AttrData
_pos := OutputAttrData(_pos);
End;
//AttrData
OutputAttrData(_pos);
End;
end;
procedure TIDCGen.OutputRTTIMethod(kind:LKind; _pos:Integer);
Var
pos1,pos2:Integer;
MethodKind,ParamCnt,flags:Byte;
n,procSig:Integer;
Begin
pos1:=_pos;
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//MethodKind
methodKind := Byte(Code[_pos]);
_pos := MakeByte(_pos);
//ParamCnt
paramCnt := Byte(Code[_pos]);
_pos := MakeByte(_pos);
for n := 1 to paramCnt do
begin
//Flags
_pos := MakeByte(_pos);
//ParamName
_pos := MakeShortString(_pos);
//TypeName
_pos := MakeShortString(_pos);
end;
if methodKind<>0 then
begin
//ResultType
_pos := MakeShortString(_pos);
if DelphiVersion > 6 then
begin
//ResultTypeRef
_pos := MakeDword(_pos);
End;
end;
if DelphiVersion > 6 then
begin
//CC (TCallConv)
_pos := MakeByte(_pos);
//ParamTypeRefs
for n := 1 to paramCnt do
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then
begin
procSig := PInteger(Code + _pos)^;
//MethSig
_pos := MakeDword(_pos);
//AttrData
OutputAttrData(_pos);
//Procedure Signature
if procSig<>0 then
begin
if IsValidImageAdr(procSig) then pos2 := Adr2Pos(procSig)
else pos2 := pos1 + procSig;
//Flags
flags := Byte(Code[pos2]);
pos2 := MakeByte(pos2);
if flags <> 255 then
begin
//CC
pos2 := MakeByte(pos2);
//ResultType
pos2 := MakeDword(pos2);
//ParamCount
paramCnt := Byte(Code[pos2]);
pos2 := MakeByte(pos2);
for n := 1 to paramCnt do
begin
//Flags
pos2 := MakeByte(pos2);
//ParamType
pos2 := MakeDword(pos2);
//Name
pos2 := MakeShortString(pos2);
//AttrData
pos2 := OutputAttrData(pos2);
End;
end;
end;
end;
End;
end;
procedure TIDCGen.OutputRTTIWChar(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//ordType
_pos := MakeByte(_pos);
//minValue
_pos := MakeDword(_pos);
//maxValue
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTILString(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
if DelphiVersion >= 2009 then
begin
//CodePage
_pos := MakeWord(_pos);
End;
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIWString(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIVariant(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIArray(kind:LKind; _pos:Integer);
var
dim,n:Integer;
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//Size
_pos := MakeDword(_pos);
//ElCount
_pos := MakeDword(_pos);
//ElType
_pos := MakeDword(_pos);
if DelphiVersion >= 2010 then
begin
//DimCount
dim := Byte(Code[_pos]);
_pos := MakeByte(_pos);
for n := 1 to dim do
begin
//Dims
_pos := MakeDword(_pos);
End;
//AttrData
OutputAttrData(_pos);
End;
end;
procedure TIDCGen.OutputRTTIRecord(kind:LKind; _pos:Integer);
Var
n, m, elNum:Integer;
metCnt:Word;
numOp,flags,paramCnt:Byte;
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//Size
_pos := MakeDword(_pos);
//ManagedFldCount
elNum := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
for n := 1 to elNum do
begin
//TypeRef
_pos := MakeDword(_pos);
//FldOffset
_pos := MakeDword(_pos);
End;
if DelphiVersion >= 2010 then
begin
//NumOps
numOp := Byte(Code[_pos]);
_pos := MakeByte(_pos);
for n := 1 to numOp do //RecOps
_pos := MakeDword(_pos);
//RecFldCnt
elNum := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
for n := 1 to elNum do
begin
//TypeRef
_pos := MakeDword(_pos);
//FldOffset
_pos := MakeDword(_pos);
//Flags
_pos := MakeByte(_pos);
//Name
_pos := MakeShortString(_pos);
//AttrData
_pos := OutputAttrData(_pos);
End;
//AttrData
_pos := OutputAttrData(_pos);
if DelphiVersion >= 2012 then
begin
metCnt := PWord(Code + _pos)^;
_pos := MakeWord(_pos);
for n := 1 to metCnt do
begin
//Flags
_pos := MakeByte(_pos);
//Code
_pos := MakeDword(_pos);
//Name
_pos := MakeShortString(_pos);
//ProcedureSignature
//Flags
flags := Byte(Code[_pos]);
_pos := MakeByte(_pos);
if flags <> 255 then
begin
//CC
_pos := MakeByte(_pos);
//ResultType
_pos := MakeDword(_pos);
paramCnt := Byte(Code[_pos]);
_pos := MakeByte(_pos);
//Params
for m := 1 to paramCnt do
begin
//Flags
_pos := MakeByte(_pos);
//ParamType
_pos := MakeDword(_pos);
//Name
_pos := MakeShortString(_pos);
//AttrData
_pos := OutputAttrData(_pos);
end;
End;
//AttrData
_pos := OutputAttrData(_pos);
end;
End;
end;
end;
procedure TIDCGen.OutputRTTIInterface(kind:LKind; _pos:Integer);
Var
count,dw:Word;
n,m:Integer;
methodKind,paramCnt,len:Byte;
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//IntfParent
_pos := MakeDword(_pos);
//IntfFlags
_pos := MakeByte(_pos);
//GUID
_pos := MakeArray(_pos, 16);
//UnitName
_pos := MakeShortString(_pos);
//PropCount
Count := PWORD(Code + _pos)^;
_pos := MakeWord(_pos);
if DelphiVersion >= 6 then
begin
//RttiCount
dw := PWORD(Code + _pos)^;
_pos := MakeWord(_pos);
if dw <> $FFFF then
begin
if DelphiVersion >= 2010 then
begin
for n := 1 To Count do
begin
//Name
_pos := MakeShortString(_pos);
//Kind
methodKind := Byte(Code[_pos]);
_pos := MakeByte(_pos);
//CallConv
_pos := MakeByte(_pos);
//ParamCount
paramCnt := Byte(Code[_pos]);
_pos := MakeByte(_pos);
for m := 1 to paramCnt do
begin
//Flags
_pos := MakeByte(_pos);
//ParamName
_pos := MakeShortString(_pos);
//TypeName
_pos := MakeShortString(_pos);
//ParamType
_pos := MakeDword(_pos);
End;
if methodKind<>0 then
begin
//ResultTypeName
len := Byte(Code[_pos]);
_pos := MakeShortString(_pos);
if len<>0 then
begin
//ResultType
_pos := MakeDword(_pos);
End;
end;
End;
end
else
begin
for n := 1 to Count do
begin
//PropType
_pos := MakeDword(_pos);
//GetProc
_pos := MakeDword(_pos);
//SetProc
_pos := MakeDword(_pos);
//StoredProc
_pos := MakeDword(_pos);
//Index
_pos := MakeDword(_pos);
//Default
_pos := MakeDword(_pos);
//NameIndex
_pos := MakeWord(_pos);
//Name
_pos := MakeShortString(_pos);
End;
End;
End;
if DelphiVersion >= 2010 then
begin
//AttrData
OutputAttrData(_pos);
End;
End;
end;
procedure TIDCGen.OutputRTTIInt64(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//MinVal
_pos := MakeQword(_pos);
//MaxVal
_pos := MakeQword(_pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIDynArray(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//elSize
_pos := MakeDword(_pos);
//elType
_pos := MakeDword(_pos);
//varType
_pos := MakeDword(_pos);
if DelphiVersion >= 6 then
begin
//elType2
_pos := MakeDword(_pos);
//UnitName
_pos := MakeShortString(_pos);
end;
if DelphiVersion >= 2010 then
begin
//DynArrElType
_pos := MakeDword(_pos);
//AttrData
OutputAttrData(_pos);
end;
end;
procedure TIDCGen.OutputRTTIUString(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
if DelphiVersion >= 2010 then OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIClassRef(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//InstanceType
_pos := MakeDword(_pos);
//AttrData
OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIPointer(kind:LKind; _pos:Integer);
Begin
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//RefType
_pos := MakeDword(_pos);
//AttrData
OutputAttrData(_pos);
end;
procedure TIDCGen.OutputRTTIProcedure(kind:LKind; _pos:Integer);
Var
pos1,procSig,n:Integer;
flags,paramCnt:Byte;
Begin
pos1:=_pos;
_pos:=_pos + OutputRTTIHeader(kind, _pos);
//MethSig
procSig := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
//AttrData
_pos := OutputAttrData(_pos);
//Procedure Signature
if procSig<>0 then
begin
if IsValidImageAdr(procSig) then _pos := Adr2pos(procSig)
else _pos := pos1 + procSig;
//Flags
flags := Byte(Code[_pos]);
_pos := MakeByte(_pos);
if flags <> 255 then
begin
//CallConv
_pos := MakeByte(_pos);
//ResultType
_pos := MakeDword(_pos);
//ParamCnt
paramCnt := Byte(Code[_pos]);
_pos := MakeByte(_pos);
for n:=1 to paramCnt do
begin
//Flags
_pos := MakeByte(_pos);
//ParamType
_pos := MakeDword(_pos);
//Name
_pos := MakeShortString(_pos);
//AttrData
_pos := OutputAttrData(_pos);
end;
end;
end;
end;
Procedure TIDCGen.OutputVMT (_pos:Integer; recN:InfoRec);
var
nameAdr,stop,ofs:Integer;
Begin
itemName := recN.Name;
_pos:=_pos + OutputVMTHeader(_pos, itemName);
if DelphiVersion >= 3 then
begin
//VmtIntfTable
OutputIntfTable(_pos);
Inc(_pos, 4);
//VmtAutoTable
OutputAutoTable(_pos);
Inc(_pos, 4);
end;
//VmtInitTable
OutputInitTable(_pos);
Inc(_pos, 4);
//VmtTypeInfo
_pos := MakeDword(_pos);
//VmtFieldTable
OutputFieldTable(_pos);
Inc(_pos, 4);
//VmtMethodTable
OutputMethodTable(_pos);
Inc(_pos, 4);
//VmtDynamicTable
OutputDynamicTable(_pos);
Inc(_pos, 4);
//VmtClassName
nameAdr := PInteger(Code + _pos)^;
_pos := MakeDword(_pos);
MakeShortString(Adr2pos(nameAdr));
//VmtInstanceSize
_pos := MakeDword(_pos);
//VmtParent
_pos := MakeDword(_pos);
if DelphiVersion >= 2009 then
begin
//VmtEquals
_pos := MakeDword(_pos);
//VmtGetHashCode
_pos := MakeDword(_pos);
//VmtToString
_pos := MakeDword(_pos);
end;
if DelphiVersion >= 3 then
begin
//VmtSafeCallException
_pos := MakeDword(_pos);
end;
if DelphiVersion >= 4 then
begin
//VmtAfterConstruction
_pos := MakeDword(_pos);
//VmtBeforeDestruction
_pos := MakeDword(_pos);
//VmtDispatch
_pos := MakeDword(_pos);
end;
//VmtDefaultHandler
_pos := MakeDword(_pos);
//VmtNewInstance
_pos := MakeDword(_pos);
//VmtFreeInstance
_pos := MakeDword(_pos);
//VmtDestroy
_pos := MakeDword(_pos);
//Vmt
stop := Adr2pos(GetStopAt(pos2Adr(_pos)));
//Virtual Methods
ofs := 0;
while _pos < stop do
begin
MakeComment(_pos, '+' + Val2Str(ofs));
Inc(ofs, 4);
_pos := MakeDword(_pos);
end;
end;
Function TIDCGen.OutputVMTHeader (_pos:Integer; vmtName:AnsiString):Integer;
var
from,adr:Integer;
s:AnsiString;