Zydis: include/Zydis/Internal/SharedData.h Source File

Zydis v4.0.0

Loading...
Searching...
No Matches
SharedData.h
1/***************************************************************************************************
2
3 Zyan Disassembler Library (Zydis)
4
5 Original Author : Florian Bernd
6
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24
25***************************************************************************************************/
26
27#ifndef ZYDIS_INTERNAL_SHAREDDATA_H
28#define ZYDIS_INTERNAL_SHAREDDATA_H
29
30#include <Zycore/Defines.h>
31#include <Zydis/Mnemonic.h>
32#include <Zydis/Register.h>
33#include <Zydis/SharedTypes.h>
34#include <Zydis/DecoderTypes.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/* ============================================================================================== */
41/* Enums and types */
42/* ============================================================================================== */
43
44// MSVC does not like types other than (un-)signed int for bit-fields
45#ifdef ZYAN_MSVC
46# pragma warning(push)
47# pragma warning(disable:4214)
48#endif
49
50#pragma pack(push, 1)
51
52/* ---------------------------------------------------------------------------------------------- */
53/* Operand definition */
54/* ---------------------------------------------------------------------------------------------- */
55
59typedef enum ZydisSemanticOperandType_
60{
61 ZYDIS_SEMANTIC_OPTYPE_UNUSED,
62 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_REG,
63 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_MEM,
64 ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_IMM1,
65 ZYDIS_SEMANTIC_OPTYPE_GPR8,
66 ZYDIS_SEMANTIC_OPTYPE_GPR16,
67 ZYDIS_SEMANTIC_OPTYPE_GPR32,
68 ZYDIS_SEMANTIC_OPTYPE_GPR64,
69 ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64,
70 ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64,
71 ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32,
72 ZYDIS_SEMANTIC_OPTYPE_GPR_ASZ,
73 ZYDIS_SEMANTIC_OPTYPE_FPR,
74 ZYDIS_SEMANTIC_OPTYPE_MMX,
75 ZYDIS_SEMANTIC_OPTYPE_XMM,
76 ZYDIS_SEMANTIC_OPTYPE_YMM,
77 ZYDIS_SEMANTIC_OPTYPE_ZMM,
78 ZYDIS_SEMANTIC_OPTYPE_TMM,
79 ZYDIS_SEMANTIC_OPTYPE_BND,
80 ZYDIS_SEMANTIC_OPTYPE_SREG,
81 ZYDIS_SEMANTIC_OPTYPE_CR,
82 ZYDIS_SEMANTIC_OPTYPE_DR,
83 ZYDIS_SEMANTIC_OPTYPE_MASK,
84 ZYDIS_SEMANTIC_OPTYPE_MEM,
85 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBX,
86 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBY,
87 ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ,
88 ZYDIS_SEMANTIC_OPTYPE_IMM,
89 ZYDIS_SEMANTIC_OPTYPE_REL,
90 ZYDIS_SEMANTIC_OPTYPE_PTR,
91 ZYDIS_SEMANTIC_OPTYPE_AGEN,
92 ZYDIS_SEMANTIC_OPTYPE_MOFFS,
93 ZYDIS_SEMANTIC_OPTYPE_MIB,
94
98 ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE = ZYDIS_SEMANTIC_OPTYPE_MIB,
102 ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE)
103} ZydisSemanticOperandType;
104
105/* ---------------------------------------------------------------------------------------------- */
106
110typedef enum ZydisInternalElementType_
111{
112 ZYDIS_IELEMENT_TYPE_INVALID,
113 ZYDIS_IELEMENT_TYPE_VARIABLE,
114 ZYDIS_IELEMENT_TYPE_STRUCT,
115 ZYDIS_IELEMENT_TYPE_INT,
116 ZYDIS_IELEMENT_TYPE_UINT,
117 ZYDIS_IELEMENT_TYPE_INT1,
118 ZYDIS_IELEMENT_TYPE_INT8,
119 ZYDIS_IELEMENT_TYPE_INT16,
120 ZYDIS_IELEMENT_TYPE_INT32,
121 ZYDIS_IELEMENT_TYPE_INT64,
122 ZYDIS_IELEMENT_TYPE_UINT8,
123 ZYDIS_IELEMENT_TYPE_UINT16,
124 ZYDIS_IELEMENT_TYPE_UINT32,
125 ZYDIS_IELEMENT_TYPE_UINT64,
126 ZYDIS_IELEMENT_TYPE_UINT128,
127 ZYDIS_IELEMENT_TYPE_UINT256,
128 ZYDIS_IELEMENT_TYPE_FLOAT16,
129 ZYDIS_IELEMENT_TYPE_FLOAT16X2,
130 ZYDIS_IELEMENT_TYPE_FLOAT32,
131 ZYDIS_IELEMENT_TYPE_FLOAT64,
132 ZYDIS_IELEMENT_TYPE_FLOAT80,
133 ZYDIS_IELEMENT_TYPE_BCD80,
134 ZYDIS_IELEMENT_TYPE_CC3,
135 ZYDIS_IELEMENT_TYPE_CC5,
136
140 ZYDIS_IELEMENT_TYPE_MAX_VALUE = ZYDIS_IELEMENT_TYPE_CC5,
144 ZYDIS_IELEMENT_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_TYPE_MAX_VALUE)
145} ZydisInternalElementType;
146
147/* ---------------------------------------------------------------------------------------------- */
148
152typedef enum ZydisImplicitRegisterType_
153{
154 // TODO: Rename OSZ|ASZ|SSZ_
155 ZYDIS_IMPLREG_TYPE_STATIC,
156 ZYDIS_IMPLREG_TYPE_GPR_OSZ,
157 ZYDIS_IMPLREG_TYPE_GPR_ASZ,
158 ZYDIS_IMPLREG_TYPE_IP_ASZ,
159 ZYDIS_IMPLREG_TYPE_IP_SSZ,
160 ZYDIS_IMPLREG_TYPE_GPR_SSZ,
161 ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
162
166 ZYDIS_IMPLREG_TYPE_MAX_VALUE = ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
170 ZYDIS_IMPLREG_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLREG_TYPE_MAX_VALUE)
171} ZydisImplicitRegisterType;
172
173/* ---------------------------------------------------------------------------------------------- */
174
178typedef enum ZydisImplicitMemBase_
179{
180 // TODO: Rename OSZ|ASZ|SSZ_
181 ZYDIS_IMPLMEM_BASE_AGPR_REG,
182 ZYDIS_IMPLMEM_BASE_AGPR_RM,
183 ZYDIS_IMPLMEM_BASE_AAX,
184 ZYDIS_IMPLMEM_BASE_ADX,
185 ZYDIS_IMPLMEM_BASE_ABX,
186 ZYDIS_IMPLMEM_BASE_ASI,
187 ZYDIS_IMPLMEM_BASE_ADI,
188 ZYDIS_IMPLMEM_BASE_SSP,
189 ZYDIS_IMPLMEM_BASE_SBP,
190
194 ZYDIS_IMPLMEM_BASE_MAX_VALUE = ZYDIS_IMPLMEM_BASE_SBP,
198 ZYDIS_IMPLMEM_BASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLMEM_BASE_MAX_VALUE)
199} ZydisImplicitMemBase;
200
201/* ---------------------------------------------------------------------------------------------- */
202
203// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
204// enum types
205ZYAN_STATIC_ASSERT(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS <= 8);
206ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS <= 8);
207ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ACTION_REQUIRED_BITS <= 8);
208ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS <= 8);
209ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS <= 8);
210ZYAN_STATIC_ASSERT(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS <= 8);
211ZYAN_STATIC_ASSERT(ZYDIS_REGISTER_REQUIRED_BITS <= 16);
212ZYAN_STATIC_ASSERT(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS <= 8);
213
217 typedef struct ZydisOperandDefinition_
218{
219 ZyanU8 type ZYAN_BITFIELD(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS);
220 ZyanU8 visibility ZYAN_BITFIELD(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS);
221 ZyanU8 actions ZYAN_BITFIELD(ZYDIS_OPERAND_ACTION_REQUIRED_BITS);
222 ZyanU16 size[3];
223 ZyanU8 element_type ZYAN_BITFIELD(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS);
224 union
225 {
226 ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS);
227 struct
228 {
229 ZyanU8 type ZYAN_BITFIELD(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS);
230 union
231 {
232 ZyanU16 reg ZYAN_BITFIELD(ZYDIS_REGISTER_REQUIRED_BITS);
233 ZyanU8 id ZYAN_BITFIELD(6);
234 } reg;
235 } reg;
236 struct
237 {
238 ZyanU8 seg ZYAN_BITFIELD(3);
239 ZyanU8 base ZYAN_BITFIELD(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS);
240 } mem;
241 } op;
242 ZyanBool is_multisource4 ZYAN_BITFIELD(1);
243 ZyanBool ignore_seg_override ZYAN_BITFIELD(1);
244} ZydisOperandDefinition;
245
246/* ---------------------------------------------------------------------------------------------- */
247/* Instruction definition */
248/* ---------------------------------------------------------------------------------------------- */
249
253typedef enum ZydisReadWriteAction_
254{
255 ZYDIS_RW_ACTION_NONE,
256 ZYDIS_RW_ACTION_READ,
257 ZYDIS_RW_ACTION_WRITE,
258 ZYDIS_RW_ACTION_READWRITE,
259
263 ZYDIS_RW_ACTION_MAX_VALUE = ZYDIS_RW_ACTION_READWRITE,
267 ZYDIS_RW_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_RW_ACTION_MAX_VALUE)
268} ZydisReadWriteAction;
269
270/* ---------------------------------------------------------------------------------------------- */
271
275typedef enum ZydisInternalVectorLength_
276{
277 ZYDIS_IVECTOR_LENGTH_DEFAULT,
278 ZYDIS_IVECTOR_LENGTH_FIXED_128,
279 ZYDIS_IVECTOR_LENGTH_FIXED_256,
280 ZYDIS_IVECTOR_LENGTH_FIXED_512,
281
285 ZYDIS_IVECTOR_LENGTH_MAX_VALUE = ZYDIS_IVECTOR_LENGTH_FIXED_512,
289 ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IVECTOR_LENGTH_MAX_VALUE)
290} ZydisInternalVectorLength;
291
292/* ---------------------------------------------------------------------------------------------- */
293
297typedef enum ZydisInternalElementSize_
298{
299 ZYDIS_IELEMENT_SIZE_INVALID,
300 ZYDIS_IELEMENT_SIZE_8,
301 ZYDIS_IELEMENT_SIZE_16,
302 ZYDIS_IELEMENT_SIZE_32,
303 ZYDIS_IELEMENT_SIZE_64,
304 ZYDIS_IELEMENT_SIZE_128,
305
309 ZYDIS_IELEMENT_SIZE_MAX_VALUE = ZYDIS_IELEMENT_SIZE_128,
313 ZYDIS_IELEMENT_SIZE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_SIZE_MAX_VALUE)
314} ZydisInternalElementSize;
315
316/* ---------------------------------------------------------------------------------------------- */
317
321typedef enum ZydisEVEXFunctionality_
322{
323 ZYDIS_EVEX_FUNC_INVALID,
327 ZYDIS_EVEX_FUNC_BC,
331 ZYDIS_EVEX_FUNC_RC,
335 ZYDIS_EVEX_FUNC_SAE,
336
340 ZYDIS_EVEX_FUNC_MAX_VALUE = ZYDIS_EVEX_FUNC_SAE,
344 ZYDIS_EVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_FUNC_MAX_VALUE)
345} ZydisEVEXFunctionality;
346
347/* ---------------------------------------------------------------------------------------------- */
348
352typedef enum ZydisEVEXTupleType_
353{
354 ZYDIS_TUPLETYPE_INVALID,
358 ZYDIS_TUPLETYPE_FV,
362 ZYDIS_TUPLETYPE_HV,
366 ZYDIS_TUPLETYPE_FVM,
370 ZYDIS_TUPLETYPE_T1S,
374 ZYDIS_TUPLETYPE_T1F,
378 ZYDIS_TUPLETYPE_T1_4X,
382 ZYDIS_TUPLETYPE_GSCAT,
386 ZYDIS_TUPLETYPE_T2,
390 ZYDIS_TUPLETYPE_T4,
394 ZYDIS_TUPLETYPE_T8,
398 ZYDIS_TUPLETYPE_HVM,
402 ZYDIS_TUPLETYPE_QVM,
406 ZYDIS_TUPLETYPE_OVM,
410 ZYDIS_TUPLETYPE_M128,
414 ZYDIS_TUPLETYPE_DUP,
418 ZYDIS_TUPLETYPE_QUARTER,
419
423 ZYDIS_TUPLETYPE_MAX_VALUE = ZYDIS_TUPLETYPE_QUARTER,
427 ZYDIS_TUPLETYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_TUPLETYPE_MAX_VALUE)
428} ZydisEVEXTupleType;
429
430/* ---------------------------------------------------------------------------------------------- */
431
435typedef enum ZydisMVEXFunctionality_
436{
440 ZYDIS_MVEX_FUNC_IGNORED,
444 ZYDIS_MVEX_FUNC_INVALID,
448 ZYDIS_MVEX_FUNC_RC,
452 ZYDIS_MVEX_FUNC_SAE,
456 ZYDIS_MVEX_FUNC_F_32,
460 ZYDIS_MVEX_FUNC_I_32,
464 ZYDIS_MVEX_FUNC_F_64,
468 ZYDIS_MVEX_FUNC_I_64,
472 ZYDIS_MVEX_FUNC_SWIZZLE_32,
476 ZYDIS_MVEX_FUNC_SWIZZLE_64,
480 ZYDIS_MVEX_FUNC_SF_32,
484 ZYDIS_MVEX_FUNC_SF_32_BCST,
488 ZYDIS_MVEX_FUNC_SF_32_BCST_4TO16,
492 ZYDIS_MVEX_FUNC_SF_64,
496 ZYDIS_MVEX_FUNC_SI_32,
500 ZYDIS_MVEX_FUNC_SI_32_BCST,
504 ZYDIS_MVEX_FUNC_SI_32_BCST_4TO16,
508 ZYDIS_MVEX_FUNC_SI_64,
512 ZYDIS_MVEX_FUNC_UF_32,
516 ZYDIS_MVEX_FUNC_UF_64,
520 ZYDIS_MVEX_FUNC_UI_32,
524 ZYDIS_MVEX_FUNC_UI_64,
528 ZYDIS_MVEX_FUNC_DF_32,
532 ZYDIS_MVEX_FUNC_DF_64,
536 ZYDIS_MVEX_FUNC_DI_32,
540 ZYDIS_MVEX_FUNC_DI_64,
541
545 ZYDIS_MVEX_FUNC_MAX_VALUE = ZYDIS_MVEX_FUNC_DI_64,
549 ZYDIS_MVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_FUNC_MAX_VALUE)
550} ZydisMVEXFunctionality;
551
552/* ---------------------------------------------------------------------------------------------- */
553
557typedef enum ZydisVEXStaticBroadcast
558{
559 ZYDIS_VEX_STATIC_BROADCAST_NONE,
560 ZYDIS_VEX_STATIC_BROADCAST_1_TO_2,
561 ZYDIS_VEX_STATIC_BROADCAST_1_TO_4,
562 ZYDIS_VEX_STATIC_BROADCAST_1_TO_8,
563 ZYDIS_VEX_STATIC_BROADCAST_1_TO_16,
564 ZYDIS_VEX_STATIC_BROADCAST_1_TO_32,
565 ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
566
570 ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
574 ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS =
575 ZYAN_BITS_TO_REPRESENT(ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE)
576} ZydisVEXStaticBroadcast;
577
578/* ---------------------------------------------------------------------------------------------- */
579
583typedef enum ZydisEVEXStaticBroadcast_
584{
585 ZYDIS_EVEX_STATIC_BROADCAST_NONE,
586 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_2,
587 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_4,
588 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_8,
589 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_16,
590 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_32,
591 ZYDIS_EVEX_STATIC_BROADCAST_1_TO_64,
592 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_4,
593 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_8,
594 ZYDIS_EVEX_STATIC_BROADCAST_2_TO_16,
595 ZYDIS_EVEX_STATIC_BROADCAST_4_TO_8,
596 ZYDIS_EVEX_STATIC_BROADCAST_4_TO_16,
597 ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
598
602 ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
606 ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS =
607 ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE)
608} ZydisEVEXStaticBroadcast;
609
610/* ---------------------------------------------------------------------------------------------- */
611
615typedef enum ZydisMVEXStaticBroadcast_
616{
617 ZYDIS_MVEX_STATIC_BROADCAST_NONE,
618 ZYDIS_MVEX_STATIC_BROADCAST_1_TO_8,
619 ZYDIS_MVEX_STATIC_BROADCAST_1_TO_16,
620 ZYDIS_MVEX_STATIC_BROADCAST_4_TO_8,
621 ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
622
626 ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
630 ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS =
631 ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE)
632} ZydisMVEXStaticBroadcast;
633
634/* ---------------------------------------------------------------------------------------------- */
635
639typedef enum ZydisMaskPolicy_
640{
641 ZYDIS_MASK_POLICY_INVALID,
646 ZYDIS_MASK_POLICY_ALLOWED,
650 ZYDIS_MASK_POLICY_REQUIRED,
654 ZYDIS_MASK_POLICY_FORBIDDEN,
655
659 ZYDIS_MASK_POLICY_MAX_VALUE = ZYDIS_MASK_POLICY_FORBIDDEN,
663 ZYDIS_MASK_POLICY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_POLICY_MAX_VALUE)
664} ZydisMaskPolicy;
665
666/* ---------------------------------------------------------------------------------------------- */
667
671typedef enum ZydisMaskOverride_
672{
673 ZYDIS_MASK_OVERRIDE_DEFAULT,
674 ZYDIS_MASK_OVERRIDE_ZEROING,
675 ZYDIS_MASK_OVERRIDE_CONTROL,
676
680 ZYDIS_MASK_OVERRIDE_MAX_VALUE = ZYDIS_MASK_OVERRIDE_CONTROL,
684 ZYDIS_MASK_OVERRIDE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_OVERRIDE_MAX_VALUE)
685} ZydisMaskOverride;
686
687/* ---------------------------------------------------------------------------------------------- */
688
689#define ZYDIS_OPDEF_REQUIRED_BITS \
690 ZYAN_MAX(ZYDIS_REGKIND_REQUIRED_BITS, ZYDIS_MEMOP_TYPE_REQUIRED_BITS + 1) + 1
691
692#define ZYDIS_OPDEF_GET_REG(operand_definition) \
693 ((operand_definition) & ((1 << ZYDIS_REGKIND_REQUIRED_BITS ) - 1))
694
695#define ZYDIS_OPDEF_GET_MEM(operand_definition) \
696 ((operand_definition) & ((1 << ZYDIS_MEMOP_TYPE_REQUIRED_BITS) - 1))
697
698#define ZYDIS_OPDEF_GET_REG_HIGH_BIT(operand_definition) \
699 (((operand_definition) >> ZYDIS_REGKIND_REQUIRED_BITS ) & 0x01)
700
701#define ZYDIS_OPDEF_GET_MEM_HIGH_BIT(operand_definition) \
702 (((operand_definition) >> ZYDIS_MEMOP_TYPE_REQUIRED_BITS) & 0x01)
703
704// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
705// enum types
706ZYAN_STATIC_ASSERT(ZYDIS_MNEMONIC_REQUIRED_BITS <= 16);
707ZYAN_STATIC_ASSERT(ZYDIS_CATEGORY_REQUIRED_BITS <= 8);
708ZYAN_STATIC_ASSERT(ZYDIS_ISA_SET_REQUIRED_BITS <= 8);
709ZYAN_STATIC_ASSERT(ZYDIS_ISA_EXT_REQUIRED_BITS <= 8);
710ZYAN_STATIC_ASSERT(ZYDIS_BRANCH_TYPE_REQUIRED_BITS <= 8);
711ZYAN_STATIC_ASSERT(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS <= 8);
712ZYAN_STATIC_ASSERT(ZYDIS_OPDEF_REQUIRED_BITS <= 8);
713ZYAN_STATIC_ASSERT(ZYDIS_RW_ACTION_REQUIRED_BITS <= 8);
714
715#ifndef ZYDIS_MINIMAL_MODE
716# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
717 ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
718 ZyanU8 operand_count ZYAN_BITFIELD( 4); \
719 ZyanU8 operand_count_visible ZYAN_BITFIELD( 3); \
720 ZyanU16 operand_reference ZYAN_BITFIELD(15); \
721 ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
722 ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
723 ZyanU8 flags_reference ZYAN_BITFIELD( 7); \
724 ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
725 ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \
726 ZyanU8 category ZYAN_BITFIELD(ZYDIS_CATEGORY_REQUIRED_BITS); \
727 ZyanU8 isa_set ZYAN_BITFIELD(ZYDIS_ISA_SET_REQUIRED_BITS); \
728 ZyanU8 isa_ext ZYAN_BITFIELD(ZYDIS_ISA_EXT_REQUIRED_BITS); \
729 ZyanU8 branch_type ZYAN_BITFIELD(ZYDIS_BRANCH_TYPE_REQUIRED_BITS); \
730 ZyanU8 exception_class ZYAN_BITFIELD(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS); \
731 ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
732 ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
733 ZyanU8 cpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
734 ZyanU8 fpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
735 ZyanU8 xmm_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
736 ZyanBool accepts_segment ZYAN_BITFIELD( 1)
737#else
738# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
739 ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
740 ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
741 ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
742 ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
743 ZyanBool no_compat_mode ZYAN_BITFIELD( 1); \
744 ZyanU8 op_reg ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS); \
745 ZyanU8 op_rm ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS)
746#endif
747
748#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR \
749 ZYDIS_INSTRUCTION_DEFINITION_BASE; \
750 ZyanU8 op_ndsndd ZYAN_BITFIELD(ZYDIS_OPDEF_REQUIRED_BITS)
751
752#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL \
753 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR; \
754 ZyanBool is_gather ZYAN_BITFIELD( 1); \
755 ZyanBool no_source_dest_match ZYAN_BITFIELD( 1); \
756 ZyanBool no_source_source_match ZYAN_BITFIELD( 1) // TODO: Could be moved to VEX
757
761 typedef struct ZydisInstructionDefinition_
762{
763 ZYDIS_INSTRUCTION_DEFINITION_BASE;
764} ZydisInstructionDefinition;
765
769 typedef struct ZydisInstructionDefinitionLEGACY_
770{
771 ZYDIS_INSTRUCTION_DEFINITION_BASE;
772#ifndef ZYDIS_MINIMAL_MODE
773 ZyanBool is_privileged ZYAN_BITFIELD( 1);
774#endif
775 ZyanBool accepts_LOCK ZYAN_BITFIELD( 1);
776#ifndef ZYDIS_MINIMAL_MODE
777 ZyanBool accepts_REP ZYAN_BITFIELD( 1);
778 ZyanBool accepts_REPEREPZ ZYAN_BITFIELD( 1);
779 ZyanBool accepts_REPNEREPNZ ZYAN_BITFIELD( 1);
780 ZyanBool accepts_BOUND ZYAN_BITFIELD( 1);
781 ZyanBool accepts_XACQUIRE ZYAN_BITFIELD( 1);
782 ZyanBool accepts_XRELEASE ZYAN_BITFIELD( 1);
783 ZyanBool accepts_NOTRACK ZYAN_BITFIELD( 1);
784 ZyanBool accepts_hle_without_lock ZYAN_BITFIELD( 1);
785 ZyanBool accepts_branch_hints ZYAN_BITFIELD( 1);
786#endif
787} ZydisInstructionDefinitionLEGACY;
788
792 typedef struct ZydisInstructionDefinition3DNOW_
793{
794 ZYDIS_INSTRUCTION_DEFINITION_BASE;
795} ZydisInstructionDefinition3DNOW;
796
800 typedef struct ZydisInstructionDefinitionXOP_
801{
802 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR;
803} ZydisInstructionDefinitionXOP;
804
805// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
806// enum types
807ZYAN_STATIC_ASSERT(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
808
812 typedef struct ZydisInstructionDefinitionVEX_
813{
814 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
815#ifndef ZYDIS_MINIMAL_MODE
816 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS);
817#endif
818} ZydisInstructionDefinitionVEX;
819
820#ifndef ZYDIS_DISABLE_AVX512
821
822// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
823// enum types
824ZYAN_STATIC_ASSERT(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS <= 8);
825ZYAN_STATIC_ASSERT(ZYDIS_TUPLETYPE_REQUIRED_BITS <= 8);
826ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS <= 8);
827ZYAN_STATIC_ASSERT(ZYDIS_EVEX_FUNC_REQUIRED_BITS <= 8);
828ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
829ZYAN_STATIC_ASSERT(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS <= 8);
830ZYAN_STATIC_ASSERT(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
831
835 typedef struct ZydisInstructionDefinitionEVEX_
836{
837 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
838#ifndef ZYDIS_MINIMAL_MODE
839 ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS);
840 ZyanU8 tuple_type ZYAN_BITFIELD(ZYDIS_TUPLETYPE_REQUIRED_BITS);
841 ZyanU8 element_size ZYAN_BITFIELD(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS);
842 ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_EVEX_FUNC_REQUIRED_BITS);
843#endif
844 ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
845 ZyanBool accepts_zero_mask ZYAN_BITFIELD( 1);
846#ifndef ZYDIS_MINIMAL_MODE
847 ZyanU8 mask_override ZYAN_BITFIELD(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS);
848 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS);
849#endif
850} ZydisInstructionDefinitionEVEX;
851#endif
852
853#ifndef ZYDIS_DISABLE_KNC
854
855// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
856// enum types
857ZYAN_STATIC_ASSERT(ZYDIS_MVEX_FUNC_REQUIRED_BITS <= 8);
858ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
859ZYAN_STATIC_ASSERT(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
860
864 typedef struct ZydisInstructionDefinitionMVEX_
865{
866 ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
867 ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_MVEX_FUNC_REQUIRED_BITS);
868 ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
869#ifndef ZYDIS_MINIMAL_MODE
870 ZyanBool has_element_granularity ZYAN_BITFIELD( 1);
871 ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS);
872#endif
873} ZydisInstructionDefinitionMVEX;
874#endif
875
876/* ---------------------------------------------------------------------------------------------- */
877
878#pragma pack(pop)
879
880#ifdef ZYAN_MSVC
881# pragma warning(pop)
882#endif
883
884/* ---------------------------------------------------------------------------------------------- */
885/* Accessed CPU/FPU flags */
886/* ---------------------------------------------------------------------------------------------- */
887
888/*
889 * Contains information about the CPU/FPU flags accessed by an instruction.
890 *
891 * We don't want this struct to be packed! A pointer to the individual members will be used by the
892 * `ZydisDecodedInstruction` struct.
893 */
894 typedef struct ZydisDefinitionAccessedFlags_
895{
896 ZydisAccessedFlags cpu_flags;
897 ZydisAccessedFlags fpu_flags;
898} ZydisDefinitionAccessedFlags;
899
900/* ---------------------------------------------------------------------------------------------- */
901
902/* ============================================================================================== */
903/* Functions */
904/* ============================================================================================== */
905
906/* ---------------------------------------------------------------------------------------------- */
907/* Instruction definition */
908/* ---------------------------------------------------------------------------------------------- */
909
918 ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding,
919 ZyanU16 id, const ZydisInstructionDefinition** definition);
920
921/* ---------------------------------------------------------------------------------------------- */
922/* Operand definition */
923/* ---------------------------------------------------------------------------------------------- */
924
925#ifndef ZYDIS_MINIMAL_MODE
933 ZYDIS_NO_EXPORT const ZydisOperandDefinition* ZydisGetOperandDefinitions(
934 const ZydisInstructionDefinition* definition);
935#endif
936
937/* ---------------------------------------------------------------------------------------------- */
938/* Element info */
939/* ---------------------------------------------------------------------------------------------- */
940
941#ifndef ZYDIS_MINIMAL_MODE
949 ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
950 ZydisElementSize* size);
951#endif
952
953/* ---------------------------------------------------------------------------------------------- */
954/* Accessed CPU flags */
955/* ---------------------------------------------------------------------------------------------- */
956
957#ifndef ZYDIS_MINIMAL_MODE
967 ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
968 const ZydisDefinitionAccessedFlags** flags);
969#endif
970
971/* ---------------------------------------------------------------------------------------------- */
972
973/* ============================================================================================== */
974
975#ifdef __cplusplus
976}
977#endif
978
979#endif /* ZYDIS_INTERNAL_SHAREDDATA_H */
DecoderTypes.h
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS
@ ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: DecoderTypes.h:509
ZYDIS_BRANCH_TYPE_REQUIRED_BITS
@ ZYDIS_BRANCH_TYPE_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: DecoderTypes.h:442
ZYDIS_NO_EXPORT
#define ZYDIS_NO_EXPORT
Symbol is not exported and for internal use only.
Definition: Defines.h:74
Mnemonic.h
Mnemonic constant definitions and helper functions.
Register.h
Utility functions and constants for registers.
SharedTypes.h
Defines decoder/encoder-shared macros and types.
ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS
@ ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: SharedTypes.h:321
ZydisInstructionEncoding
enum ZydisInstructionEncoding_ ZydisInstructionEncoding
Defines the ZydisInstructionEncoding enum.
ZYDIS_OPERAND_ENCODING_REQUIRED_BITS
@ ZYDIS_OPERAND_ENCODING_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: SharedTypes.h:288
ZYDIS_OPERAND_ACTION_REQUIRED_BITS
@ ZYDIS_OPERAND_ACTION_REQUIRED_BITS
The minimum number of bits required to represent all values of this bitset.
Definition: SharedTypes.h:396
ZydisElementType
enum ZydisElementType_ ZydisElementType
Defines the ZydisElementType enum.
ZydisElementSize
ZyanU16 ZydisElementSize
Defines the ZydisElementSize datatype.
Definition: SharedTypes.h:190
ZydisAccessedFlags_
Definition: DecoderTypes.h:386
ZydisDefinitionAccessedFlags_
Definition: SharedData.h:895
ZydisInstructionDefinition3DNOW_
Defines the ZydisInstructionDefinition3DNOW struct.
Definition: SharedData.h:793
ZydisInstructionDefinitionEVEX_
Defines the ZydisInstructionDefinitionEVEX struct.
Definition: SharedData.h:836
ZydisInstructionDefinitionLEGACY_
Defines the ZydisInstructionDefinitionLEGACY struct.
Definition: SharedData.h:770
ZydisInstructionDefinitionMVEX_
Defines the ZydisInstructionDefinitionMVEX struct.
Definition: SharedData.h:865
ZydisInstructionDefinitionVEX_
Defines the ZydisInstructionDefinitionVEX struct.
Definition: SharedData.h:813
ZydisInstructionDefinitionXOP_
Defines the ZydisInstructionDefinitionXOP struct.
Definition: SharedData.h:801
ZydisInstructionDefinition_
Defines the ZydisInstructionDefinition struct.
Definition: SharedData.h:762
ZydisOperandDefinition_
Defines the ZydisOperandDefinition struct.
Definition: SharedData.h:218