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
|
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYDIS_INTERNAL_SHAREDDATA_H
#define ZYDIS_INTERNAL_SHAREDDATA_H
#include "zydis/Zycore/Defines.h"
#include "zydis/Zydis/Mnemonic.h"
#include "zydis/Zydis/Register.h"
#include "zydis/Zydis/SharedTypes.h"
#include "zydis/Zydis/DecoderTypes.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
// MSVC does not like types other than (un-)signed int for bit-fields
#ifdef ZYAN_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisSemanticOperandType` enum.
*/
typedef enum ZydisSemanticOperandType_
{
ZYDIS_SEMANTIC_OPTYPE_UNUSED,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_REG,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_MEM,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_IMM1,
ZYDIS_SEMANTIC_OPTYPE_GPR8,
ZYDIS_SEMANTIC_OPTYPE_GPR16,
ZYDIS_SEMANTIC_OPTYPE_GPR32,
ZYDIS_SEMANTIC_OPTYPE_GPR64,
ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64,
ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64,
ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32,
ZYDIS_SEMANTIC_OPTYPE_GPR_ASZ,
ZYDIS_SEMANTIC_OPTYPE_FPR,
ZYDIS_SEMANTIC_OPTYPE_MMX,
ZYDIS_SEMANTIC_OPTYPE_XMM,
ZYDIS_SEMANTIC_OPTYPE_YMM,
ZYDIS_SEMANTIC_OPTYPE_ZMM,
ZYDIS_SEMANTIC_OPTYPE_TMM,
ZYDIS_SEMANTIC_OPTYPE_BND,
ZYDIS_SEMANTIC_OPTYPE_SREG,
ZYDIS_SEMANTIC_OPTYPE_CR,
ZYDIS_SEMANTIC_OPTYPE_DR,
ZYDIS_SEMANTIC_OPTYPE_MASK,
ZYDIS_SEMANTIC_OPTYPE_MEM,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBX,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBY,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ,
ZYDIS_SEMANTIC_OPTYPE_IMM,
ZYDIS_SEMANTIC_OPTYPE_REL,
ZYDIS_SEMANTIC_OPTYPE_PTR,
ZYDIS_SEMANTIC_OPTYPE_AGEN,
ZYDIS_SEMANTIC_OPTYPE_MOFFS,
ZYDIS_SEMANTIC_OPTYPE_MIB,
/**
* Maximum value of this enum.
*/
ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE = ZYDIS_SEMANTIC_OPTYPE_MIB,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE)
} ZydisSemanticOperandType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalElementType` enum.
*/
typedef enum ZydisInternalElementType_
{
ZYDIS_IELEMENT_TYPE_INVALID,
ZYDIS_IELEMENT_TYPE_VARIABLE,
ZYDIS_IELEMENT_TYPE_STRUCT,
ZYDIS_IELEMENT_TYPE_INT,
ZYDIS_IELEMENT_TYPE_UINT,
ZYDIS_IELEMENT_TYPE_INT1,
ZYDIS_IELEMENT_TYPE_INT8,
ZYDIS_IELEMENT_TYPE_INT16,
ZYDIS_IELEMENT_TYPE_INT32,
ZYDIS_IELEMENT_TYPE_INT64,
ZYDIS_IELEMENT_TYPE_UINT8,
ZYDIS_IELEMENT_TYPE_UINT16,
ZYDIS_IELEMENT_TYPE_UINT32,
ZYDIS_IELEMENT_TYPE_UINT64,
ZYDIS_IELEMENT_TYPE_UINT128,
ZYDIS_IELEMENT_TYPE_UINT256,
ZYDIS_IELEMENT_TYPE_FLOAT16,
ZYDIS_IELEMENT_TYPE_FLOAT16X2,
ZYDIS_IELEMENT_TYPE_FLOAT32,
ZYDIS_IELEMENT_TYPE_FLOAT64,
ZYDIS_IELEMENT_TYPE_FLOAT80,
ZYDIS_IELEMENT_TYPE_BCD80,
ZYDIS_IELEMENT_TYPE_CC3,
ZYDIS_IELEMENT_TYPE_CC5,
/**
* Maximum value of this enum.
*/
ZYDIS_IELEMENT_TYPE_MAX_VALUE = ZYDIS_IELEMENT_TYPE_CC5,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IELEMENT_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_TYPE_MAX_VALUE)
} ZydisInternalElementType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisImplicitRegisterType` enum.
*/
typedef enum ZydisImplicitRegisterType_
{
// TODO: Rename OSZ|ASZ|SSZ_
ZYDIS_IMPLREG_TYPE_STATIC,
ZYDIS_IMPLREG_TYPE_GPR_OSZ,
ZYDIS_IMPLREG_TYPE_GPR_ASZ,
ZYDIS_IMPLREG_TYPE_IP_ASZ,
ZYDIS_IMPLREG_TYPE_IP_SSZ,
ZYDIS_IMPLREG_TYPE_GPR_SSZ,
ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
/**
* Maximum value of this enum.
*/
ZYDIS_IMPLREG_TYPE_MAX_VALUE = ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IMPLREG_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLREG_TYPE_MAX_VALUE)
} ZydisImplicitRegisterType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisImplicitMemBase` enum.
*/
typedef enum ZydisImplicitMemBase_
{
// TODO: Rename OSZ|ASZ|SSZ_
ZYDIS_IMPLMEM_BASE_AGPR_REG,
ZYDIS_IMPLMEM_BASE_AGPR_RM,
ZYDIS_IMPLMEM_BASE_AAX,
ZYDIS_IMPLMEM_BASE_ADX,
ZYDIS_IMPLMEM_BASE_ABX,
ZYDIS_IMPLMEM_BASE_ASI,
ZYDIS_IMPLMEM_BASE_ADI,
ZYDIS_IMPLMEM_BASE_SSP,
ZYDIS_IMPLMEM_BASE_SBP,
/**
* Maximum value of this enum.
*/
ZYDIS_IMPLMEM_BASE_MAX_VALUE = ZYDIS_IMPLMEM_BASE_SBP,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IMPLMEM_BASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLMEM_BASE_MAX_VALUE)
} ZydisImplicitMemBase;
/* ---------------------------------------------------------------------------------------------- */
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ACTION_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_REGISTER_REQUIRED_BITS <= 16);
ZYAN_STATIC_ASSERT(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisOperandDefinition` struct.
*/
typedef struct ZydisOperandDefinition_
{
ZyanU8 type ZYAN_BITFIELD(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS);
ZyanU8 visibility ZYAN_BITFIELD(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS);
ZyanU8 actions ZYAN_BITFIELD(ZYDIS_OPERAND_ACTION_REQUIRED_BITS);
ZyanU16 size[3];
ZyanU8 element_type ZYAN_BITFIELD(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS);
union
{
ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS);
struct
{
ZyanU8 type ZYAN_BITFIELD(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS);
union
{
ZyanU16 reg ZYAN_BITFIELD(ZYDIS_REGISTER_REQUIRED_BITS);
ZyanU8 id ZYAN_BITFIELD(6);
} reg;
} reg;
struct
{
ZyanU8 seg ZYAN_BITFIELD(3);
ZyanU8 base ZYAN_BITFIELD(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS);
} mem;
} op;
ZyanBool is_multisource4 ZYAN_BITFIELD(1);
ZyanBool ignore_seg_override ZYAN_BITFIELD(1);
} ZydisOperandDefinition;
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisReadWriteAction` enum.
*/
typedef enum ZydisReadWriteAction_
{
ZYDIS_RW_ACTION_NONE,
ZYDIS_RW_ACTION_READ,
ZYDIS_RW_ACTION_WRITE,
ZYDIS_RW_ACTION_READWRITE,
/**
* Maximum value of this enum.
*/
ZYDIS_RW_ACTION_MAX_VALUE = ZYDIS_RW_ACTION_READWRITE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_RW_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_RW_ACTION_MAX_VALUE)
} ZydisReadWriteAction;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalVectorLength` enum.
*/
typedef enum ZydisInternalVectorLength_
{
ZYDIS_IVECTOR_LENGTH_DEFAULT,
ZYDIS_IVECTOR_LENGTH_FIXED_128,
ZYDIS_IVECTOR_LENGTH_FIXED_256,
ZYDIS_IVECTOR_LENGTH_FIXED_512,
/**
* Maximum value of this enum.
*/
ZYDIS_IVECTOR_LENGTH_MAX_VALUE = ZYDIS_IVECTOR_LENGTH_FIXED_512,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IVECTOR_LENGTH_MAX_VALUE)
} ZydisInternalVectorLength;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalElementSize` enum.
*/
typedef enum ZydisInternalElementSize_
{
ZYDIS_IELEMENT_SIZE_INVALID,
ZYDIS_IELEMENT_SIZE_8,
ZYDIS_IELEMENT_SIZE_16,
ZYDIS_IELEMENT_SIZE_32,
ZYDIS_IELEMENT_SIZE_64,
ZYDIS_IELEMENT_SIZE_128,
/**
* Maximum value of this enum.
*/
ZYDIS_IELEMENT_SIZE_MAX_VALUE = ZYDIS_IELEMENT_SIZE_128,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IELEMENT_SIZE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_SIZE_MAX_VALUE)
} ZydisInternalElementSize;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXFunctionality` enum.
*/
typedef enum ZydisEVEXFunctionality_
{
ZYDIS_EVEX_FUNC_INVALID,
/**
* `EVEX.b` enables broadcast functionality.
*/
ZYDIS_EVEX_FUNC_BC,
/**
* `EVEX.b` enables embedded-rounding functionality.
*/
ZYDIS_EVEX_FUNC_RC,
/**
* `EVEX.b` enables sae functionality.
*/
ZYDIS_EVEX_FUNC_SAE,
/**
* Maximum value of this enum.
*/
ZYDIS_EVEX_FUNC_MAX_VALUE = ZYDIS_EVEX_FUNC_SAE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_EVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_FUNC_MAX_VALUE)
} ZydisEVEXFunctionality;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXTupleType` enum.
*/
typedef enum ZydisEVEXTupleType_
{
ZYDIS_TUPLETYPE_INVALID,
/**
* Full Vector
*/
ZYDIS_TUPLETYPE_FV,
/**
* Half Vector
*/
ZYDIS_TUPLETYPE_HV,
/**
* Full Vector Mem
*/
ZYDIS_TUPLETYPE_FVM,
/**
* Tuple1 Scalar
*/
ZYDIS_TUPLETYPE_T1S,
/**
* Tuple1 Fixed
*/
ZYDIS_TUPLETYPE_T1F,
/**
* Tuple1 4x32
*/
ZYDIS_TUPLETYPE_T1_4X,
/**
* Gather / Scatter
*/
ZYDIS_TUPLETYPE_GSCAT,
/**
* Tuple2
*/
ZYDIS_TUPLETYPE_T2,
/**
* Tuple4
*/
ZYDIS_TUPLETYPE_T4,
/**
* Tuple8
*/
ZYDIS_TUPLETYPE_T8,
/**
* Half Mem
*/
ZYDIS_TUPLETYPE_HVM,
/**
* QuarterMem
*/
ZYDIS_TUPLETYPE_QVM,
/**
* OctMem
*/
ZYDIS_TUPLETYPE_OVM,
/**
* Mem128
*/
ZYDIS_TUPLETYPE_M128,
/**
* MOVDDUP
*/
ZYDIS_TUPLETYPE_DUP,
/**
* Quarter of the vector-length.
*/
ZYDIS_TUPLETYPE_QUARTER,
/**
* Maximum value of this enum.
*/
ZYDIS_TUPLETYPE_MAX_VALUE = ZYDIS_TUPLETYPE_QUARTER,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_TUPLETYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_TUPLETYPE_MAX_VALUE)
} ZydisEVEXTupleType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMVEXFunctionality` enum.
*/
typedef enum ZydisMVEXFunctionality_
{
/**
* The `MVEX.SSS` value is ignored.
*/
ZYDIS_MVEX_FUNC_IGNORED,
/**
* `MVEX.SSS` must be `000b`.
*/
ZYDIS_MVEX_FUNC_INVALID,
/**
* `MVEX.SSS` controls embedded-rounding functionality.
*/
ZYDIS_MVEX_FUNC_RC,
/**
* `MVEX.SSS` controls sae functionality.
*/
ZYDIS_MVEX_FUNC_SAE,
/**
* No special operation (32bit float elements).
*/
ZYDIS_MVEX_FUNC_F_32,
/**
* No special operation (32bit uint elements).
*/
ZYDIS_MVEX_FUNC_I_32,
/**
* No special operation (64bit float elements).
*/
ZYDIS_MVEX_FUNC_F_64,
/**
* No special operation (64bit uint elements).
*/
ZYDIS_MVEX_FUNC_I_64,
/**
* Sf32(reg) or Si32(reg).
*/
ZYDIS_MVEX_FUNC_SWIZZLE_32,
/**
* Sf64(reg) or Si64(reg).
*/
ZYDIS_MVEX_FUNC_SWIZZLE_64,
/**
* Sf32(mem).
*/
ZYDIS_MVEX_FUNC_SF_32,
/**
* Sf32(mem) broadcast only.
*/
ZYDIS_MVEX_FUNC_SF_32_BCST,
/**
* Sf32(mem) broadcast 4to16 only.
*/
ZYDIS_MVEX_FUNC_SF_32_BCST_4TO16,
/**
* Sf64(mem).
*/
ZYDIS_MVEX_FUNC_SF_64,
/**
* Si32(mem).
*/
ZYDIS_MVEX_FUNC_SI_32,
/**
* Si32(mem) broadcast only.
*/
ZYDIS_MVEX_FUNC_SI_32_BCST,
/**
* Si32(mem) broadcast 4to16 only.
*/
ZYDIS_MVEX_FUNC_SI_32_BCST_4TO16,
/**
* Si64(mem).
*/
ZYDIS_MVEX_FUNC_SI_64,
/**
* Uf32.
*/
ZYDIS_MVEX_FUNC_UF_32,
/**
* Uf64.
*/
ZYDIS_MVEX_FUNC_UF_64,
/**
* Ui32.
*/
ZYDIS_MVEX_FUNC_UI_32,
/**
* Ui64.
*/
ZYDIS_MVEX_FUNC_UI_64,
/**
* Df32.
*/
ZYDIS_MVEX_FUNC_DF_32,
/**
* Df64.
*/
ZYDIS_MVEX_FUNC_DF_64,
/**
* Di32.
*/
ZYDIS_MVEX_FUNC_DI_32,
/**
* Di64.
*/
ZYDIS_MVEX_FUNC_DI_64,
/**
* Maximum value of this enum.
*/
ZYDIS_MVEX_FUNC_MAX_VALUE = ZYDIS_MVEX_FUNC_DI_64,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_FUNC_MAX_VALUE)
} ZydisMVEXFunctionality;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisVEXStaticBroadcast` enum.
*/
typedef enum ZydisVEXStaticBroadcast
{
ZYDIS_VEX_STATIC_BROADCAST_NONE,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_2,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_4,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_32,
ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
/**
* Maximum value of this enum.
*/
ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXStaticBroadcast` enum.
*/
typedef enum ZydisEVEXStaticBroadcast_
{
ZYDIS_EVEX_STATIC_BROADCAST_NONE,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_2,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_4,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_32,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_64,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_4,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_4_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_4_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
/**
* Maximum value of this enum.
*/
ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisEVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMVEXStaticBroadcast` enum.
*/
typedef enum ZydisMVEXStaticBroadcast_
{
ZYDIS_MVEX_STATIC_BROADCAST_NONE,
ZYDIS_MVEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_MVEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_MVEX_STATIC_BROADCAST_4_TO_8,
ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
/**
* Maximum value of this enum.
*/
ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisMVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMaskPolicy` enum.
*/
typedef enum ZydisMaskPolicy_
{
ZYDIS_MASK_POLICY_INVALID,
/**
* The instruction accepts mask-registers other than the default-mask (K0), but
* does not require them.
*/
ZYDIS_MASK_POLICY_ALLOWED,
/**
* The instruction requires a mask-register other than the default-mask (K0).
*/
ZYDIS_MASK_POLICY_REQUIRED,
/**
* The instruction does not allow a mask-register other than the default-mask (K0).
*/
ZYDIS_MASK_POLICY_FORBIDDEN,
/**
* Maximum value of this enum.
*/
ZYDIS_MASK_POLICY_MAX_VALUE = ZYDIS_MASK_POLICY_FORBIDDEN,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MASK_POLICY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_POLICY_MAX_VALUE)
} ZydisMaskPolicy;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMaskOverride` enum.
*/
typedef enum ZydisMaskOverride_
{
ZYDIS_MASK_OVERRIDE_DEFAULT,
ZYDIS_MASK_OVERRIDE_ZEROING,
ZYDIS_MASK_OVERRIDE_CONTROL,
/**
* Maximum value of this enum.
*/
ZYDIS_MASK_OVERRIDE_MAX_VALUE = ZYDIS_MASK_OVERRIDE_CONTROL,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MASK_OVERRIDE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_OVERRIDE_MAX_VALUE)
} ZydisMaskOverride;
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_OPDEF_REQUIRED_BITS \
ZYAN_MAX(ZYDIS_REGKIND_REQUIRED_BITS, ZYDIS_MEMOP_TYPE_REQUIRED_BITS + 1) + 1
#define ZYDIS_OPDEF_GET_REG(operand_definition) \
((operand_definition) & ((1 << ZYDIS_REGKIND_REQUIRED_BITS ) - 1))
#define ZYDIS_OPDEF_GET_MEM(operand_definition) \
((operand_definition) & ((1 << ZYDIS_MEMOP_TYPE_REQUIRED_BITS) - 1))
#define ZYDIS_OPDEF_GET_REG_HIGH_BIT(operand_definition) \
(((operand_definition) >> ZYDIS_REGKIND_REQUIRED_BITS ) & 0x01)
#define ZYDIS_OPDEF_GET_MEM_HIGH_BIT(operand_definition) \
(((operand_definition) >> ZYDIS_MEMOP_TYPE_REQUIRED_BITS) & 0x01)
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_MNEMONIC_REQUIRED_BITS <= 16);
ZYAN_STATIC_ASSERT(ZYDIS_CATEGORY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_ISA_SET_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_ISA_EXT_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_BRANCH_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPDEF_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_RW_ACTION_REQUIRED_BITS <= 8);
#ifndef ZYDIS_MINIMAL_MODE
# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
ZyanU8 operand_count ZYAN_BITFIELD( 4); \
ZyanU8 operand_count_visible ZYAN_BITFIELD( 3); \
ZyanU16 operand_reference ZYAN_BITFIELD(15); \
ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
ZyanU8 flags_reference ZYAN_BITFIELD( 7); \
ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \
ZyanU8 category ZYAN_BITFIELD(ZYDIS_CATEGORY_REQUIRED_BITS); \
ZyanU8 isa_set ZYAN_BITFIELD(ZYDIS_ISA_SET_REQUIRED_BITS); \
ZyanU8 isa_ext ZYAN_BITFIELD(ZYDIS_ISA_EXT_REQUIRED_BITS); \
ZyanU8 branch_type ZYAN_BITFIELD(ZYDIS_BRANCH_TYPE_REQUIRED_BITS); \
ZyanU8 exception_class ZYAN_BITFIELD(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS); \
ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
ZyanU8 cpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
ZyanU8 fpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
ZyanU8 xmm_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
ZyanBool accepts_segment ZYAN_BITFIELD( 1)
#else
# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \
ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS)
#endif
#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR \
ZYDIS_INSTRUCTION_DEFINITION_BASE; \
ZyanU8 op_ndsndd ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS)
#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL \
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR; \
ZyanBool is_gather ZYAN_BITFIELD( 1); \
ZyanBool no_source_dest_match ZYAN_BITFIELD( 1); \
ZyanBool no_source_source_match ZYAN_BITFIELD( 1) // TODO: Could be moved to VEX
/**
* Defines the `ZydisInstructionDefinition` struct.
*/
typedef struct ZydisInstructionDefinition_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
} ZydisInstructionDefinition;
/**
* Defines the `ZydisInstructionDefinitionLEGACY` struct.
*/
typedef struct ZydisInstructionDefinitionLEGACY_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool is_privileged ZYAN_BITFIELD( 1);
#endif
ZyanBool accepts_LOCK ZYAN_BITFIELD( 1);
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool accepts_REP ZYAN_BITFIELD( 1);
ZyanBool accepts_REPEREPZ ZYAN_BITFIELD( 1);
ZyanBool accepts_REPNEREPNZ ZYAN_BITFIELD( 1);
ZyanBool accepts_BOUND ZYAN_BITFIELD( 1);
ZyanBool accepts_XACQUIRE ZYAN_BITFIELD( 1);
ZyanBool accepts_XRELEASE ZYAN_BITFIELD( 1);
ZyanBool accepts_NOTRACK ZYAN_BITFIELD( 1);
ZyanBool accepts_hle_without_lock ZYAN_BITFIELD( 1);
ZyanBool accepts_branch_hints ZYAN_BITFIELD( 1);
#endif
} ZydisInstructionDefinitionLEGACY;
/**
* Defines the `ZydisInstructionDefinition3DNOW` struct.
*/
typedef struct ZydisInstructionDefinition3DNOW_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
} ZydisInstructionDefinition3DNOW;
/**
* Defines the `ZydisInstructionDefinitionXOP` struct.
*/
typedef struct ZydisInstructionDefinitionXOP_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR;
} ZydisInstructionDefinitionXOP;
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionVEX` struct.
*/
typedef struct ZydisInstructionDefinitionVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionVEX;
#ifndef ZYDIS_DISABLE_AVX512
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_TUPLETYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EVEX_FUNC_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionEVEX` struct.
*/
typedef struct ZydisInstructionDefinitionEVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS);
ZyanU8 tuple_type ZYAN_BITFIELD(ZYDIS_TUPLETYPE_REQUIRED_BITS);
ZyanU8 element_size ZYAN_BITFIELD(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS);
ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_EVEX_FUNC_REQUIRED_BITS);
#endif
ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
ZyanBool accepts_zero_mask ZYAN_BITFIELD( 1);
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 mask_override ZYAN_BITFIELD(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS);
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionEVEX;
#endif
#ifndef ZYDIS_DISABLE_KNC
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_MVEX_FUNC_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionMVEX` struct.
*/
typedef struct ZydisInstructionDefinitionMVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_MVEX_FUNC_REQUIRED_BITS);
ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool has_element_granularity ZYAN_BITFIELD( 1);
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionMVEX;
#endif
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYAN_MSVC
# pragma warning(pop)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU/FPU flags */
/* ---------------------------------------------------------------------------------------------- */
/*
* Contains information about the CPU/FPU flags accessed by an instruction.
*
* We don't want this struct to be packed! A pointer to the individual members will be used by the
* `ZydisDecodedInstruction` struct.
*/
typedef struct ZydisDefinitionAccessedFlags_
{
ZydisAccessedFlags cpu_flags;
ZydisAccessedFlags fpu_flags;
} ZydisDefinitionAccessedFlags;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the instruction-definition with the given `encoding` and `id`.
*
* @param encoding The instruction-encoding.
* @param id The definition-id.
* @param definition A pointer to the variable that receives a pointer to the instruction-
* definition.
*/
ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding,
ZyanU16 id, const ZydisInstructionDefinition** definition);
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the the operand-definitions for the given instruction-`definition`.
*
* @param definition A pointer to the instruction-definition.
*
* @return A pointer to the first operand definition of the instruction, or `ZYAN_NULL`.
*/
ZYDIS_NO_EXPORT const ZydisOperandDefinition* ZydisGetOperandDefinitions(
const ZydisInstructionDefinition* definition);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the actual type and size of an internal element-type.
*
* @param element The internal element type.
* @param type The actual element type.
* @param size The element size.
*/
ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
ZydisElementSize* size);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the the operand-definitions for the given instruction-`definition`.
*
* @param definition A pointer to the instruction-definition.
* @param flags A pointer to the variable that receives the `ZydisDefinitionAccessedFlags`
* struct.
*
* @return `ZYAN_TRUE`, if the instruction accesses any flags, or `ZYAN_FALSE`, if not.
*/
ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
const ZydisDefinitionAccessedFlags** flags);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_INTERNAL_SHAREDDATA_H */
|