Zydis  master
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
35 extern "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 ZyanU16 ZydisDecoderTreeNode;
58 
59 /* ---------------------------------------------------------------------------------------------- */
60 
65 {
216 
226 
227 /* ---------------------------------------------------------------------------------------------- */
228 /* Opcode tables */
229 /* ---------------------------------------------------------------------------------------------- */
230 
231 // TODO: Auto generate this.
232 
233 #define ZYDIS_OPCODE_TABLE_PRIMARY 0x00
234 #define ZYDIS_OPCODE_TABLE_0F 0x01
235 #define ZYDIS_OPCODE_TABLE_0F38 0x02
236 #define ZYDIS_OPCODE_TABLE_0F3A 0x03
237 #define ZYDIS_OPCODE_TABLE_VEX 0x04
238 #define ZYDIS_OPCODE_TABLE_EVEX 0x14
239 #define ZYDIS_OPCODE_TABLE_MVEX 0x34
240 #define ZYDIS_OPCODE_TABLE_XOP 0x44
241 #define ZYDIS_OPCODE_TABLE_3DNOW 0x47
242 
243 /* ---------------------------------------------------------------------------------------------- */
244 
245 #pragma pack(pop)
246 
247 #ifdef ZYAN_MSVC
248 # pragma warning(pop)
249 #endif
250 
251 /* ---------------------------------------------------------------------------------------------- */
252 /* Physical instruction encoding info */
253 /* ---------------------------------------------------------------------------------------------- */
254 
259 
263 #define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01
264 
268 #define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02
269 
273 #define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04
274 
278 #define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08
279 
286 #define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10
287 
292 {
300  struct
301  {
305  ZyanU8 size[3];
306  } disp;
310  struct
311  {
315  ZyanU8 size[3];
319  ZyanBool is_signed;
323  ZyanBool is_address;
327  ZyanBool is_relative;
328  } imm[2];
330 
331 /* ---------------------------------------------------------------------------------------------- */
332 
333 /* ============================================================================================== */
334 /* Functions */
335 /* ============================================================================================== */
336 
337 /* ---------------------------------------------------------------------------------------------- */
338 /* Decoder tree */
339 /* ---------------------------------------------------------------------------------------------- */
340 
348 #define ZYDIS_DT_GET_TYPE(node) \
349  ((ZydisDecoderTreeNodeType)((*(node)) & 0xFF))
350 
358 #define ZYDIS_DT_GET_ARG0(node) \
359  ((ZyanU8)(((*(node)) >> 8) & 0xFF))
360 
367 #define ZYDIS_DT_GET_VALUE(node, index) \
368  ((ZyanU16)(*((node) + 1 + (index))))
369 
377 
386  const ZydisInstructionEncodingInfo** info);
387 
388 /* ---------------------------------------------------------------------------------------------- */
389 
390 /* ============================================================================================== */
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 
396 #endif /* ZYDIS_INTERNAL_DECODERDATA_H */
ZyanU8 ZydisInstructionEncodingFlags
Defines the ZydisInstructionEncodingFlags data-type.
Definition: DecoderData.h:258
enum ZydisDecoderTreeNodeType_ ZydisDecoderTreeNodeType
Values that represent Zydis decoder tree node types.
ZyanU16 ZydisDecoderTreeNode
Defines the ZydisDecoderTreeNode data-type.
Definition: DecoderData.h:57
ZYDIS_NO_EXPORT const ZydisDecoderTreeNode * ZydisGetOpcodeTableRootNode(ZyanU8 opcode_table_id)
Returns the root node of the opcode table with the given opcode_table_id.
ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode *node, const ZydisInstructionEncodingInfo **info)
Returns information about optional instruction parts (like modrm, displacement or immediates) for the...
ZydisDecoderTreeNodeType_
Values that represent Zydis decoder tree node types.
Definition: DecoderData.h:65
@ ZYDIS_NODETYPE_MODE_CET
Reference to a CET-mode selector.
Definition: DecoderData.h:171
@ ZYDIS_NODETYPE_MODE_CLDEMOTE
Reference to a CLDEMOTE-mode selector.
Definition: DecoderData.h:187
@ ZYDIS_NODETYPE_MODRM_MOD_COMPACT
Reference to a compacted ModRM.mod selector.
Definition: DecoderData.h:111
@ ZYDIS_NODETYPE_ADDRESS_SIZE
Reference to an address-size selector.
Definition: DecoderData.h:135
@ ZYDIS_NODETYPE_MODRM_MOD
Reference to a ModRM.mod selector.
Definition: DecoderData.h:107
@ ZYDIS_NODETYPE_DEFINITION
Reference to an instruction-definition.
Definition: DecoderData.h:70
@ ZYDIS_NODETYPE_VECTOR_LENGTH
Reference to a vector-length selector.
Definition: DecoderData.h:139
@ ZYDIS_NODETYPE_MAX_VALUE
Maximum value of this enum.
Definition: DecoderData.h:220
@ ZYDIS_NODETYPE_EVEX_U
Reference to a EVEX.U selector.
Definition: DecoderData.h:215
@ ZYDIS_NODETYPE_MODE_MPX
Reference to a MPX-mode selector.
Definition: DecoderData.h:167
@ ZYDIS_NODETYPE_MODRM_REG
Reference to a ModRM.reg selector.
Definition: DecoderData.h:115
@ ZYDIS_NODETYPE_SWITCH_TABLE_REX2
Reference to a REX2-map selector.
Definition: DecoderData.h:91
@ ZYDIS_NODETYPE_MODE_AMD
Reference to a AMD-mode selector.
Definition: DecoderData.h:159
@ ZYDIS_NODETYPE_EVEX_B
Reference to an EVEX.b selector.
Definition: DecoderData.h:151
@ ZYDIS_NODETYPE_MODE_COMPACT
Reference to an compacted instruction-mode selector.
Definition: DecoderData.h:103
@ ZYDIS_NODETYPE_REX_B
Reference to an REX/VEX/EVEX.B selector.
Definition: DecoderData.h:147
@ ZYDIS_NODETYPE_SWITCH_TABLE_EMVEX
Reference to an EVEX/MVEX-map selector.
Definition: DecoderData.h:87
@ ZYDIS_NODETYPE_OPCODE_TABLE
Reference to an opcode selector.
Definition: DecoderData.h:95
@ ZYDIS_NODETYPE_MODE_KNC
Reference to a KNC-mode selector.
Definition: DecoderData.h:163
@ ZYDIS_NODETYPE_SWITCH_TABLE
A decoder tree node that instructs the decoder to switch to a different opcode table.
Definition: DecoderData.h:75
@ ZYDIS_NODETYPE_MODE_UD0_COMPAT
Reference to a UD0_COMPAT-mode selector.
Definition: DecoderData.h:195
@ ZYDIS_NODETYPE_MODRM_RM
Reference to a ModRM.rm selector.
Definition: DecoderData.h:119
@ ZYDIS_NODETYPE_PREFIX_GROUP1
Reference to a PrefixGroup1 selector.
Definition: DecoderData.h:123
@ ZYDIS_NODETYPE_REX_W
Reference to an REX/VEX/EVEX.W selector.
Definition: DecoderData.h:143
@ ZYDIS_NODETYPE_MODE_TZCNT
Reference to a TZCNT-mode selector.
Definition: DecoderData.h:179
@ ZYDIS_NODETYPE_EVEX_SCC
Reference to an EVEX.scc selector.
Definition: DecoderData.h:207
@ ZYDIS_NODETYPE_OPERAND_SIZE
Reference to an operand-size selector.
Definition: DecoderData.h:131
@ ZYDIS_NODETYPE_SWITCH_TABLE_XOP
Reference to an XOP-map selector.
Definition: DecoderData.h:79
@ ZYDIS_NODETYPE_MANDATORY_PREFIX
Reference to a mandatory-prefix selector.
Definition: DecoderData.h:127
@ ZYDIS_NODETYPE_MODE_LZCNT
Reference to a LZCNT-mode selector.
Definition: DecoderData.h:175
@ ZYDIS_NODETYPE_MVEX_E
Reference to an MVEX.E selector.
Definition: DecoderData.h:155
@ ZYDIS_NODETYPE_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition: DecoderData.h:224
@ ZYDIS_NODETYPE_MODE_WBNOINVD
Reference to a WBNOINVD-mode selector.
Definition: DecoderData.h:183
@ ZYDIS_NODETYPE_INVALID
Definition: DecoderData.h:66
@ ZYDIS_NODETYPE_SWITCH_TABLE_VEX
Reference to an VEX-map selector.
Definition: DecoderData.h:83
@ ZYDIS_NODETYPE_MODE
Reference to an instruction-mode selector.
Definition: DecoderData.h:99
@ ZYDIS_NODETYPE_REX_2
Reference to a REX2-prefix selector.
Definition: DecoderData.h:211
@ ZYDIS_NODETYPE_EVEX_ND
Reference to an EVEX.nd selector.
Definition: DecoderData.h:199
@ ZYDIS_NODETYPE_EVEX_NF
Reference to an EVEX.nf selector.
Definition: DecoderData.h:203
@ ZYDIS_NODETYPE_MODE_IPREFETCH
Reference to a IPREFETCH-mode selector.
Definition: DecoderData.h:191
struct ZydisInstructionEncodingInfo_ ZydisInstructionEncodingInfo
Defines the ZydisInstructionEncodingInfo struct.
Import/export defines for MSVC builds.
#define ZYDIS_NO_EXPORT
Symbol is not exported and for internal use only.
Definition: Defines.h:74
Defines the ZydisInstructionEncodingInfo struct.
Definition: DecoderData.h:292
ZyanBool is_address
Signals, if the value is an address.
Definition: DecoderData.h:323
struct ZydisInstructionEncodingInfo_::@9 disp
Displacement info.
ZydisInstructionEncodingFlags flags
Contains flags with information about the physical instruction-encoding.
Definition: DecoderData.h:296
ZyanBool is_relative
Signals, if the value is a relative offset.
Definition: DecoderData.h:327
ZyanBool is_signed
Signals, if the value is signed.
Definition: DecoderData.h:319
ZyanU8 size[3]
The size of the displacement value.
Definition: DecoderData.h:305
struct ZydisInstructionEncodingInfo_::@10 imm[2]
Immediate info.