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

Zydis v4.1.0

Loading...
Searching...
No Matches
DecoderData.h
Go to the documentation of this file.
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_DECODERDATA_H
28#define ZYDIS_INTERNAL_DECODERDATA_H
29
30#include <Zycore/Defines.h>
31#include <Zycore/Types.h>
32#include <Zydis/Defines.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* ============================================================================================== */
39/* Enums and types */
40/* ============================================================================================== */
41
42// MSVC does not like types other than (un-)signed int for bit-fields
43#ifdef ZYAN_MSVC
44# pragma warning(push)
45# pragma warning(disable:4214)
46#endif
47
48#pragma pack(push, 1)
49
50/* ---------------------------------------------------------------------------------------------- */
51/* Decoder tree */
52/* ---------------------------------------------------------------------------------------------- */
53
57 typedef ZyanU8 ZydisDecoderTreeNodeType;
58
62 enum ZydisDecoderTreeNodeTypes
63{
64 ZYDIS_NODETYPE_INVALID = 0x00,
68 ZYDIS_NODETYPE_DEFINITION_MASK = 0x80,
72 ZYDIS_NODETYPE_FILTER_XOP = 0x01,
76 ZYDIS_NODETYPE_FILTER_VEX = 0x02,
80 ZYDIS_NODETYPE_FILTER_EMVEX = 0x03,
84 ZYDIS_NODETYPE_FILTER_OPCODE = 0x04,
88 ZYDIS_NODETYPE_FILTER_MODE = 0x05,
92 ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x06,
96 ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x07,
100 ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08,
104 ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09,
108 ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0A,
112 ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1 = 0x0B,
116 ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0C,
120 ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0D,
124 ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0E,
128 ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x0F,
132 ZYDIS_NODETYPE_FILTER_REX_W = 0x10,
136 ZYDIS_NODETYPE_FILTER_REX_B = 0x11,
140 ZYDIS_NODETYPE_FILTER_EVEX_B = 0x12,
144 ZYDIS_NODETYPE_FILTER_MVEX_E = 0x13,
148 ZYDIS_NODETYPE_FILTER_MODE_AMD = 0x14,
152 ZYDIS_NODETYPE_FILTER_MODE_KNC = 0x15,
156 ZYDIS_NODETYPE_FILTER_MODE_MPX = 0x16,
160 ZYDIS_NODETYPE_FILTER_MODE_CET = 0x17,
164 ZYDIS_NODETYPE_FILTER_MODE_LZCNT = 0x18,
168 ZYDIS_NODETYPE_FILTER_MODE_TZCNT = 0x19,
172 ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD = 0x1A,
176 ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1B,
180 ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH = 0x1C,
184 ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT = 0x1D
185};
186
187/* ---------------------------------------------------------------------------------------------- */
188
192 typedef ZyanU16 ZydisDecoderTreeNodeValue;
193
194/* ---------------------------------------------------------------------------------------------- */
195
199 typedef struct ZydisDecoderTreeNode_
200{
201 ZydisDecoderTreeNodeType type;
202 ZydisDecoderTreeNodeValue value;
203} ZydisDecoderTreeNode;
204
205/* ---------------------------------------------------------------------------------------------- */
206
207#pragma pack(pop)
208
209#ifdef ZYAN_MSVC
210# pragma warning(pop)
211#endif
212
213/* ---------------------------------------------------------------------------------------------- */
214/* Physical instruction encoding info */
215/* ---------------------------------------------------------------------------------------------- */
216
220 typedef ZyanU8 ZydisInstructionEncodingFlags;
221
225#define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01
226
230#define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02
231
235#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04
236
240#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08
241
248#define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10
249
253 typedef struct ZydisInstructionEncodingInfo_
254{
258 ZydisInstructionEncodingFlags flags;
262 struct
263 {
267 ZyanU8 size[3];
268 } disp;
272 struct
273 {
277 ZyanU8 size[3];
281 ZyanBool is_signed;
285 ZyanBool is_relative;
286 } imm[2];
287} ZydisInstructionEncodingInfo;
288
289/* ---------------------------------------------------------------------------------------------- */
290
291/* ============================================================================================== */
292/* Functions */
293/* ============================================================================================== */
294
295/* ---------------------------------------------------------------------------------------------- */
296/* Decoder tree */
297/* ---------------------------------------------------------------------------------------------- */
298
299extern const ZydisDecoderTreeNode zydis_decoder_tree_root;
300
306ZYAN_INLINE const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void)
307{
308 return &zydis_decoder_tree_root;
309}
310
319 ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(
320 const ZydisDecoderTreeNode* parent, ZyanU16 index);
321
329 ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,
330 const ZydisInstructionEncodingInfo** info);
331
332/* ---------------------------------------------------------------------------------------------- */
333
334/* ============================================================================================== */
335
336#ifdef __cplusplus
337}
338#endif
339
340#endif /* ZYDIS_INTERNAL_DECODERDATA_H */
ZydisDecoderTreeNode
struct ZydisDecoderTreeNode_ ZydisDecoderTreeNode
Defines the ZydisDecoderTreeNode struct.
ZydisDecoderTreeGetRootNode
ZYAN_INLINE const ZydisDecoderTreeNode * ZydisDecoderTreeGetRootNode(void)
Returns the root node of the instruction tree.
Definition DecoderData.h:306
ZydisInstructionEncodingFlags
ZyanU8 ZydisInstructionEncodingFlags
Defines the ZydisInstructionEncodingFlags data-type.
Definition DecoderData.h:220
ZydisDecoderTreeNodeType
ZyanU8 ZydisDecoderTreeNodeType
Defines the ZydisDecoderTreeNodeType data-type.
Definition DecoderData.h:57
ZydisDecoderTreeGetChildNode
ZYDIS_NO_EXPORT const ZydisDecoderTreeNode * ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeNode *parent, ZyanU16 index)
Returns the child node of parent specified by index.
ZydisDecoderTreeNodeValue
ZyanU16 ZydisDecoderTreeNodeValue
Defines the ZydisDecoderTreeNodeValue data-type.
Definition DecoderData.h:192
ZydisGetInstructionEncodingInfo
ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode *node, const ZydisInstructionEncodingInfo **info)
Returns information about optional instruction parts (like modrm, displacement or immediates) for the...
ZydisDecoderTreeNodeTypes
ZydisDecoderTreeNodeTypes
Values that represent zydis decoder tree node types.
Definition DecoderData.h:63
ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT
@ ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT
Reference to a compacted ModRM.mod filter.
Definition DecoderData.h:100
ZYDIS_NODETYPE_DEFINITION_MASK
@ ZYDIS_NODETYPE_DEFINITION_MASK
Reference to an instruction-definition.
Definition DecoderData.h:68
ZYDIS_NODETYPE_FILTER_MVEX_E
@ ZYDIS_NODETYPE_FILTER_MVEX_E
Reference to an MVEX.E filter.
Definition DecoderData.h:144
ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT
@ ZYDIS_NODETYPE_FILTER_MODE_UD0_COMPAT
Reference to a UD0_COMPAT-mode filter.
Definition DecoderData.h:184
ZYDIS_NODETYPE_FILTER_EMVEX
@ ZYDIS_NODETYPE_FILTER_EMVEX
Reference to an EVEX/MVEX-map filter.
Definition DecoderData.h:80
ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1
@ ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1
Reference to a PrefixGroup1 filter.
Definition DecoderData.h:112
ZYDIS_NODETYPE_FILTER_MODRM_MOD
@ ZYDIS_NODETYPE_FILTER_MODRM_MOD
Reference to a ModRM.mod filter.
Definition DecoderData.h:96
ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD
@ ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD
Reference to a WBNOINVD-mode filter.
Definition DecoderData.h:172
ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE
@ ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE
Reference to a CLDEMOTE-mode filter.
Definition DecoderData.h:176
ZYDIS_NODETYPE_FILTER_MODRM_REG
@ ZYDIS_NODETYPE_FILTER_MODRM_REG
Reference to a ModRM.reg filter.
Definition DecoderData.h:104
ZYDIS_NODETYPE_FILTER_MODE_MPX
@ ZYDIS_NODETYPE_FILTER_MODE_MPX
Reference to a MPX-mode filter.
Definition DecoderData.h:156
ZYDIS_NODETYPE_FILTER_MODE_TZCNT
@ ZYDIS_NODETYPE_FILTER_MODE_TZCNT
Reference to a TZCNT-mode filter.
Definition DecoderData.h:168
ZYDIS_NODETYPE_FILTER_MODE_COMPACT
@ ZYDIS_NODETYPE_FILTER_MODE_COMPACT
Reference to an compacted instruction-mode filter.
Definition DecoderData.h:92
ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH
@ ZYDIS_NODETYPE_FILTER_MODE_IPREFETCH
Reference to a IPREFETCH-mode filter.
Definition DecoderData.h:180
ZYDIS_NODETYPE_FILTER_REX_B
@ ZYDIS_NODETYPE_FILTER_REX_B
Reference to an REX/VEX/EVEX.B filter.
Definition DecoderData.h:136
ZYDIS_NODETYPE_FILTER_OPCODE
@ ZYDIS_NODETYPE_FILTER_OPCODE
Reference to an opcode filter.
Definition DecoderData.h:84
ZYDIS_NODETYPE_FILTER_MODRM_RM
@ ZYDIS_NODETYPE_FILTER_MODRM_RM
Reference to a ModRM.rm filter.
Definition DecoderData.h:108
ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH
@ ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH
Reference to a vector-length filter.
Definition DecoderData.h:128
ZYDIS_NODETYPE_FILTER_MODE_KNC
@ ZYDIS_NODETYPE_FILTER_MODE_KNC
Reference to a KNC-mode filter.
Definition DecoderData.h:152
ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE
@ ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE
Reference to an address-size filter.
Definition DecoderData.h:124
ZYDIS_NODETYPE_FILTER_REX_W
@ ZYDIS_NODETYPE_FILTER_REX_W
Reference to an REX/VEX/EVEX.W filter.
Definition DecoderData.h:132
ZYDIS_NODETYPE_FILTER_MODE
@ ZYDIS_NODETYPE_FILTER_MODE
Reference to an instruction-mode filter.
Definition DecoderData.h:88
ZYDIS_NODETYPE_FILTER_MODE_LZCNT
@ ZYDIS_NODETYPE_FILTER_MODE_LZCNT
Reference to a LZCNT-mode filter.
Definition DecoderData.h:164
ZYDIS_NODETYPE_FILTER_MODE_AMD
@ ZYDIS_NODETYPE_FILTER_MODE_AMD
Reference to a AMD-mode filter.
Definition DecoderData.h:148
ZYDIS_NODETYPE_INVALID
@ ZYDIS_NODETYPE_INVALID
Definition DecoderData.h:64
ZYDIS_NODETYPE_FILTER_EVEX_B
@ ZYDIS_NODETYPE_FILTER_EVEX_B
Reference to an EVEX.b filter.
Definition DecoderData.h:140
ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX
@ ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX
Reference to a mandatory-prefix filter.
Definition DecoderData.h:116
ZYDIS_NODETYPE_FILTER_OPERAND_SIZE
@ ZYDIS_NODETYPE_FILTER_OPERAND_SIZE
Reference to an operand-size filter.
Definition DecoderData.h:120
ZYDIS_NODETYPE_FILTER_XOP
@ ZYDIS_NODETYPE_FILTER_XOP
Reference to an XOP-map filter.
Definition DecoderData.h:72
ZYDIS_NODETYPE_FILTER_MODE_CET
@ ZYDIS_NODETYPE_FILTER_MODE_CET
Reference to a CET-mode filter.
Definition DecoderData.h:160
ZYDIS_NODETYPE_FILTER_VEX
@ ZYDIS_NODETYPE_FILTER_VEX
Reference to an VEX-map filter.
Definition DecoderData.h:76
zydis_decoder_tree_root
const ZydisDecoderTreeNode zydis_decoder_tree_root
ZydisInstructionEncodingInfo
struct ZydisInstructionEncodingInfo_ ZydisInstructionEncodingInfo
Defines the ZydisInstructionEncodingInfo struct.
Defines.h
Import/export defines for MSVC builds.
ZYDIS_NO_EXPORT
#define ZYDIS_NO_EXPORT
Symbol is not exported and for internal use only.
Definition Defines.h:74
ZydisDecoderTreeNode_
Defines the ZydisDecoderTreeNode struct.
Definition DecoderData.h:200
ZydisDecoderTreeNode_::value
ZydisDecoderTreeNodeValue value
Definition DecoderData.h:202
ZydisDecoderTreeNode_::type
ZydisDecoderTreeNodeType type
Definition DecoderData.h:201
ZydisInstructionEncodingInfo_
Defines the ZydisInstructionEncodingInfo struct.
Definition DecoderData.h:254
ZydisInstructionEncodingInfo_::disp
struct ZydisInstructionEncodingInfo_::@9 disp
Displacement info.
ZydisInstructionEncodingInfo_::flags
ZydisInstructionEncodingFlags flags
Contains flags with information about the physical instruction-encoding.
Definition DecoderData.h:258
ZydisInstructionEncodingInfo_::is_relative
ZyanBool is_relative
Signals, if the value is a relative offset.
Definition DecoderData.h:285
ZydisInstructionEncodingInfo_::is_signed
ZyanBool is_signed
Signals, if the value is signed.
Definition DecoderData.h:281
ZydisInstructionEncodingInfo_::size
ZyanU8 size[3]
The size of the displacement value.
Definition DecoderData.h:267
ZydisInstructionEncodingInfo_::imm
struct ZydisInstructionEncodingInfo_::@10 imm[2]
Immediate info.