Zydis  master
Encoder.h File Reference

Functions for encoding instructions. More...

#include <Zycore/Types.h>
#include <Zydis/MetaInfo.h>
#include <Zydis/Register.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Status.h>
Include dependency graph for Encoder.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ZydisEncoderOperand_
 Describes explicit or implicit instruction operand. More...
 
struct  ZydisEncoderOperand_::ZydisEncoderOperandReg_
 Extended info for register-operands. More...
 
struct  ZydisEncoderOperand_::ZydisEncoderOperandMem_
 Extended info for memory-operands. More...
 
struct  ZydisEncoderOperand_::ZydisEncoderOperandPtr_
 Extended info for pointer-operands. More...
 
union  ZydisEncoderOperand_::ZydisEncoderOperandImm_
 Extended info for immediate-operands. More...
 
struct  ZydisEncoderRequest_
 Main structure consumed by the encoder. More...
 
struct  ZydisEncoderRequest_::ZydisEncoderRequestEvexFeatures_
 Extended info for EVEX instructions. More...
 
struct  ZydisEncoderRequest_::ZydisEncoderRequestMvexFeatures_
 Extended info for MVEX instructions. More...
 

Macros

#define ZYDIS_ENCODER_MAX_OPERANDS   5
 Maximum number of encodable (explicit and implicit) operands. More...
 
#define ZYDIS_ENCODABLE_PREFIXES
 Combination of all user-encodable prefixes. More...
 

Typedefs

typedef enum ZydisEncodableEncoding_ ZydisEncodableEncoding
 Defines possible physical instruction encodings as bit flags, so multiple acceptable encodings can be specified simultaneously. More...
 
typedef enum ZydisBranchWidth_ ZydisBranchWidth
 Defines encodable physical/effective sizes of relative immediate operands. More...
 
typedef enum ZydisAddressSizeHint_ ZydisAddressSizeHint
 Defines possible values for address size hints. More...
 
typedef enum ZydisOperandSizeHint_ ZydisOperandSizeHint
 Defines possible values for operand size hints. More...
 
typedef struct ZydisEncoderOperand_ ZydisEncoderOperand
 Describes explicit or implicit instruction operand. More...
 
typedef struct ZydisEncoderRequest_ ZydisEncoderRequest
 Main structure consumed by the encoder. More...
 

Enumerations

enum  ZydisEncodableEncoding_ {
  ZYDIS_ENCODABLE_ENCODING_DEFAULT = 0x00000000 , ZYDIS_ENCODABLE_ENCODING_LEGACY = 0x00000001 , ZYDIS_ENCODABLE_ENCODING_3DNOW = 0x00000002 , ZYDIS_ENCODABLE_ENCODING_XOP = 0x00000004 ,
  ZYDIS_ENCODABLE_ENCODING_VEX = 0x00000008 , ZYDIS_ENCODABLE_ENCODING_EVEX = 0x00000010 , ZYDIS_ENCODABLE_ENCODING_MVEX = 0x00000020 , ZYDIS_ENCODABLE_ENCODING_MAX_VALUE ,
  ZYDIS_ENCODABLE_ENCODING_REQUIRED_BITS =
}
 Defines possible physical instruction encodings as bit flags, so multiple acceptable encodings can be specified simultaneously. More...
 
enum  ZydisBranchWidth_ {
  ZYDIS_BRANCH_WIDTH_NONE , ZYDIS_BRANCH_WIDTH_8 , ZYDIS_BRANCH_WIDTH_16 , ZYDIS_BRANCH_WIDTH_32 ,
  ZYDIS_BRANCH_WIDTH_64 , ZYDIS_BRANCH_WIDTH_MAX_VALUE = ZYDIS_BRANCH_WIDTH_64 , ZYDIS_BRANCH_WIDTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_BRANCH_WIDTH_MAX_VALUE)
}
 Defines encodable physical/effective sizes of relative immediate operands. More...
 
enum  ZydisAddressSizeHint_ {
  ZYDIS_ADDRESS_SIZE_HINT_NONE , ZYDIS_ADDRESS_SIZE_HINT_16 , ZYDIS_ADDRESS_SIZE_HINT_32 , ZYDIS_ADDRESS_SIZE_HINT_64 ,
  ZYDIS_ADDRESS_SIZE_HINT_MAX_VALUE = ZYDIS_ADDRESS_SIZE_HINT_64 , ZYDIS_ADDRESS_SIZE_HINT_REQUIRED_BITS =
}
 Defines possible values for address size hints. More...
 
enum  ZydisOperandSizeHint_ {
  ZYDIS_OPERAND_SIZE_HINT_NONE , ZYDIS_OPERAND_SIZE_HINT_8 , ZYDIS_OPERAND_SIZE_HINT_16 , ZYDIS_OPERAND_SIZE_HINT_32 ,
  ZYDIS_OPERAND_SIZE_HINT_64 , ZYDIS_OPERAND_SIZE_HINT_MAX_VALUE = ZYDIS_OPERAND_SIZE_HINT_64 , ZYDIS_OPERAND_SIZE_HINT_REQUIRED_BITS =
}
 Defines possible values for operand size hints. More...
 

Functions

 ZYAN_STATIC_ASSERT (ZYAN_BITS_TO_REPRESENT(ZYDIS_ENCODER_MAX_OPERANDS)==3)
 
ZYDIS_EXPORT ZyanStatus ZydisEncoderEncodeInstruction (const ZydisEncoderRequest *request, void *buffer, ZyanUSize *length)
 Encodes instruction with semantics specified in encoder request structure. More...
 
ZYDIS_EXPORT ZyanStatus ZydisEncoderEncodeInstructionAbsolute (ZydisEncoderRequest *request, void *buffer, ZyanUSize *length, ZyanU64 runtime_address)
 Encodes instruction with semantics specified in encoder request structure. More...
 
ZYDIS_EXPORT ZyanStatus ZydisEncoderDecodedInstructionToEncoderRequest (const ZydisDecodedInstruction *instruction, const ZydisDecodedOperand *operands, ZyanU8 operand_count_visible, ZydisEncoderRequest *request)
 Converts decoded instruction to encoder request that can be passed to ZydisEncoderEncodeInstruction. More...
 
ZYDIS_EXPORT ZyanStatus ZydisEncoderNopFill (void *buffer, ZyanUSize length)
 Fills provided buffer with NOP instructions using longest possible multi-byte instructions. More...
 

Detailed Description

Functions for encoding instructions.

Macro Definition Documentation

◆ ZYDIS_ENCODABLE_PREFIXES

#define ZYDIS_ENCODABLE_PREFIXES
Value:
ZYDIS_ATTRIB_HAS_REP | \
ZYDIS_ATTRIB_HAS_REPE | \
ZYDIS_ATTRIB_HAS_REPNE | \
ZYDIS_ATTRIB_HAS_BND | \
ZYDIS_ATTRIB_HAS_XACQUIRE | \
ZYDIS_ATTRIB_HAS_XRELEASE | \
ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN | \
ZYDIS_ATTRIB_HAS_BRANCH_TAKEN | \
ZYDIS_ATTRIB_HAS_NOTRACK | \
ZYDIS_ATTRIB_HAS_SEGMENT_CS | \
ZYDIS_ATTRIB_HAS_SEGMENT_SS | \
ZYDIS_ATTRIB_HAS_SEGMENT_DS | \
ZYDIS_ATTRIB_HAS_SEGMENT_ES | \
ZYDIS_ATTRIB_HAS_SEGMENT_FS | \
ZYDIS_ATTRIB_HAS_SEGMENT_GS)
#define ZYDIS_ATTRIB_HAS_LOCK
The instruction has the LOCK prefix (0xF0).
Definition: SharedTypes.h:626

Combination of all user-encodable prefixes.

◆ ZYDIS_ENCODER_MAX_OPERANDS

#define ZYDIS_ENCODER_MAX_OPERANDS   5

Maximum number of encodable (explicit and implicit) operands.

Typedef Documentation

◆ ZydisAddressSizeHint

Defines possible values for address size hints.

See ZydisEncoderRequest for more information about address size hints.

◆ ZydisBranchWidth

Defines encodable physical/effective sizes of relative immediate operands.

See ZydisEncoderRequest.branch_width for more details.

◆ ZydisEncodableEncoding

Defines possible physical instruction encodings as bit flags, so multiple acceptable encodings can be specified simultaneously.

◆ ZydisEncoderOperand

Describes explicit or implicit instruction operand.

◆ ZydisEncoderRequest

Main structure consumed by the encoder.

It represents full semantics of an instruction.

◆ ZydisOperandSizeHint

Defines possible values for operand size hints.

See ZydisEncoderRequest for more information about operand size hints.

Enumeration Type Documentation

◆ ZydisAddressSizeHint_

Defines possible values for address size hints.

See ZydisEncoderRequest for more information about address size hints.

Enumerator
ZYDIS_ADDRESS_SIZE_HINT_NONE 
ZYDIS_ADDRESS_SIZE_HINT_16 
ZYDIS_ADDRESS_SIZE_HINT_32 
ZYDIS_ADDRESS_SIZE_HINT_64 
ZYDIS_ADDRESS_SIZE_HINT_MAX_VALUE 

Maximum value of this enum.

ZYDIS_ADDRESS_SIZE_HINT_REQUIRED_BITS 

The minimum number of bits required to represent all values of this enum.

◆ ZydisBranchWidth_

Defines encodable physical/effective sizes of relative immediate operands.

See ZydisEncoderRequest.branch_width for more details.

Enumerator
ZYDIS_BRANCH_WIDTH_NONE 
ZYDIS_BRANCH_WIDTH_8 
ZYDIS_BRANCH_WIDTH_16 
ZYDIS_BRANCH_WIDTH_32 
ZYDIS_BRANCH_WIDTH_64 
ZYDIS_BRANCH_WIDTH_MAX_VALUE 

Maximum value of this enum.

ZYDIS_BRANCH_WIDTH_REQUIRED_BITS 

The minimum number of bits required to represent all values of this enum.

◆ ZydisEncodableEncoding_

Defines possible physical instruction encodings as bit flags, so multiple acceptable encodings can be specified simultaneously.

Enumerator
ZYDIS_ENCODABLE_ENCODING_DEFAULT 
ZYDIS_ENCODABLE_ENCODING_LEGACY 
ZYDIS_ENCODABLE_ENCODING_3DNOW 
ZYDIS_ENCODABLE_ENCODING_XOP 
ZYDIS_ENCODABLE_ENCODING_VEX 
ZYDIS_ENCODABLE_ENCODING_EVEX 
ZYDIS_ENCODABLE_ENCODING_MVEX 
ZYDIS_ENCODABLE_ENCODING_MAX_VALUE 

Maximum value of this enum.

ZYDIS_ENCODABLE_ENCODING_REQUIRED_BITS 

The minimum number of bits required to represent all values of this enum.

◆ ZydisOperandSizeHint_

Defines possible values for operand size hints.

See ZydisEncoderRequest for more information about operand size hints.

Enumerator
ZYDIS_OPERAND_SIZE_HINT_NONE 
ZYDIS_OPERAND_SIZE_HINT_8 
ZYDIS_OPERAND_SIZE_HINT_16 
ZYDIS_OPERAND_SIZE_HINT_32 
ZYDIS_OPERAND_SIZE_HINT_64 
ZYDIS_OPERAND_SIZE_HINT_MAX_VALUE 

Maximum value of this enum.

ZYDIS_OPERAND_SIZE_HINT_REQUIRED_BITS 

The minimum number of bits required to represent all values of this enum.

Function Documentation

◆ ZYAN_STATIC_ASSERT()

ZYAN_STATIC_ASSERT ( ZYAN_BITS_TO_REPRESENT(ZYDIS_ENCODER_MAX_OPERANDS = =3)