-
Notifications
You must be signed in to change notification settings - Fork 20
/
Threads.pas
3835 lines (3777 loc) · 119 KB
/
Threads.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 Threads;
Interface
Uses Classes, Def_thread,Main;
Type
TAnalyzeThread = class(TThread)
private
mainForm:TFMain;
adrCnt:Integer;
Function StartProgress(pbMaxCount:Integer; const sbText:AnsiString):Integer;
Procedure UpdateProgress;
Procedure StopProgress;
Procedure UpdateStatusBar(adr:Integer); Overload;
Procedure UpdateStatusBar(const sbText:AnsiString); Overload;
Procedure UpdateAddrInStatusBar(adr:Integer);
Procedure UpdateUnits;
Procedure UpdateRTTIs;
Procedure UpdateVmtList;
Procedure UpdateStrings;
Procedure UpdateCode;
Procedure UpdateXrefs;
Procedure UpdateShortClassViewer;
Procedure UpdateClassViewer;
Procedure UpdateBeforeClassViewer;
Procedure StrapSysProcs;
Procedure FindRTTIs;
Procedure FindVMTs2; //for Delphi2 (different structure!)
Procedure FindVMTs;
Procedure FindTypeFields;
Function FindEvent(VmtAdr:Integer; Name:AnsiString):AnsiString;
Procedure FindPrototypes;
Procedure StrapVMTs;
Procedure ScanCode;
Procedure ScanCode1;
Procedure ScanVMTs;
Procedure ScanConsts;
Procedure ScanGetSetStoredProcs;
Procedure FindStrings;
Procedure AnalyzeCode1;
Procedure AnalyzeCode2(args:Boolean);
Procedure PropagateClassProps;
Procedure FillClassViewer;
Procedure AnalyzeDC;
Procedure ClearPassFlags;
protected
procedure Execute; Override;
public
all:Boolean; //if false, only ClassViewer
ReturnValue:Integer;
constructor Create(AForm:TFMain; AllValues:Boolean);
end;
Implementation
Uses Windows,Messages,SysUtils,Types,Def_know,Def_info,Def_main,Forms,
Misc,Infos,Def_disasm,TypInfo,Resources,Def_res,Dialogs,Heuristic;
type
StdUnitInfo = record
used:Boolean;
name:PAnsiChar; //èìÿ þíèòà
matched:Single; //ìàêñèìàëüíîå êîë-âî ñîâïàäåíèé
maxno:Integer; //íîìåð þíèòà ñ ìàêñèìàëüíûì êîë-âîì ñîâïàäåíèé
end;
PStdUnitInfo = ^StdUnitInfo;
const
SKIPADDR_COUNT = 10;
PB_MAX_STEPS = 2048;
StdUnits:Array[0..6] of StdUnitInfo = (
(used:false; name:'Types'; matched:0; maxno:-1),
(used:false; name:'Multimon'; matched:0; maxno:-1),
(used:false; name:'VarUtils'; matched:0; maxno:-1),
(used:false; name:'StrUtils'; matched:0; maxno:-1),
(used:false; name:'Registry'; matched:0; maxno:-1),
(used:false; name:'IniFiles'; matched:0; maxno:-1),
(used:false; name:'Clipbrd'; matched:0; maxno:-1)
);
constructor TAnalyzeThread.Create(AForm:TFMain; AllValues:Boolean);
Begin
Inherited Create(True);
Priority:=tpLower;
mainForm:=AForm;
all:=AllValues;
end;
//PopupMenu items!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//The Execute method is called when the thread starts
Procedure TAnalyzeThread.Execute;
Begin
try
if all then
begin
//1
StrapSysProcs;
ReturnValue := 1;
CurProcAdr := EP;
UpdateCode;
//2
if DelphiVersion <> 2 Then
begin
FindRTTIs;
ReturnValue := 2;
UpdateUnits;
End;
//3
if DelphiVersion = 2 then FindVMTs2
else FindVMTs;
ReturnValue := 3;
UpdateVmtList;
UpdateRTTIs;
UpdateCode;
//4
StrapVMTs;
ReturnValue := 4;
UpdateCode;
//5
ScanCode;
ReturnValue := 5;
UpdateCode;
//6
ScanVMTs;
ReturnValue := 6;
UpdateVmtList;
UpdateCode;
UpdateShortClassViewer;
//7
ScanConsts;
ReturnValue := 7;
UpdateUnits;
//8
ScanGetSetStoredProcs;
ReturnValue := 8;
//9
FindStrings;
ReturnValue := 9;
//10
AnalyzeCode1;
ReturnValue := 10;
UpdateCode;
UpdateXrefs;
//11
ScanCode1;
ReturnValue := 11;
UpdateCode;
//12
PropagateClassProps;
ReturnValue := 12;
UpdateCode;
//13
FindTypeFields;
ReturnValue := 13;
UpdateCode;
//14
FindPrototypes;
ReturnValue := 14;
UpdateCode;
//15
AnalyzeCode2(true);
ReturnValue := 15;
UpdateCode;
UpdateStrings;
//16
AnalyzeDC;
ReturnValue := 16;
UpdateCode;
//17
AnalyzeCode2(false);
ReturnValue := 17;
UpdateCode;
UpdateStrings;
//18
AnalyzeDC;
ReturnValue := 18;
UpdateCode;
//19
AnalyzeCode2(false);
ReturnValue := LAST_ANALYZE_STEP;
UpdateCode;
UpdateStrings;
UpdateBeforeClassViewer;
end;
//20
FillClassViewer;
ReturnValue := LAST_ANALYZE_STEP + 1;
UpdateClassViewer;
Except
on E:Exception do Application.ShowException(e);
end;
//as update main wnd about operation over
//only Post() here! - async, otehrwise deadlock!
PostMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taFinished), 0);
end;
Function TAnalyzeThread.StartProgress (pbMaxCount:Integer; Const sbText:AnsiString):Integer;
var
stepSize, pbSteps:Integer;
startOperation:PThreadAnalysisData;
Begin
stepSize := 1;
pbSteps := pbMaxCount div stepSize;
if pbSteps * stepSize < pbMaxCount then Inc(pbSteps);
if pbMaxCount > PB_MAX_STEPS then
begin
stepSize := 256;
while pbSteps > PB_MAX_STEPS do
begin
stepSize:= stepSize shl 1;
pbSteps := pbMaxCount div stepSize;
if pbSteps * stepSize < pbMaxCount then Inc(pbSteps);
end;
End;
New(startOperation);
startOperation.pbSteps:=pbSteps;
startOperation.sbText:=sbText;
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taStartPrBar), Integer(startOperation));
//if stepSize <> 1 then Dec(stepSize);
Result:=stepSize - 1;
end;
Procedure TAnalyzeThread.UpdateProgress;
Begin
if Not Terminated then SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdatePrBar), 0);
end;
Procedure TAnalyzeThread.StopProgress;
Begin
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdatePrBar), 0);
//as the nice place to check if we are asked to Terminate
if Terminated Then Raise Exception.Create('Termination request 1');
end;
Procedure TAnalyzeThread.UpdateStatusBar (adr:Integer);
var
updStatBar:PThreadAnalysisData;
Begin
if not Terminated then
begin
New(updStatBar);
updStatBar.pbSteps:=0;
updStatBar.sbText:= Val2Str(adr,8);
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateStBar), Integer(updStatBar));
end;
end;
Procedure TAnalyzeThread.UpdateStatusBar(const sbText:AnsiString);
var
updStatBar:PThreadAnalysisData;
Begin
if not Terminated then
begin
New(updStatBar);
updStatBar.pbSteps:=0;
updStatBar.sbText:= sbText;
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateStBar), Integer(updStatBar));
end;
end;
Procedure TAnalyzeThread.UpdateAddrInStatusBar (adr:Integer);
Begin
if not Terminated then
begin
Inc(adrCnt);
//if adrCnt = SKIPADDR_COUNT then
begin
UpdateStatusBar(adr);
//adrCnt := 0;
end;
end;
end;
Procedure TAnalyzeThread.UpdateUnits;
var
isLastStep:LongBool;
Begin
if not Terminated then
begin
isLastStep := ReturnValue = LAST_ANALYZE_STEP;
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateUnits), Ord(isLastStep));
End;
end;
Procedure TAnalyzeThread.UpdateRTTIs;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateRTTIs), 0);
end;
Procedure TAnalyzeThread.UpdateVmtList;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateVmtList), 0);
end;
Procedure TAnalyzeThread.UpdateStrings;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateStrings), 0);
end;
Procedure TAnalyzeThread.UpdateCode;
Begin
if not Terminated then
begin
UpdateUnits;
//cant use Post here, there are some global shared vars!
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateCode), 0);
end;
end;
Procedure TAnalyzeThread.UpdateXrefs;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateXrefs), 0);
end;
Procedure TAnalyzeThread.UpdateShortClassViewer;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateShortClassViewer), 0);
end;
Procedure TAnalyzeThread.UpdateClassViewer;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateClassViewer), 0);
end;
Procedure TAnalyzeThread.UpdateBeforeClassViewer;
Begin
if not Terminated then
SendMessage(mainForm.Handle, WM_UPDANALYSISSTATUS, Ord(taUpdateBeforeClassViewer), 0);
end;
Procedure TAnalyzeThread.StrapSysProcs;
var
n, Idx, _pos:Integer;
pInfo:MProcInfo;
moduleID:Word;
has_pInfo:Boolean;
Begin
StartProgress(mainForm.SysProcsNum, 'Strap SysProcs');
moduleID := KBase.GetModuleID('System');
for n:=Low(SysProcs) to High(SysProcs) do
begin
if Terminated then Break;
UpdateProgress;
Idx := KBase.GetProcIdx(moduleID, PAnsiChar(SysProcs[n].name));
if Idx <> -1 then
begin
Idx := KBase.ProcOffsets[Idx].NamId;
if not KBase.IsUsedProc(Idx) then
begin
has_pInfo:=KBase.GetProcInfo(Idx, [INFO_DUMP, INFO_ARGS], pInfo);
if SysProcs[n].impAdr<>0 then
mainForm.StrapProc(Adr2Pos(SysProcs[n].impAdr), Idx, @pInfo, false, 6)
else
begin
_pos := KBase.ScanCode(Code, FlagList, CodeSize, @pInfo);
if has_pInfo and (_pos <> -1) then
begin
UpdateStatusBar(pInfo.ProcName);
mainForm.StrapProc(_pos, Idx, @pInfo, true, pInfo.DumpSz);
End;
end;
End;
end;
end;
moduleID := KBase.GetModuleID('SysInit');
for n:=Low(SysInitProcs) to High(SysInitProcs) do
begin
if Terminated then Break;
UpdateProgress;
Idx := KBase.GetProcIdx(moduleID, PAnsiChar(SysInitProcs[n].name));
if Idx <> -1 then
begin
Idx := KBase.ProcOffsets[Idx].NamId;
if not KBase.IsUsedProc(Idx) then
begin
has_pInfo := KBase.GetProcInfo(Idx, [INFO_DUMP, INFO_ARGS], pInfo);
_pos := KBase.ScanCode(Code, FlagList, CodeSize, @pInfo);
if has_pInfo and (_pos <> -1) then
begin
UpdateStatusBar(pInfo.ProcName);
mainForm.StrapProc(_pos, Idx, @pInfo, true, pInfo.DumpSz);
end;
end;
end;
end;
StopProgress;
end;
Procedure TAnalyzeThread.FindRTTIs;
Var
paramCnt, numOps, methodKind, flags, len:Byte;
typeKind:LKind;
dw, Count, methCnt:Word;
typInfo, baseTypeAdr, procSig, stepMask:Integer;
i,j, n, m, minValue, maxValue, elNum, _pos, instrLen:Integer;
adr,TypeAdr:Integer;
recN:InfoRec;
recT:PTypeRec;
unitName, typeName:AnsiString;
//prefix:AnsiString;
disInfo:TDisInfo;
Begin
stepMask := StartProgress(CodeSize, 'Find Types');
i:=0;
while (i< CodeSize) and not Terminated do
Begin
if (i and stepMask) = 0 then UpdateProgress;
adr := PInteger(Code + i)^;
if IsValidImageAdr(adr) and (adr = Pos2Adr(i) + 4) then
Begin
//euristica - look at byte Code + i - 3 - may be case (jmp [adr + reg*4])
instrLen := frmDisasm.Disassemble(Code + i - 3, Pos2Adr(i) - 3, @DisInfo, Nil);
if (instrLen > 3) and DisInfo.Branch and (DisInfo.Offset = adr) then
begin
Inc(i,4);
continue;
end;
typeAdr := adr - 4;
typeKind := LKind(Code[i + 4]);
if (typeKind = ikUnknown) or (typeKind > ikProcedure) then
begin
Inc(i,4);
continue;
End;
len := Byte(Code[i + 5]);
if not IsValidName(len, i + 6) then
begin
Inc(i,4);
continue;
end;
TypeName := GetTypeName(adr);
UpdateStatusBar(TypeName);
(*
//Names that begins with '.'
if TypeName[1] = '.' then
Begin
case typeKind of
ikEnumeration: prefix := '_Enumeration_';
ikArray: prefix := '_Array_';
ikDynArray: prefix := '_DynArray_';
else prefix := form.GetUnitName(recU);
End;
TypeName := prefix + Val2Str(recU.iniOrder) + '_' + Copy(TypeName,2, len);
End;
*)
n := i + 6 + len;
SetFlag([cfRTTI], i);
unitName := '';
case typeKind of
ikInteger: //1
begin
Inc(n); //ordType
Inc(n,4); //MinVal
Inc(n,4); //MaxVal
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikChar: //2
begin
Inc(n); //ordType
Inc(n,4); //MinVal
Inc(n,4); //MaxVal
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikEnumeration: //3
begin
Inc(n); //ordType
minValue := PInteger(Code + n)^;
Inc(n, 4);
maxValue := PInteger(Code + n)^;
Inc(n, 4);
//BaseType
baseTypeAdr := PInteger(Code + n)^;
Inc(n, 4);
if baseTypeAdr = typeAdr then
Begin
if SameText(TypeName, 'ByteBool') or
SameText(TypeName, 'WordBool') or
SameText(TypeName, 'LongBool') then
Begin
minValue := 0;
maxValue := 1;
End;
for j := minValue to maxValue do
Begin
len := Byte(Code[n]);
Inc(n, len + 1);
End;
End;
(*
//UnitName
len := Code[n];
if IsValidName(len, n + 1) then
Begin
unitName := Trim(MakeString(Code + n + 1, len));
SetUnitName(recU, unitName);
End;
Inc(n, len + 1);
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);
End;
*)
SetFlags([cfData], i, n - i);
end;
ikFloat: //4
begin
Inc(n); //FloatType
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikString: //5
begin
Inc(n); //MaxLength
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikSet: //6
begin
Inc(n, 1 + 4); //ordType+CompType
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikClass: //7
begin
Inc(n, 4); //classVMT
Inc(n, 4); //ParentInfo
Inc(n, 2); //PropCount
//UnitName
len := Byte(Code[n]);
if IsValidName(len, n + 1) then
Begin
unitName := Trim(MakeString(Code + n + 1, len));
//FMain.SetUnitName(recU, unitName);
End;
Inc(n, len + 1);
//PropData
Count := PWord(Code + n)^;
Inc(n, 2);
for j := 0 to Count-1 do
Begin
//TPropInfo
Inc(n, 26);
len := Byte(Code[n]);
Inc(n, len + 1);
End;
if DelphiVersion >= 2010 then
Begin
//PropDataEx
Count := PWord(Code + n)^;
Inc(n, 2);
for j := 0 to Count-1 do
Begin
//TPropInfoEx
//Flags
Inc(n);
//Info
typInfo := PInteger(Code + n)^;
Inc(n, 4);
_pos := Adr2Pos(typInfo);
len := Byte(Code[_pos + 26]);
SetFlags([cfData], _pos, 27 + len);
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
if DelphiVersion >= 2012 then
Begin
//ArrayPropCount
Count := PWord(Code + n)^;
Inc(n, 2);
//ArrayPropData
for j := 0 to Count-1 do
Begin
//Flags
Inc(n);
//ReadIndex
Inc(n, 2);
//WriteIndex
Inc(n, 2);
//Name
len := Byte(Code[n]);
Inc(n, len + 1);
//AttrData
dw := Pword(Code + n)^;
Inc(n,dw);//ATR!!
End;
End;
End;
SetFlags([cfData], i, n - i);
end;
ikMethod: //8
begin
//MethodKind
methodKind := Byte(Code[n]);
Inc(n); //0 (mkProcedure) or 1 (mkFunction)
paramCnt := Byte(Code[n]);
Inc(n);
for j := 0 to paramCnt-1 do
Begin
Inc(n); //Flags
len := Byte(Code[n]);
Inc(n, len + 1); //ParamName
len := Byte(Code[n]);
Inc(n,len + 1); //TypeName
End;
if methodKind<>0 then
Begin
//ResultType
len := Byte(Code[n]);
Inc(n, len + 1);
if DelphiVersion > 6 then
Begin
//ResultTypeRef
Inc(n, 4);
End;
End;
if DelphiVersion > 6 then
Begin
//CC
Inc(n);
//ParamTypeRefs
Inc(n, 4*paramCnt);
if DelphiVersion >= 2010 then
Begin
//MethSig
procSig := PInteger(Code + n)^;
Inc(n, 4);
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
//Procedure Signature
if procSig<>0 then
Begin
if IsValidImageAdr(procSig) then
_pos := Adr2Pos(procSig)
else
_pos := i + procSig;
m := 0;
//Flags
flags := Byte(Code[_pos]);
Inc(m);
if flags <> 255 then
Begin
//CC
Inc(m);
//ResultType
Inc(m, 4);
//ParamCount
paramCnt := Byte(Code[_pos + m]);
Inc(m);
for j := 0 to paramCnt-1 do
Begin
//Flags
Inc(m);
//ParamType
Inc(m, 4);
//Name
len := Byte(Code[_pos + m]);
Inc(m, len + 1);
//AttrData
dw := PWord(Code + _pos + m)^;
Inc(m, dw);//ATR!!
End;
End;
SetFlags([cfData], _pos, m);
End;
End;
End;
SetFlags([cfData], i, n - i);
end;
ikWChar: //9
begin
Inc(n); //ordType
Inc(n, 4); //MinVal
Inc(n, 4); //MaxVal
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikLString: // $0A
begin
//CodePage
if DelphiVersion >= 2009 then Inc(n, 2);
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikWString: // $0B
begin
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikVariant: // $0C
begin
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikArray: // $0D
begin
Inc(n, 4); //Size
Inc(n, 4); //ElCount
Inc(n, 4); //ElType
if DelphiVersion >= 2010 then
Begin
//DimCount
paramCnt := Byte(Code[n]);
Inc(n);
for j := 0 to paramCnt-1 do
Begin
//Dims
Inc(n, 4);
End;
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikRecord: // $0E
begin
Inc(n, 4); //Size
elNum := PInteger(Code + n)^;
Inc(n, 4); //ManagedFldCount
for j := 0 to elNum-1 do
Begin
Inc(n, 4); //TypeRef
Inc(n, 4); //FldOffset
End;
if DelphiVersion >= 2010 then
Begin
numOps := Byte(Code[n]);
Inc(n); //NumOps
for j := 0 to numOps-1 do //RecOps
Inc(n, 4);
elNum := PInteger(Code + n)^;
Inc(n, 4); //RecFldCnt
for j := 0 to elNum-1 do
Begin
Inc(n, 4); //TypeRef
Inc(n, 4); //FldOffset
Inc(n); //Flags
len := Byte(Code[n]);
Inc(n, len + 1); //Name
dw := PWord(Code + n)^;
if dw <> 2 then dummy := 1;
Inc(n, dw);//ATR!!
End;
dw := PWord(Code + n)^;
if dw <> 2 then dummy:=1;
Inc(n, dw);//ATR!!
if DelphiVersion >= 2012 then
Begin
methCnt := PWord(Code + n)^;
Inc(n, 2);
for j := 0 to methCnt-1 do
Begin
Inc(n); //Flags
Inc(n, 4); //Code
len := Byte(Code[n]);
Inc(n, len + 1); //Name
//ProcedureSignature
//Flags
flags := Byte(Code[n]);
Inc(n);
if flags <> 255 then
Begin
//CC
Inc(n);
//ResultType
Inc(n, 4);
//ParamCnt
paramCnt := Byte(Code[n]);
Inc(n);
//Params
for m := 0 to paramCnt-1 do
Begin
Inc(n); //Flags
Inc(n, 4); //ParamType
len := Byte(Code[n]);
Inc(n, len + 1); //Name
dw := PWord(Code + n)^;
if dw <> 2 then dummy:=1;
Inc(n, dw);//ATR!!
End;
End;
dw := PWord(Code + n)^;
if dw <> 2 then dummy:=1;
Inc(n, dw);//ATR!!
End;
End;
End;
SetFlags([cfData], i, n - i);
End;
ikInterface: // $0F
begin
Inc(n, 4); //IntfParent
Inc(n); //IntfFlags
Inc(n, 16); //GUID
//UnitName
len := Byte(Code[n]);
if IsValidName(len, n + 1) then
Begin
unitName := Trim(MakeString(Code + n + 1, len));
//FMain.SetUnitName(recU, unitName);
End;
Inc(n, len + 1);
//PropCount
Count := PWord(Code + n)^;
Inc(n, 2);
if DelphiVersion >= 6 then
Begin
//RttiCount
dw := PWord(Code + n)^;
Inc(n, 2);
if dw <> $FFFF then
Begin
if DelphiVersion >= 2010 then
Begin
for j := 0 to Count-1 do
Begin
//Name
len := Byte(Code[n]);
Inc(n, len + 1);
//Kind
methodKind := Byte(Code[n]);
Inc(n);
//CallConv
Inc(n);
//ParamCount
paramCnt := Byte(Code[n]);
Inc(n);
for m := 0 to paramCnt-1 do
Begin
//Flags
Inc(n);
//ParamName
len := Byte(Code[n]);
Inc(n, len + 1);
//TypeName
len := Byte(Code[n]);
Inc(n, len + 1);
//ParamType
Inc(n, 4);
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
if methodKind<>0 then
Begin
//ResultTypeName
len := Byte(Code[n]);
Inc(n, len + 1);
if len<>0 then
Begin
//ResultType
Inc(n, 4);
// ====== Insert by Pigrecos
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw); //ATR!!
// ====== Insert by Pigrecos
End;
End;
End;
End
else for j := 0 to Count-1 do
Begin
//PropType
Inc(n, 4);
//GetProc
Inc(n, 4);
//SetProc
Inc(n, 4);
//StoredProc
Inc(n, 4);
//Index
Inc(n, 4);
//Default
Inc(n, 4);
//NameIndex
Inc(n, 2);
//Name
len := Byte(Code[n]);
Inc(n, len + 1);
End;
End;
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
End;
SetFlags([cfData], i, n - i);
end;
ikInt64: // $10
begin
Inc(n, 8); //MinVal
Inc(n, 8); //MaxVal
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikDynArray: // $11
begin
Inc(n, 4); //elSize
Inc(n, 4); //elType
Inc(n, 4); //varType
if DelphiVersion >= 6 then
Begin
Inc(n, 4); //elType2
//UnitName
len := Byte(Code[n]);
if IsValidName(len, n + 1) then
Begin
unitName := Trim(MakeString(Code + n + 1, len));
//FMain.SetUnitName(recU, unitName);
End;
Inc(n, len + 1);
End;
if DelphiVersion >= 2010 then
Begin
//DynArrElType
Inc(n, 4);
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;
SetFlags([cfData], i, n - i);
end;
ikUString: // $12
begin
if DelphiVersion >= 2010 then
Begin
//AttrData
dw := PWord(Code + n)^;
Inc(n, dw);//ATR!!
End;