forked from jmpoep/vmprotect-3.5.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intel.h
1570 lines (1428 loc) · 56.8 KB
/
intel.h
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
#ifndef INTEL_H
#define INTEL_H
enum IntelCommandType : uint16_t
{
cmUnknown,cmPush,cmPop,cmMov,cmAdd,cmXor,cmTest,cmLea,
cmUd0, cmRet,cmNor,cmNand,cmCrc,cmCall,cmJmp,cmFstsw,cmFsqrt,cmFchs,cmFstcw,cmFldcw,
cmFild,cmFist,cmFistp,cmFld,cmFstp,cmFst,
cmFadd,cmFsub,cmFsubr,cmFisub,cmFisubr,cmFdiv,cmFcomp,cmFmul,
cmRepe,cmRepne,cmRep,cmDB,cmDW,cmDD,cmDQ,
cmMovs,cmCmps,cmScas,
cmMovzx,cmMovsx,
cmInc,cmDec,
cmLes,cmLds,cmLfs,cmLgs,cmLss,
cmXadd,cmBswap,
cmJmpWithFlag,
cmAnd,cmSub,cmStos,cmLods,cmNop,cmXchg,
cmPushf,cmPopf,cmSahf,cmLahf,cmShl,cmShr,cmSal,cmSar,cmRcl,cmRcr,cmRol,cmRor,cmShld,cmShrd,
cmLoope,cmLoopne,cmLoop,cmJCXZ,
cmIn,cmIns,cmOut,cmOuts,cmWait,
cmCbw,cmCwde,cmCdqe,cmCwd,cmCdq,cmCqo,
cmClc,cmStc,cmCli,cmSti,cmCld,cmStd,
cmNot,cmNeg,cmDiv,cmImul,cmIdiv,cmMul,
cmOr,cmAdc,cmCmp,cmSbb,
cmPusha,cmPopa,
cmClflush,cmPause,
cmBound,cmArpl,cmDaa,cmDas,cmAaa,cmAam,cmAad,cmAas,cmEnter,cmLeave,cmInt,cmInto,cmIret,
cmSetXX,cmCmov,
cmAddpd,cmAddps,cmAddsd,cmAddss,
cmAndpd,cmAndps,cmAndnpd,cmAndnps,
cmCmppd,cmCmpps,cmCmpsd,cmCmpss,
cmComisd,cmComiss,
cmCvtdq2ps,cmCvtpd2dq,cmCvtdq2pd,cmCvtpd2pi,cmCvtps2pi,
cmCvtpd2ps,cmCvtps2pd,cmCvtpi2pd,cmCvtpi2ps,cmCvtps2dq,
cmCvtsd2si,cmCvtss2si,cmCvtsd2ss,cmCvtss2sd,
cmCvttpd2pi,cmCvttps2pi,cmCvttpd2dq,cmCvttps2dq,
cmCvttsd2si,cmCvttss2si,
cmDivpd,cmDivps,cmDivsd,cmDivss,
cmMaxpd,cmMaxps,cmMaxsd,cmMaxss,
cmMinpd,cmMinps,cmMinsd,cmMinss,
cmMulpd,cmMulps,cmMulsd,cmMulss,
cmOrpd,cmOrps,
cmMovd,cmMovq,cmMovntq,cmMovapd,cmMovaps,cmMovdqa,cmMovdqu,
cmMovdq2q,cmMovq2dq,
cmMovhlps,cmMovhpd,cmMovhps,cmMovlhps,cmMovlpd,cmMovlps,
cmMovmskpd,cmMovmskps,
cmMovnti,
cmMovntpd,cmMovntps,
cmMovsd,cmMovss,
cmMovupd,cmMovups,
cmPmovmskb,cmPsadbw,
cmPshufw,cmPshufd,cmPshuflw,cmPshufhw,
cmPsubb,cmPsubw,cmPsubd,cmPsubq,
cmPsubsb,cmPsubsw,
cmPsubusb,cmPsubusw,
cmPaddb,cmPaddw,cmPaddd,cmPaddq,
cmPaddsb,cmPaddsw,
cmPaddusb,cmPaddusw,
cmPavgb,cmPavgw,
cmPinsrb,cmPinsrw,cmPinsrd,cmPinsrq,cmPextrw,
cmPmaxsb,cmPmaxsw,cmPmaxsd,cmPmaxub,cmPmaxuw,cmPmaxud,
cmPminsb,cmPminsw,cmPminsd,cmPminub,cmPminuw,cmPminud,
cmPmulhuw,cmPmulhw,cmPmullw,cmPmuludq,cmPmulld,
cmPsllw,cmPslld,cmPsllq,cmPslldq,
cmPsraw,cmPsrad,
cmPsrlw,cmPsrld,cmPsrlq,cmPsrldq,
cmPunpcklbw,cmPunpcklwd,cmPunpckldq,cmPunpcklqdq,cmPunpckhqdq,
cmPackusdw,cmPcmpgtb,cmPcmpgtw,cmPcmpgtd,cmPcmpeqb,cmPcmpeqw,cmPcmpeqd,cmEmms,
cmPacksswb,cmPackuswb,cmPunpckhbw,cmPunpckhwd,cmPunpckhdq,cmPackssdw,cmPand,cmPandn,cmPor,cmPxor,cmPmaddwd,
cmRcpps,cmRcpss,
cmRsqrtss,cmMovsxd,
cmShufps,cmShufpd,
cmSqrtpd,cmSqrtps,cmSqrtsd,cmSqrtss,
cmSubpd,cmSubps,cmSubsd,cmSubss,
cmUcomisd,cmUcomiss,
cmUnpckhpd,cmUnpckhps,
cmUnpcklpd,cmUnpcklps,
cmXorpd,cmXorps,
cmBt,cmBts,cmBtr,cmBtc,cmXlat,cmCpuid,cmRsm,cmBsf,cmBsr,cmCmpxchg,cmCmpxchg8b,
cmHlt,cmCmc,
cmLgdt,cmSgdt,cmLidt,cmSidt,cmSmsw,cmLmsw,cmInvlpg,
cmLar,cmLsl,cmClts,cmInvd,cmWbinvd,cmUd2,cmWrmsr,cmRdtsc,cmRdmsr,cmRdpmc,
cmFcom,cmFdivr,
cmFiadd,cmFimul,cmFicom,cmFicomp,cmFidiv,cmFidivr,
cmFaddp,cmFmulp,cmFsubp,cmFsubrp,cmFdivp,cmFdivrp,
cmFbld,cmFbstp,
cmFfree,cmFrstor,cmFsave,cmFucom,cmFucomp,
cmFldenv,cmFstenvm,
cmFxch,cmFabs,cmFxam,
cmFld1,cmFldl2t,cmFldl2e,cmFldpi,cmFldlg2,cmFldln2,
cmFldz,cmFyl2x,cmFptan,cmFpatan,cmFxtract,cmFprem1,cmFdecstp,cmFincstp,
cmFprem,cmFyl2xp1,cmFsincos,cmFrndint,cmFscale,cmFsin,cmFcos,cmFtst,
cmFstenv,cmF2xm1,cmFnop,cmFinit,cmFclex,cmFcompp,
cmSysenter,cmSysexit,cmSldt,cmStr,cmLldt,cmLtr,cmVerr,cmVerw,
cmSfence,cmLfence,cmMfence,cmPrefetchnta,cmPrefetcht0,cmPrefetcht1,cmPrefetcht2,cmPrefetch,cmPrefetchw,
cmFxrstor,cmFxsave,cmLdmxcsr,cmStmxcsr,
cmFcmovb, cmFcmove, cmFcmovbe, cmFcmovu, cmFcmovnb, cmFcmovne, cmFcmovnbe, cmFcmovnu,
cmFucomi,cmFcomi,
cmFucomip,cmFcomip,cmFucompp,
cmVmcall, cmVmlaunch, cmVmresume, cmVmxoff, cmMonitor, cmMwait, cmXgetbv, cmXsetbv, cmVmrun, cmVmmcall,
cmVmload, cmVmsave, cmStgi, cmClgi, cmSkinit, cmInvlpga, cmSwapgs, cmRdtscp, cmSyscall, cmSysret, cmFemms, cmGetsec,
cmPshufb, cmPhaddw, cmPhaddd, cmPhaddsw, cmPmaddubsw, cmPhsubw, cmPhsubd, cmPhsubsw, cmPsignb, cmPsignw, cmPsignd, cmPmulhrsw,
cmPabsb, cmPabsw, cmPabsd, cmMovbe, cmPalignr, cmRsqrtps, cmVmread, cmVmwrite, cmSvldt, cmRsldt, cmSvts, cmRsts,
cmXsave, cmXrstor, cmVmptrld, cmVmptrst, cmMaskmovq, cmFnstenv, cmFnstcw, cmFstp1, cmFneni, cmFndisi, cmFnclex, cmFninit,
cmFsetpm, cmFisttp, cmFnsave, cmFnstsw, cmFxch4, cmFcomp5, cmFfreep, cmFxch7, cmFstp8, cmFstp9, cmHaddpd, cmHsubpd,
cmAddsubpd, cmAddsubps, cmMovntdq, cmFcom2, cmFcomp3, cmHaddps, cmHsubps, cmMovddup, cmMovsldup, cmCvtsi2sd, cmCvtsi2ss,
cmMovntsd, cmMovntss, cmLddqu, cmMovshdup, cmPopcnt, cmTzcnt, cmLzcnt,
cmPblendvb, cmPblendps, cmPblendpd, cmPblendw, cmPtest, cmPmovsxbw, cmPmovsxbd, cmPmovsxbq, cmPmovsxwd, cmPmovsxwq, cmPmovsxdq, cmPmuldq,
cmPcmpeqq, cmMovntdqa, cmXsaveopt, cmMaskmovdqu, cmUd1, cmPcmpgtq,
cmAesdec, cmAesdeclast, cmAesenc, cmAesenclast, cmAesimc, cmAeskeygenassist,
cmRdrand, cmRdseed,
cmPmovzxbw, cmPmovzxbd, cmPmovzxbq, cmPmovzxwd, cmPmovzxwq, cmPmovzxdq,
cmFnmadd132sd, cmFnmadd213sd, cmFnmadd231sd,
cmFnmadd132ss, cmFnmadd213ss, cmFnmadd231ss,
cmUleb,cmSleb,cmDC,
cmVbroadcastss, cmVbroadcastsd, cmVbroadcastf128, cmVperm2f128, cmVpermilpd, cmVpermilps, cmRoundpd, cmRoundps, cmCrc32, cmPextrb, cmPextrd, cmPextrq, cmVzeroupper,
cmVzeroall, cmBlendpd, cmBlendps, cmBlendvpd, cmBlendvps, cmDpps, cmExtractf128, cmInsertf128, cmMaskmovpd, cmMaskmovps,
cmVtestps, cmVtestpd, cmPcmpistri
};
static const char *intel_command_name[] = {
"db ??","push","pop","mov","add","xor","test","lea",
"ud0", "ret","nor","nand","crc","call","jmp","fstsw","fsqrt","fchs","fstcw","fldcw",
"fild","fist","fistp","fld","fstp","fst",
"fadd","fsub","fsubr","fisub","fisubr","fdiv","fcomp","fmul",
"repe","repne","rep","db","dw","dd","dq",
"movs","cmps","scas",
"movzx","movsx",
"inc","dec",
"les","lds","lfs","lgs","lss",
"xadd","bswap",
"j",
"and","sub","stos","lods","nop","xchg",
"pushf","popf","sahf","lahf","shl","shr","sal","sar","rcl","rcr","rol","ror","shld","shrd",
"loope","loopne","loop","jcxz",
"in","ins","out","outs","wait",
"cbw","cwde","cdqe","cwd","cdq","cqo",
"clc","stc","cli","sti","cld","std",
"not","neg","div","imul","idiv","mul",
"or","adc","cmp","sbb",
"pusha","popa",
"clflush","pause",
"bound","arpl","daa","das","aaa","aam","aad","aas","enter","leave","int","into","iret",
"set","cmov",
"addpd","addps","addsd","addss",
"andpd","andps","andnpd","andnps",
"cmppd","cmpps","cmpsd","cmpss",
"comisd","comiss",
"cvtdq2ps","cvtpd2dq","cvtdq2pd","cvtpd2pi","cvtps2pi",
"cvtpd2ps","cvtps2pd","cvtpi2pd","cvtpi2ps","cvtps2dq",
"cvtsd2si","cvtss2si","cvtsd2ss","cvtss2sd",
"cvttpd2pi","cvttps2pi","cvttpd2dq","cvttps2dq",
"cvttsd2si","cvttss2si",
"divpd","divps","divsd","divss",
"maxpd","maxps","maxsd","maxss",
"minpd","minps","minsd","minss",
"mulpd","mulps","mulsd","mulss",
"orpd","orps",
"movd","movq","movntq","movapd","movaps","movdqa","movdqu",
"movdq2q","movq2dq",
"movhlps","movhpd","movhps","movlhps","movlpd","movlps",
"movmskpd","movmskps",
"movnti",
"movntpd","movntps",
"movsd","movss",
"movupd","movups",
"pmovmskb","psadbw",
"pshufw","pshufd","pshuflw","pshufhw",
"psubb","psubw","psubd","psubq",
"psubsb","psubsw",
"psubusb","psubusw",
"paddb","paddw","paddd","paddq",
"paddsb","paddsw",
"paddusb","paddusw",
"pavgb","pavgw",
"pinsrb","pinsrw","pinsrd","pinsrq","pextrw",
"pmaxsb","pmaxsw","pmaxsd","pmaxub","pmaxuw","pmaxud",
"pminsb","pminsw","pminsd","pminub","pminuw","pminud",
"pmulhuw","pmulhw","pmullw","pmuludq","pmulld",
"psllw","pslld","psllq","pslldq",
"psraw","psrad",
"psrlw","psrld","psrlq","psrldq",
"punpcklbw","punpcklwd","punpckldq","punpcklqdq","punpckhqdq",
"packusdw","pcmpgtb","pcmpgtw","pcmpgtd","pcmpeqb","pcmpeqw","pcmpeqd","emms",
"packsswb","packuswb","punpckhbw","punpckhwd","punpckhdq","packssdw","pand","pandn","por","pxor","pmaddwd",
"rcpps","rcpss",
"rsqrtss","movsxd",
"shufps","shufpd",
"sqrtpd","sqrtps","sqrtsd","sqrtss",
"subpd","subps","subsd","subss",
"ucomisd","ucomiss",
"unpckhpd","unpckhps",
"unpcklpd","unpcklps",
"xorpd","xorps",
"bt","bts","btr","btc","xlat","cpuid","rsm","bsf","bsr","cmpxchg","cmpxchg8b",
"hlt","cmc",
"lgdt","sgdt","lidt","sidt","smsw","lmsw","invlpg",
"lar","lsl","clts","invd","wbinvd","ud2","wrmsr","rdtsc","rdmsr","rdpmc",
"fcom","fdivr",
"fiadd","fimul","ficom","ficomp","fidiv","fidivr",
"faddp","fmulp","fsubp","fsubrp","fdivp","fdivrp",
"fbld","fbstp",
"ffree","frstor","fsave","fucom","fucomp",
"fldenv","fstenvm",
"fxch","fabs","fxam",
"fld1","fldl2t","fldl2e","fldpi","fldlg2","fldln2",
"fldz","fyl2x","fptan","fpatan","fxtract","fprem1","fdecstp","fincstp",
"fprem","fyl2xp1","fsincos","frndint","fscale","fsin","fcos","ftst",
"fstenv","f2xm1","fnop","finit","fclex","fcompp",
"sysenter","sysexit","sldt","str","lldt","ltr","verr","verw",
"sfence","lfence","mfence","prefetchnta","prefetcht0","prefetcht1","prefetcht2","prefetch","prefetchw",
"fxrstor","fxsave","ldmxcsr","stmxcsr",
"fcmovb", "fcmove", "fcmovbe", "fcmovu", "fcmovnb", "fcmovne", "fcmovnbe", "fcmovnu",
"fucomi","fcomi",
"fucomip","fcomip","fucompp",
"vmcall", "vmlaunch", "vmresume", "vmxoff", "monitor", "mwait", "xgetbv", "xsetbv", "vmrun", "vmmcall",
"vmload", "vmsave", "stgi", "clgi", "skinit", "invlpga", "swapgs", "rdtscp", "syscall", "sysret", "femms", "getsec",
"pshufb", "phaddw", "phaddd", "phaddsw", "pmaddubsw", "phsubw", "phsubd", "phsubsw", "psignb", "psignw", "psignd", "pmulhrsw",
"pabsb", "pabsw", "pabsd", "movbe", "palignr", "rsqrtps", "vmread", "vmwrite", "svldt", "rsldt", "svts", "rsts",
"xsave", "xrstor", "vmptrld", "vmptrst", "maskmovq", "fnstenv", "fnstcw", "fstp1", "fneni", "fndisi", "fnclex", "fninit",
"fsetpm", "fisttp", "fnsave", "fnstsw", "fxch4", "fcomp5", "ffreep", "fxch7", "fstp8", "fstp9", "haddpd", "hsubpd",
"addsubpd", "addsubps", "movntdq", "fcom2", "fcomp3", "haddps", "hsubps", "movddup", "movsldup", "cvtsi2sd", "cvtsi2ss",
"movntsd", "movntss", "lddqu", "movshdup", "popcnt", "tzcnt", "lzcnt",
"pblendvb", "pblendps", "pblendpd", "pblendw", "ptest", "pmovsxbw", "pmovsxbd", "pmovsxbq", "pmovsxwd", "pmovsxwq", "pmovsxdq", "pmuldq",
"pcmpeqq", "movntdqa", "xsaveopt", "maskmovdqu", "ud1", "pcmpgtq",
"aesdec", "aesdeclast", "aesenc", "aesenclast", "aesimc", "aeskeygenassist",
"rdrand", "rdseed",
"pmovzxbw", "pmovzxbd", "pmovzxbq", "pmovzxwd", "pmovzxwq", "pmovzxdq",
"fnmadd132sd", "fnmadd213sd", "fnmadd231sd",
"fnmadd132ss", "fnmadd213ss", "fnmadd231ss",
"uleb","sleb","dc",
"broadcastss", "broadcastsd", "broadcastf128", "perm2f128", "permilpd", "permilps", "roundpd", "roundps", "crc32", "pextrb", "pextrd", "pextrq", "zeroupper",
"zeroall", "blendpd", "blendps", "blendvpd", "blendvps", "dpps", "extractf128", "insertf128", "maskmovpd", "maskmovps",
"testps", "testpd", "pcmpistri"
};
enum IntelFlags : uint16_t {
fl_C = 0x0001,
fl_P = 0x0004,
fl_A = 0x0010,
fl_Z = 0x0040,
fl_S = 0x0080,
fl_T = 0x0100,
fl_I = 0x0200,
fl_D = 0x0400,
fl_O = 0x0800,
fl_OS = fl_S | fl_O
};
enum IntelRegistr : uint8_t {
regEAX,
regECX,
regEDX,
regEBX,
regESP,
regEBP,
regESI,
regEDI,
regR8,
regR9,
regR10,
regR11,
regR12,
regR13,
regR14,
regR15,
regEIP
};
enum IntelSegment : uint8_t {
segES,
segCS,
segSS,
segDS,
segFS,
segGS,
segDefault = 0xff
};
enum IntelRexFlags : uint8_t {
rexB = 0x01,
rexX = 0x02,
rexR = 0x04,
rexW = 0x08,
vexL = 0x80
};
struct IntelOperand {
uint64_t value;
IFixup *fixup;
IRelocation *relocation;
uint16_t type;
OperandSize size;
uint8_t registr;
uint8_t base_registr;
uint8_t scale_registr;
uint8_t value_pos;
OperandSize address_size;
OperandSize value_size;
bool show_size;
bool is_large_value;
IntelOperand()
{
Clear();
}
void Clear()
{
type = otNone;
fixup = NULL;
relocation = NULL;
registr = 0;
base_registr = 0;
scale_registr = 0;
size = osDefault;
value_size = address_size = osDefault;
value_pos = 0;
value = 0;
show_size = false;
is_large_value = false;
}
IntelSegment effective_base_segment(IntelSegment base_segment) const
{
if (base_segment == segDefault &&
(((type & otBaseRegistr) && (base_registr == regESP || base_registr == regEBP)) ||
((type & otRegistr) && (registr == regESP || registr == regEBP)))) {
return segSS;
} else {
return (base_segment == segDefault) ? segDS : base_segment;
}
}
IntelOperand(uint32_t type_, OperandSize size_, uint8_t registr_ = 0, uint64_t value_ = 0, IFixup *fixup_ = NULL);
uint64_t encode() const
{
uint64_t res = static_cast<uint64_t>(type) << 48;
if (type & (otRegistr | otSegmentRegistr | otControlRegistr | otDebugRegistr | otFPURegistr | otHiPartRegistr | otMMXRegistr | otXMMRegistr))
res |= static_cast<uint64_t>(registr) << 44;
if (type & otBaseRegistr)
res |= static_cast<uint64_t>(base_registr) << 40;
if (type & otValue)
res |= static_cast<uint32_t>(value);
return res;
}
void decode(uint64_t value_)
{
type = (value_ >> 48) & 0xffff;
if (type & (otRegistr | otSegmentRegistr | otControlRegistr | otDebugRegistr | otFPURegistr | otHiPartRegistr | otMMXRegistr | otXMMRegistr))
registr = (value_ >> 44) & 0xf;
if (type & otBaseRegistr)
base_registr = (value_ >> 40) & 0xf;
if (type & otValue)
value = static_cast<uint32_t>(value_);
}
bool operator == (const IntelOperand &operand) const
{
if (type != operand.type)
return false;
if (type & (otRegistr | otSegmentRegistr | otControlRegistr | otDebugRegistr | otFPURegistr | otHiPartRegistr | otMMXRegistr | otXMMRegistr)) {
if (registr != operand.registr)
return false;
}
if ((type & (otMemory | otRegistr)) == (otMemory | otRegistr)) {
if (scale_registr != operand.scale_registr)
return false;
}
if (type & otBaseRegistr) {
if (base_registr != operand.base_registr)
return false;
}
if (type & otValue) {
if (value != operand.value)
return false;
}
return true;
}
bool operator != (const IntelOperand &operand) const
{
return !(operator == (operand));
}
};
class IntelCommand;
class IntelOpcodeInfo;
class IntelVMCommand : public BaseVMCommand
{
public:
explicit IntelVMCommand(IntelCommand *owner, IntelCommandType command_type, OperandType operand_type, OperandSize size, uint64_t value, uint32_t options);
explicit IntelVMCommand(IntelCommand *owner, const IntelVMCommand &src);
virtual void WriteToFile(IArchitecture &file);
virtual void Compile();
IntelVMCommand *Clone(IntelCommand *owner);
virtual uint64_t address() const { return address_; }
virtual size_t dump_size() const { return dump_.size(); }
virtual void set_address(uint64_t address) { address_ = address; }
virtual void set_value(uint64_t value) { value_ = value; }
void set_sub_value(uint64_t sub_value) { sub_value_ = sub_value; }
void set_dump(const Data &dump) { dump_ = dump; }
uint32_t options() const { return options_; }
void include_option(VMCommandOption option) { options_ |= option; }
int GetStackLevel() const;
IntelCommandType crypt_command() const { return crypt_command_; }
OperandSize crypt_size() const { return crypt_size_; }
uint64_t crypt_key() const { return crypt_key_; }
IntelVMCommand *link_command() const { return link_command_; }
void set_crypt_command(IntelCommandType crypt_command, OperandSize crypt_size, uint64_t crypt_key) { crypt_command_ = crypt_command; crypt_size_ = crypt_size; crypt_key_ = crypt_key; }
void set_link_command(IntelVMCommand *command) { link_command_ = command; }
IntelCommandType command_type() const { return command_type_; }
OperandType operand_type() const { return operand_type_; }
uint8_t registr() const { return registr_; }
OperandSize size() const { return size_; }
uint64_t value() const { return value_; }
uint64_t sub_value() const { return sub_value_; }
IntelSegment base_segment() const { return base_segment_; }
uint8_t subtype() const { return subtype_; }
uint8_t dump(size_t pos) const { return dump_[pos]; }
uint64_t dump_value(OperandSize size, size_t pos) const;
void set_dump_value(OperandSize size, size_t pos, uint64_t value);
void set_dump(size_t pos, uint8_t value) { dump_[pos] = value; }
bool can_merge(CommandInfoList &command_info_list) const;
IntelOpcodeInfo *opcode() const { return opcode_; }
void set_opcode(IntelOpcodeInfo *opcode) { opcode_ = opcode; }
virtual bool is_end() const;
bool is_data() const { return (command_type_ == cmDD || command_type_ == cmDQ); }
IFixup *fixup() const { return fixup_; }
void set_fixup(IFixup *fixup) { fixup_ = fixup; }
private:
uint64_t CorrectDumpValue(OperandSize size, uint64_t value) const;
uint64_t address_;
uint64_t crypt_key_;
uint64_t sub_value_;
uint64_t value_;
IntelVMCommand *link_command_;
IntelOpcodeInfo *opcode_;
uint32_t options_;
IntelCommandType command_type_;
IntelCommandType crypt_command_;
Data dump_;
OperandType operand_type_;
uint8_t registr_;
uint8_t subtype_;
OperandSize size_;
IntelSegment base_segment_;
OperandSize crypt_size_;
IFixup *fixup_;
};
struct DisasmContext {
IArchitecture *file;
bool lower_reg;
bool lower_address;
uint8_t rex_prefix;
uint8_t vex_registr;
bool use_last_byte;
};
struct AsmContext {
uint8_t rex_prefix;
};
enum CompileOperandOption {
coSaveResult = 0x0001,
coAsPointer = 0x0002,
coInverse = 0x0004,
coFixup = 0x0008,
coAsWord = 0x0010
};
class IntelFunction;
class SectionCryptor;
class AddressRange;
class IntelCommandInfoList : public CommandInfoList
{
public:
explicit IntelCommandInfoList(OperandSize cpu_address_size);
virtual void Add(AccessType access_type, uint8_t value, OperandType operand_type, OperandSize size);
void AddOperand(const IntelOperand &operand, AccessType access_type);
void set_base_segment(IntelSegment base_segment) { base_segment_ = base_segment; }
private:
OperandSize cpu_address_size_;
IntelSegment base_segment_;
};
class EncodedData;
class IntelCommand: public BaseCommand
{
public:
explicit IntelCommand(IFunction *owner, OperandSize size, uint64_t address = 0);
explicit IntelCommand(IFunction *owner, OperandSize size, IntelCommandType type, IntelOperand operand1 = IntelOperand(), IntelOperand operand2 = IntelOperand(), IntelOperand operand3 = IntelOperand());
explicit IntelCommand(IFunction *owner, OperandSize size, const std::string &value);
explicit IntelCommand(IFunction *owner, OperandSize size, const os::unicode_string &value);
explicit IntelCommand(IFunction *owner, OperandSize size, const Data &value);
explicit IntelCommand(IFunction *owner, const IntelCommand &source);
~IntelCommand();
virtual void clear();
virtual IntelCommand *Clone(IFunction *owner) const;
virtual void CompileToNative();
virtual void CompileLink(const CompileContext &ctx);
virtual void PrepareLink(const CompileContext &ctx);
void CompileToVM(const CompileContext &ctx);
virtual uint64_t address() const { return address_; }
virtual CommandType type() const { return type_; }
IntelOperand operand(size_t index) const {
if (index >= _countof(operand_))
throw std::runtime_error("subscript out of range");
return operand_[index];
}
const IntelOperand *operand_ptr(size_t index) const {
if (index >= _countof(operand_))
throw std::runtime_error("subscript out of range");
return &operand_[index];
}
virtual std::string text() const;
virtual CommentInfo comment();
virtual uint32_t section_options() const { return section_options_; }
virtual void set_address(uint64_t address);
virtual size_t original_dump_size() const { return (original_dump_size_) ? original_dump_size_ : dump_size(); }
IntelSegment base_segment() const { return base_segment_; }
CommandType preffix_command() const { return preffix_command_; }
OperandSize size() const { return size_; }
uint32_t flags() const { return flags_; }
void set_flags(uint32_t flags) { flags_ = flags; }
virtual ISEHandler *seh_handler() const { return seh_handler_; }
void set_seh_handler(ISEHandler *handler) { seh_handler_ = handler; }
size_t command_pos() const { return command_pos_; }
size_t ReadFromFile(IArchitecture &file);
uint64_t ReadValueFromFile(IArchitecture &file, OperandSize size);
void ReadArray(IArchitecture &file, size_t len);
virtual void ReadFromBuffer(Buffer &buffer, IArchitecture &file);
virtual void WriteToFile(IArchitecture &file);
virtual void set_operand_value(size_t operand_index, uint64_t value);
virtual void set_link_value(size_t link_index, uint64_t value);
virtual void set_jmp_value(size_t link_index, uint64_t value);
void set_operand_fixup(size_t operand_index, IFixup *fixup);
void set_operand_relocation(size_t operand_index, IRelocation *relocation);
void set_operand_scale(size_t operand_index, uint8_t value);
void set_base_segment(IntelSegment base_segment) { base_segment_ = base_segment; }
void set_preffix_command(IntelCommandType preffix_command) { preffix_command_ = preffix_command; }
void Init(IntelCommandType type, IntelOperand operand1 = IntelOperand(), IntelOperand operand2 = IntelOperand(), IntelOperand operand3 = IntelOperand());
void Init(const Data &data);
void InitUnknown();
virtual bool is_data() const;
virtual bool is_end() const;
virtual void Rebase(uint64_t delta_base);
virtual void include_section_option(SectionOption option) { section_options_ |= option; }
virtual void exclude_section_option(SectionOption option) { section_options_ &= ~option; }
IntelVMCommand *AddVMCommand(const CompileContext &ctx, IntelCommandType command_type, OperandType operand_type, OperandSize size, uint64_t value, uint32_t options = 0, IFixup *fixup = NULL);
void AddBeginSection(const CompileContext &ctx, uint32_t options = 0);
void AddEndSection(const CompileContext &ctx, IntelCommandType end_command, uint8_t end_value = 0, uint32_t options = 0);
void AddExtSection(const CompileContext &ctx, IntelCommand *command);
uint64_t AddStoreEIPSection(const CompileContext &ctx, uint64_t prev_eip);
void AddStoreExtRegistrSection(const CompileContext &ctx, uint8_t registr);
void AddStoreExtRegistersSection(const CompileContext &ctx);
void AddCryptorSection(const CompileContext &ctx, ValueCryptor *cryptor, bool is_decrypt);
IntelVMCommand *item(size_t index) const { return reinterpret_cast<IntelVMCommand *>(BaseCommand::item(index)); }
virtual uint64_t ext_vm_address() const { return (ext_vm_entry_) ? ext_vm_entry_->address() : vm_address(); }
virtual std::string dump_str() const;
virtual std::string display_address() const;
bool is_equal(const IntelCommand &command) const;
IntelVMCommand *ext_vm_entry() const { return ext_vm_entry_; }
bool GetCommandInfo(IntelCommandInfoList &command_info_list) const;
virtual bool Merge(ICommand *command);
uint8_t ReadDataByte(EncodedData &data, size_t *pos);
uint16_t ReadDataWord(EncodedData &data, size_t *pos);
uint32_t ReadDataDWord(EncodedData &data, size_t *pos);
uint64_t ReadDataQWord(EncodedData &data, size_t *pos);
uint64_t ReadUleb128(EncodedData &data, size_t *pos);
int64_t ReadSleb128(EncodedData &data, size_t *pos);
uint64_t ReadEncoding(EncodedData &data, uint8_t encoding, size_t *pos);
std::string ReadString(EncodedData &data, size_t *pos);
void ReadData(EncodedData &data, size_t size, size_t *pos);
int32_t ReadCompressedValue(IArchitecture &file);
#ifdef CHECKED
virtual bool check_hash() const;
void update_hash();
#endif
private:
bool GetOperandText(std::string &str, size_t index) const;
IntelOperand *GetFreeOperand();
// disasm methods
void ReadCommand(IntelCommandType type, uint32_t of_1, uint32_t of_2, uint32_t of_3, DisasmContext &ctx);
void ReadRegFromRM(uint8_t code, OperandSize operand_size, OperandType operand_type, const DisasmContext &ctx);
void ReadRM(uint8_t code, OperandSize operand_size, OperandType operand_type, bool show_size, const DisasmContext &ctx);
void ReadReg(uint8_t code, OperandSize operand_size, OperandType operand_type, const DisasmContext &ctx);
IntelOperand *ReadValue(OperandSize operand_size, OperandSize value_size, const DisasmContext &ctx);
void ReadValueAddAddress(OperandSize operand_size, OperandSize value_size, const DisasmContext &ctx);
void ReadFlags(uint8_t code);
// asm methods
void PushReg(size_t operand_index, uint8_t add_code, AsmContext &ctx);
void PushRM(size_t operand_index, uint8_t add_code, AsmContext &ctx);
void PushRegAndRM(size_t reg_operand_index, size_t rm_operand_index, AsmContext &ctx);
void PushFlags(uint8_t add_code);
void PushPrefix(AsmContext &ctx);
void PushBytePrefix(uint8_t prefix);
void PushWordPrefix();
// virtualization methods
void CompileOperand(const CompileContext &ctx, size_t operand_index, uint32_t options = 0);
void AddCorrectOperandSizeSection(const CompileContext &ctx, OperandSize src, OperandSize dst);
void AddCombineFlagsSection(const CompileContext &ctx, uint16_t mask);
void AddRegistrAndValueSection(const CompileContext &ctx, uint8_t registr, OperandSize registr_size, uint64_t value, bool need_pushf = false);
void AddRegistrOrValueSection(const CompileContext &ctx, uint8_t registr, OperandSize registr_size, uint64_t value, bool need_pushf = false);
void AddCorrectFlagSection(const CompileContext &ctx, uint16_t flags);
void AddExtractFlagSection(const CompileContext &ctx, uint16_t flags, bool is_inverse, uint8_t extract_to);
void AddJmpWithFlagSection(const CompileContext &ctx, IntelCommandType command_type);
void AddCorrectESPSection(const CompileContext &ctx, OperandSize operand_size, size_t value);
void AddCheckBreakpointSection(const CompileContext &ctx, OperandSize address_size);
void AddCheckCRCSection(const CompileContext &ctx, OperandSize address_size);
#ifdef CHECKED
uint32_t calc_hash() const;
uint32_t hash_;
#endif
uint64_t address_;
IntelOperand operand_[3];
uint32_t vex_operand_;
uint32_t flags_;
std::vector<IntelVMCommand *> vm_links_;
InternalLinkList internal_links_;
std::vector<IntelVMCommand *> jmp_links_;
IntelVMCommand *ext_vm_entry_;
SectionCryptor *begin_section_cryptor_;
SectionCryptor *end_section_cryptor_;
IntelCommandInfoList *vm_command_info_list_;
size_t command_pos_;
size_t original_dump_size_;
uint32_t section_options_;
IntelCommandType type_;
IntelCommandType preffix_command_;
OperandSize size_;
IntelSegment base_segment_;
ISEHandler *seh_handler_;
// no copy ctr or assignment op
IntelCommand(const IntelCommand &);
IntelCommand &operator =(const IntelCommand &);
};
class SectionCryptorList;
class SectionCryptor : public IObject
{
public:
explicit SectionCryptor(SectionCryptorList *owner, OperandSize cpu_address_size);
~SectionCryptor();
ByteList *registr_order() { return ®istr_order_; }
SectionCryptor *end_cryptor();
void set_end_cryptor(SectionCryptor *cryptor);
private:
SectionCryptorList *owner_;
ByteList registr_order_;
SectionCryptor *parent_cryptor_;
};
class SectionCryptorList : public ObjectList<SectionCryptor>
{
public:
explicit SectionCryptorList(IFunction *owner);
SectionCryptor *Add();
private:
IFunction *owner_;
};
enum ReadMarkerOption {
moNone,
moNeedParam = 0x1,
moForward = 0x2,
moSkipLastCall = 0x4
};
class IntelFunction : public BaseFunction
{
public:
explicit IntelFunction(IFunctionList *owner, const std::string &name, CompilationType compilation_type, uint32_t compilation_options, bool need_compile, Folder *folder);
explicit IntelFunction(IFunctionList *owner = NULL);
explicit IntelFunction(IFunctionList *owner, OperandSize cpu_address_size, IFunction *parent = NULL);
explicit IntelFunction(IFunctionList *owner, const IntelFunction &src);
virtual ~IntelFunction();
virtual void clear();
virtual IntelFunction *Clone(IFunctionList *owner) const;
IntelCommand *item(size_t index) const { return reinterpret_cast<IntelCommand *>(IFunction::item(index)); }
IntelCommand *ReadValidCommand(IArchitecture &file, uint64_t address);
void ReadMarkerCommands(IArchitecture &file, MarkerCommandList &command_list, uint64_t address, uint32_t options);
virtual bool Compile(const CompileContext &ctx);
virtual void AfterCompile(const CompileContext &ctx);
virtual void CompileLinks(const CompileContext &ctx);
virtual bool Init(const CompileContext &ctx);
virtual bool Prepare(const CompileContext &ctx);
virtual bool PrepareExtCommands(const CompileContext &ctx);
virtual void CompileInfo(const CompileContext &ctx);
IntelCommand *AddCommand(OperandSize value_size, uint64_t value);
IntelCommand *AddCommand(const std::string &value);
IntelCommand *AddCommand(const os::unicode_string &value);
IntelCommand *AddCommand(const Data &value);
IntelCommand *Add(uint64_t address);
IntelCommand *AddCommand(IntelCommandType type, IntelOperand operand1 = IntelOperand(), IntelOperand operand2 = IntelOperand(), IntelOperand operand3 = IntelOperand());
SectionCryptorList *section_cryptor_list() { return section_cryptor_list_; }
void AddWatermarkReference(uint64_t address, const std::string &value);
IntelCommand *GetCommandByAddress(uint64_t address) const;
IntelCommand *GetCommandByNearAddress(uint64_t address) const;
virtual void ReadFromBuffer(Buffer &buffer, IArchitecture &file);
bool ParseNewSEH(IArchitecture &file, uint64_t address);
bool ParseCxxSEH(IArchitecture &file, uint64_t address);
bool ParseCompressedCxxSEH(IArchitecture &file, uint64_t address, uint64_t begin);
bool ParseScopeSEH(IArchitecture &file, uint64_t address, uint32_t table_count);
virtual IntelCommand *ParseCommand(IArchitecture &file, uint64_t address, bool dump_mode = false);
uint64_t ParseParam(IArchitecture &file, size_t index, uint64_t ¶m_reference);
protected:
virtual IntelCommand *CreateCommand();
virtual IntelCommand *ParseString(IArchitecture &file, uint64_t address, size_t len);
virtual void ParseBeginCommands(IArchitecture &file);
virtual void ParseEndCommands(IArchitecture &file);
virtual uint64_t GetNextAddress(IArchitecture &file);
virtual IntelFunction *CreateFunction(IFunction *parent = NULL) { return new IntelFunction(NULL, cpu_address_size(), parent); }
void CompileToNative(const CompileContext &ctx);
void CompileToVM(const CompileContext &ctx);
void CreateBlocks();
private:
bool ParseFilterSEH(IArchitecture &file, uint64_t address);
bool ParseSwitch(IArchitecture &file, uint64_t address, OperandSize value_size, uint64_t add_value, IntelCommand *parent_command, size_t mode, size_t max_table_count);
bool ParseSEH3(IArchitecture &file, uint64_t address);
bool ParseSEH4(IArchitecture &file, uint64_t address);
bool ParseVB6SEH(IArchitecture &file, uint64_t address);
bool ParseBCBSEH(IArchitecture &file, uint64_t address, uint64_t next_address, uint8_t version);
bool ParseDelphiSEH(IArchitecture &file, uint64_t address);
CompilerFunction *ParseCompilerFunction(IArchitecture &file, uint64_t address);
IntelCommand *AddGate(ICommand *to_command, AddressRange *address_range);
IntelCommand *AddShortGate(ICommand *to_command, AddressRange *address_range);
uint64_t GetRegistrValue(uint8_t reg, size_t end_index);
uint64_t GetRegistrMaxValue(uint8_t reg, size_t end_index, IArchitecture &file);
void GetFreeRegisters(size_t index, CommandInfoList &command_info_list) const;
void Mutate(const CompileContext &ctx, bool for_virtualization, int index = 0);
SectionCryptorList *section_cryptor_list_;
std::set<uint64_t> break_case_list_;
// no copy ctr or assignment op
IntelFunction(const IntelFunction &);
IntelFunction &operator =(const IntelFunction &);
};
class IntelStack;
class IntelFlagsValue;
enum ValueType {
vtNone = 0,
vtValue = 1,
vtRegistr = 2,
vtReturnAddress = 4
};
class IntelStackValue : public IObject
{
public:
IntelStackValue(IntelStack *owner, ValueType type, uint64_t value);
~IntelStackValue();
ValueType type() const { return type_; }
uint64_t value() const { return value_; }
void set_value(uint64_t value) { value_ = value; }
bool is_modified() const { return is_modified_; }
void set_is_modified(bool value) { is_modified_ = value; }
void Calc(IntelCommandType command_type, uint16_t command_flags, bool inverse_flags, OperandSize size, uint64_t op2, IntelFlagsValue *flags);
private:
IntelStack *owner_;
ValueType type_;
uint64_t value_;
bool is_modified_;
};
class IntelStack : public ObjectList<IntelStackValue>
{
public:
IntelStack();
IntelStackValue *Add(ValueType type, uint64_t value);
IntelStackValue *Insert(size_t index, ValueType type, uint64_t value);
IntelStackValue *GetRegistr(uint8_t reg) const;
IntelStackValue *GetRandom(uint32_t types);
};
class IntelRegistrValue : public IntelStackValue
{
public:
IntelRegistrValue(IntelStack *owner, uint8_t registr, uint64_t value)
: IntelStackValue(owner, vtValue, value), registr_(registr) { }
uint8_t registr() const { return registr_; }
private:
uint8_t registr_;
};
class IntelFlagsValue : public IObject
{
public:
IntelFlagsValue();
uint32_t mask() const { return mask_; }
uint32_t value() const { return value_; }
void Calc(IntelCommandType command_type, OperandSize size, uint64_t op1, uint64_t op2, uint64_t result);
uint16_t GetRandom() const;
bool Check(uint16_t flags) const;
void clear() {
mask_ = 0;
value_ = 0;
}
private:
void exclude(uint16_t mask);
uint32_t mask_;
uint32_t value_;
};
class IntelRegistrStorage : public IntelStack
{
public:
IntelRegistrStorage();
IntelRegistrValue *item(size_t index) const;
IntelRegistrValue *GetRegistr(uint8_t reg) const;
IntelRegistrValue *Add(uint8_t reg, uint64_t value);
};
class IntelObfuscation : public IObject
{
public:
explicit IntelObfuscation();
void Compile(IntelFunction *func, size_t index, size_t end_index = -1, bool for_virtualization = false);
private:
IntelCommand *AddCommand(IntelCommandType type, IntelOperand operand1 = IntelOperand(), IntelOperand operand2 = IntelOperand(), IntelOperand operand3 = IntelOperand());
void AddRandomCommands();
void AddRestoreStack(size_t to_index);
void AddRestoreRegistr(uint8_t reg);
void AddRestoreStackItem(IntelStackValue *stack_item);
void CompileOperand(IntelOperand *operand);
IntelFunction *func_;
AddressRange *address_range_;
std::vector<IntelCommand *> command_list_;
IntelStack stack_;
IntelRegistrStorage registr_values_;
IntelFlagsValue flags_;
std::map<IntelCommand *, size_t> jmp_command_list_;
};
class IntelFileHelper : public IObject
{
public:
explicit IntelFileHelper();
~IntelFileHelper();
void Parse(IArchitecture &file);
private:
void AddMarker(IArchitecture &file, uint64_t address, uint64_t name_reference, uint64_t name_address, ObjectType type, uint8_t tag, bool is_unicode);
void AddString(IArchitecture &file, uint64_t address, uint64_t reference, bool is_unicode);
void AddEndMarker(IArchitecture &file, uint64_t address, uint64_t next_address, ObjectType type);
std::vector<MapFunction *> string_list_;
MapFunctionList *marker_name_list_;
size_t marker_index_;
// no copy ctr or assignment op
IntelFileHelper(const IntelFileHelper &);
IntelFileHelper &operator =(const IntelFileHelper &);
};
class IntelSDK : public IntelFunction
{
public:
explicit IntelSDK(IFunctionList *owner, OperandSize cpu_address_size);
virtual bool Init(const CompileContext &ctx);
};
class PEIntelSDK : public IntelSDK
{
public:
explicit PEIntelSDK(IFunctionList *owner, OperandSize cpu_address_size);
virtual bool Init(const CompileContext &ctx);
};
class PEIntelExport : public IntelFunction
{
public:
explicit PEIntelExport(IFunctionList *owner, OperandSize cpu_address_size);
virtual bool Init(const CompileContext &ctx);
virtual bool Compile(const CompileContext &ctx);
uint32_t size() const { return size_; }
private:
uint32_t size_;
};
class PEImportFunction;
class IntelImport : public IntelFunction
{
public:
explicit IntelImport(IFunctionList *owner, OperandSize cpu_address_size);
bool Init(const CompileContext &ctx);
IntelCommand *GetIATCommand(PEImportFunction *import_function) const;
private:
struct IATInfo {
PEImportFunction *import_function;
IntelCommand *command;
bool from_runtime;
};
std::vector<IATInfo> iat_info_list_;
};
class IntelCRCTable : public IntelFunction
{
public:
explicit IntelCRCTable(IFunctionList *owner, OperandSize cpu_address_size);
virtual bool Init(const CompileContext &ctx);
size_t table_size() const { return (count() - 2) * OperandSizeToValue(osDWord); }
IntelCommand *table_entry() const { return item(0); }
IntelCommand *size_entry() const { return size_entry_; }
IntelCommand *hash_entry() const { return hash_entry_; }
private:
IntelCommand *size_entry_;
IntelCommand *hash_entry_;
};
class IntelRuntimeData : public IntelFunction
{
public:
explicit IntelRuntimeData(IFunctionList *owner, OperandSize cpu_address_size);
virtual bool Init(const CompileContext &ctx);
virtual size_t WriteToFile(IArchitecture &file);
private:
RC5Key rc5_key_;
uint32_t data_key_;
IntelCommand *strings_entry_;
uint32_t strings_size_;
IntelCommand *resources_entry_;
uint32_t resources_size_;
IntelCommand *trial_hwid_entry_;
uint32_t trial_hwid_size_;
#ifdef ULTIMATE
IntelCommand *license_data_entry_;
uint32_t license_data_size_;
IntelCommand *files_entry_;
uint32_t files_size_;
IntelCommand *registry_entry_;
uint32_t registry_size_;
#endif
struct CommandCompareHelper {
bool operator () (const IntelCommand *left, IntelCommand *right) const;
};
};
class IntelLoaderData : public IntelFunction
{
public: