Zydis v4.1.1

Loading...
Searching...
No Matches
EncoderData.h
Go to the documentation of this file.
1/***************************************************************************************************
2
3 Zyan Disassembler Library (Zydis)
4
5 Original Author : Mappa
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_ENCODERDATA_H
28#define ZYDIS_INTERNAL_ENCODERDATA_H
29
30#include <Zycore/Defines.h>
31#include <Zydis/Mnemonic.h>
32#include <Zydis/SharedTypes.h>
33
37 typedef enum ZydisWidthFlag_
38{
39 ZYDIS_WIDTH_INVALID = 0x00,
40 ZYDIS_WIDTH_16 = 0x01,
41 ZYDIS_WIDTH_32 = 0x02,
42 ZYDIS_WIDTH_64 = 0x04,
43
47 ZYDIS_WIDTH_MAX_VALUE = (ZYDIS_WIDTH_64 | (ZYDIS_WIDTH_64 - 1)),
51 ZYDIS_WIDTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_WIDTH_MAX_VALUE)
52} ZydisWidthFlag;
53
58 typedef enum ZydisMandatoryPrefix_
59{
60 ZYDIS_MANDATORY_PREFIX_NONE,
61 ZYDIS_MANDATORY_PREFIX_66,
62 ZYDIS_MANDATORY_PREFIX_F2,
63 ZYDIS_MANDATORY_PREFIX_F3,
64
68 ZYDIS_MANDATORY_PREFIX_MAX_VALUE = ZYDIS_MANDATORY_PREFIX_F3,
72 ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MANDATORY_PREFIX_MAX_VALUE)
73} ZydisMandatoryPrefix;
74
78 typedef enum ZydisVectorLength_
79{
80 ZYDIS_VECTOR_LENGTH_INVALID,
81 ZYDIS_VECTOR_LENGTH_128,
82 ZYDIS_VECTOR_LENGTH_256,
83 ZYDIS_VECTOR_LENGTH_512,
84
88 ZYDIS_VECTOR_LENGTH_MAX_VALUE = ZYDIS_VECTOR_LENGTH_512,
92 ZYDIS_VECTOR_LENGTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_VECTOR_LENGTH_MAX_VALUE)
93} ZydisVectorLength;
94
98 typedef enum ZydisSizeHint_
99{
100 ZYDIS_SIZE_HINT_NONE,
101 ZYDIS_SIZE_HINT_ASZ,
102 ZYDIS_SIZE_HINT_OSZ,
103
107 ZYDIS_SIZE_HINT_MAX_VALUE = ZYDIS_SIZE_HINT_OSZ,
111 ZYDIS_SIZE_HINT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_SIZE_HINT_MAX_VALUE)
112} ZydisSizeHint;
113
118 typedef struct ZydisEncoderLookupEntry_
119{
123 ZyanU16 encoder_reference;
127 ZyanU8 instruction_count;
128} ZydisEncoderLookupEntry;
129
130#pragma pack(push, 1)
131
135 typedef struct ZydisEncodableInstruction_
136{
140 ZyanU16 instruction_reference;
145 ZyanU16 operand_mask;
149 ZyanU8 opcode;
153 ZyanU8 modrm;
157 ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_INSTRUCTION_ENCODING_REQUIRED_BITS);
161 ZyanU8 opcode_map ZYAN_BITFIELD(ZYDIS_OPCODE_MAP_REQUIRED_BITS);
165 ZyanU8 modes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS);
169 ZyanU8 address_sizes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS);
173 ZyanU8 operand_sizes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS);
177 ZyanU8 mandatory_prefix ZYAN_BITFIELD(ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS);
181 ZyanU8 rex_w ZYAN_BITFIELD(1);
185 ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS);
189 ZyanU8 accepts_hint ZYAN_BITFIELD(ZYDIS_SIZE_HINT_REQUIRED_BITS);
200 ZyanU8 swappable ZYAN_BITFIELD(1);
201} ZydisEncodableInstruction;
202
203#pragma pack(pop)
204
209 typedef struct ZydisEncoderRelInfo_
210{
215 ZyanU8 size[3][3];
219 ZyanU8 accepts_scaling_hints;
223 ZyanBool accepts_branch_hints;
227 ZyanBool accepts_bound;
228} ZydisEncoderRelInfo;
229
240ZyanU8 ZydisGetEncodableInstructions(ZydisMnemonic mnemonic,
241 const ZydisEncodableInstruction **instruction);
242
251 const ZydisEncoderRelInfo *ZydisGetRelInfo(ZydisMnemonic mnemonic);
252
253#endif /* ZYDIS_INTERNAL_ENCODERDATA_H */
ZydisVectorLength_
ZydisVectorLength_
Used in encoder's table to represent vector size supported by instruction definition.
Definition EncoderData.h:79
ZYDIS_VECTOR_LENGTH_256
@ ZYDIS_VECTOR_LENGTH_256
Definition EncoderData.h:82
ZYDIS_VECTOR_LENGTH_512
@ ZYDIS_VECTOR_LENGTH_512
Definition EncoderData.h:83
ZYDIS_VECTOR_LENGTH_128
@ ZYDIS_VECTOR_LENGTH_128
Definition EncoderData.h:81
ZYDIS_VECTOR_LENGTH_MAX_VALUE
@ ZYDIS_VECTOR_LENGTH_MAX_VALUE
Maximum value of this enum.
Definition EncoderData.h:88
ZYDIS_VECTOR_LENGTH_REQUIRED_BITS
@ ZYDIS_VECTOR_LENGTH_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition EncoderData.h:92
ZYDIS_VECTOR_LENGTH_INVALID
@ ZYDIS_VECTOR_LENGTH_INVALID
Definition EncoderData.h:80
ZydisVectorLength
enum ZydisVectorLength_ ZydisVectorLength
Used in encoder's table to represent vector size supported by instruction definition.
ZydisWidthFlag
enum ZydisWidthFlag_ ZydisWidthFlag
Used in encoder's table to represent standard ISA sizes in form of bit flags.
ZydisSizeHint
enum ZydisSizeHint_ ZydisSizeHint
Used in encoder's table to represent hint type supported by instruction definition.
ZydisMandatoryPrefix
enum ZydisMandatoryPrefix_ ZydisMandatoryPrefix
Used in encoder's table to represent mandatory instruction prefix.
ZydisWidthFlag_
ZydisWidthFlag_
Used in encoder's table to represent standard ISA sizes in form of bit flags.
Definition EncoderData.h:38
ZYDIS_WIDTH_INVALID
@ ZYDIS_WIDTH_INVALID
Definition EncoderData.h:39
ZYDIS_WIDTH_REQUIRED_BITS
@ ZYDIS_WIDTH_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition EncoderData.h:51
ZYDIS_WIDTH_16
@ ZYDIS_WIDTH_16
Definition EncoderData.h:40
ZYDIS_WIDTH_64
@ ZYDIS_WIDTH_64
Definition EncoderData.h:42
ZYDIS_WIDTH_32
@ ZYDIS_WIDTH_32
Definition EncoderData.h:41
ZYDIS_WIDTH_MAX_VALUE
@ ZYDIS_WIDTH_MAX_VALUE
Maximum value of this enum.
Definition EncoderData.h:47
ZydisGetRelInfo
const ZydisEncoderRelInfo * ZydisGetRelInfo(ZydisMnemonic mnemonic)
Fetches ZydisEncoderRelInfo record for given instruction mnemonic.
ZydisEncoderLookupEntry
struct ZydisEncoderLookupEntry_ ZydisEncoderLookupEntry
Used in encoder's primary lookup table which allows to access a set of instruction definitions for sp...
ZydisSizeHint_
ZydisSizeHint_
Used in encoder's table to represent hint type supported by instruction definition.
Definition EncoderData.h:99
ZYDIS_SIZE_HINT_ASZ
@ ZYDIS_SIZE_HINT_ASZ
Definition EncoderData.h:101
ZYDIS_SIZE_HINT_REQUIRED_BITS
@ ZYDIS_SIZE_HINT_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition EncoderData.h:111
ZYDIS_SIZE_HINT_MAX_VALUE
@ ZYDIS_SIZE_HINT_MAX_VALUE
Maximum value of this enum.
Definition EncoderData.h:107
ZYDIS_SIZE_HINT_NONE
@ ZYDIS_SIZE_HINT_NONE
Definition EncoderData.h:100
ZYDIS_SIZE_HINT_OSZ
@ ZYDIS_SIZE_HINT_OSZ
Definition EncoderData.h:102
ZydisMandatoryPrefix_
ZydisMandatoryPrefix_
Used in encoder's table to represent mandatory instruction prefix.
Definition EncoderData.h:59
ZYDIS_MANDATORY_PREFIX_NONE
@ ZYDIS_MANDATORY_PREFIX_NONE
Definition EncoderData.h:60
ZYDIS_MANDATORY_PREFIX_MAX_VALUE
@ ZYDIS_MANDATORY_PREFIX_MAX_VALUE
Maximum value of this enum.
Definition EncoderData.h:68
ZYDIS_MANDATORY_PREFIX_66
@ ZYDIS_MANDATORY_PREFIX_66
Definition EncoderData.h:61
ZYDIS_MANDATORY_PREFIX_F3
@ ZYDIS_MANDATORY_PREFIX_F3
Definition EncoderData.h:63
ZYDIS_MANDATORY_PREFIX_F2
@ ZYDIS_MANDATORY_PREFIX_F2
Definition EncoderData.h:62
ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS
@ ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition EncoderData.h:72
ZydisEncodableInstruction
struct ZydisEncodableInstruction_ ZydisEncodableInstruction
This structure is encoder's internal representation of encodable instruction definition.
ZydisGetEncodableInstructions
ZyanU8 ZydisGetEncodableInstructions(ZydisMnemonic mnemonic, const ZydisEncodableInstruction **instruction)
Fetches array of ZydisEncodableInstruction structures and its size for given instruction mnemonic.
ZydisEncoderRelInfo
struct ZydisEncoderRelInfo_ ZydisEncoderRelInfo
Contains information used by instruction size prediction algorithm inside ZydisEncoderEncodeInstructi...
ZydisMnemonic
enum ZydisMnemonic_ ZydisMnemonic
Defines the ZydisMnemonic enum.
Mnemonic.h
Mnemonic constant definitions and helper functions.
SharedTypes.h
Defines decoder/encoder-shared macros and types.
ZYDIS_INSTRUCTION_ENCODING_REQUIRED_BITS
@ ZYDIS_INSTRUCTION_ENCODING_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition SharedTypes.h:449
ZYDIS_OPCODE_MAP_REQUIRED_BITS
@ ZYDIS_OPCODE_MAP_REQUIRED_BITS
The minimum number of bits required to represent all values of this enum.
Definition SharedTypes.h:482
ZydisEncodableInstruction_
This structure is encoder's internal representation of encodable instruction definition.
Definition EncoderData.h:136
ZydisEncodableInstruction_::operand_mask
ZyanU16 operand_mask
Compressed information about operand count and types.
Definition EncoderData.h:145
ZydisEncodableInstruction_::instruction_reference
ZyanU16 instruction_reference
Index to one of decoder's instruction definition arrays.
Definition EncoderData.h:140
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 swappable ZYAN_BITFIELD(1)
Indicates that next instruction definition can be safely used instead of current one.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS)
The vector length.
ZydisEncodableInstruction_::modrm
ZyanU8 modrm
The mandatory ModR/M value.
Definition EncoderData.h:153
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 operand_sizes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS)
The combination of allowed operand sizes.
ZydisEncodableInstruction_::opcode
ZyanU8 opcode
The instruction-opcode.
Definition EncoderData.h:149
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 accepts_hint ZYAN_BITFIELD(ZYDIS_SIZE_HINT_REQUIRED_BITS)
The accepted sizing hint.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 modes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS)
The combination of allowed processor modes.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 mandatory_prefix ZYAN_BITFIELD(ZYDIS_MANDATORY_PREFIX_REQUIRED_BITS)
The mandatory prefix.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 rex_w ZYAN_BITFIELD(1)
True if REX.W is required for this definition.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_INSTRUCTION_ENCODING_REQUIRED_BITS)
The instruction-encoding.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 opcode_map ZYAN_BITFIELD(ZYDIS_OPCODE_MAP_REQUIRED_BITS)
The opcode map.
ZydisEncodableInstruction_::ZYAN_BITFIELD
ZyanU8 address_sizes ZYAN_BITFIELD(ZYDIS_WIDTH_REQUIRED_BITS)
The combination of allowed address sizes.
ZydisEncoderLookupEntry_
Used in encoder's primary lookup table which allows to access a set of instruction definitions for sp...
Definition EncoderData.h:119
ZydisEncoderLookupEntry_::encoder_reference
ZyanU16 encoder_reference
Index to main array of ZydisEncodableInstruction.
Definition EncoderData.h:123
ZydisEncoderLookupEntry_::instruction_count
ZyanU8 instruction_count
The number of entries.
Definition EncoderData.h:127
ZydisEncoderRelInfo_
Contains information used by instruction size prediction algorithm inside ZydisEncoderEncodeInstructi...
Definition EncoderData.h:210
ZydisEncoderRelInfo_::size
ZyanU8 size[3][3]
Sizes of instruction variants.
Definition EncoderData.h:215
ZydisEncoderRelInfo_::accepts_branch_hints
ZyanBool accepts_branch_hints
True if instruction accepts branch hint prefixes.
Definition EncoderData.h:223
ZydisEncoderRelInfo_::accepts_scaling_hints
ZyanU8 accepts_scaling_hints
See ZydisSizeHint.
Definition EncoderData.h:219
ZydisEncoderRelInfo_::accepts_bound
ZyanBool accepts_bound
True if instruction accepts bound (BND) prefix.
Definition EncoderData.h:227