Zydis  v2.0.0-beta1
Decoder.h File Reference

Functions for decoding instructions. More...

#include <Zydis/CommonTypes.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Defines.h>
#include <Zydis/Status.h>
Include dependency graph for Decoder.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ZydisDecoder_
 Defines the ZydisDecoder struct. More...
 

Typedefs

typedef ZydisU8 ZydisDecoderMode
 Defines the ZydisDecoderMode datatype.
 
typedef struct ZydisDecoder_ ZydisDecoder
 Defines the ZydisDecoder struct.
 

Enumerations

enum  ZydisDecoderModes {
  ZYDIS_DECODER_MODE_MINIMAL , ZYDIS_DECODER_MODE_AMD_BRANCHES , ZYDIS_DECODER_MODE_KNC , ZYDIS_DECODER_MODE_MPX ,
  ZYDIS_DECODER_MODE_CET , ZYDIS_DECODER_MODE_LZCNT , ZYDIS_DECODER_MODE_TZCNT , ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_TZCNT
}
 Values that represent decoder-modes. More...
 

Functions

ZYDIS_EXPORT ZydisStatus ZydisDecoderInit (ZydisDecoder *decoder, ZydisMachineMode machineMode, ZydisAddressWidth addressWidth)
 Initializes the given ZydisDecoder instance. More...
 
ZYDIS_EXPORT ZydisStatus ZydisDecoderEnableMode (ZydisDecoder *decoder, ZydisDecoderMode mode, ZydisBool enabled)
 Enables or disables the specified decoder-mode. More...
 
ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer (const ZydisDecoder *decoder, const void *buffer, ZydisUSize bufferLen, ZydisU64 instructionPointer, ZydisDecodedInstruction *instruction)
 Decodes the instruction in the given input buffer. More...
 

Detailed Description

Functions for decoding instructions.

Enumeration Type Documentation

◆ ZydisDecoderModes

Values that represent decoder-modes.

Enumerator
ZYDIS_DECODER_MODE_MINIMAL 

Enables minimal instruction decoding without semantic analysis.

This mode provides access to the mnemonic, the instruction-length, the effective operand-size, the effective address-width, some attributes (e.g. ZYDIS_ATTRIB_IS_RELATIVE) and all of the information in the raw field of the ZydisDecodedInstruction struct.

Operands, most attributes and other specific information (like AVX info) are not accessible in this mode.

This mode is NOT enabled by default.

ZYDIS_DECODER_MODE_AMD_BRANCHES 

Enables the AMD-branch mode.

Intel ignores the operand-size override-prefix (0x66) for all branches with 32-bit immediates and forces the operand-size of the instruction to 64-bit in 64-bit mode. In AMD-branch mode 0x66 is not ignored and changes the operand-size and the size of the immediate to 16-bit.

This mode is NOT enabled by default.

ZYDIS_DECODER_MODE_KNC 

Enables KNC compatibility-mode.

KNC and KNL+ chips are sharing opcodes and encodings for some mask-related instructions. Enable this mode to use the old KNC specifications (different mnemonics, operands, ..).

This mode is NOT enabled by default.

ZYDIS_DECODER_MODE_MPX 

Enables the MPX mode.

The MPX isa-extension reuses (overrides) some of the widenop instruction opcodes.

This mode is enabled by default.

ZYDIS_DECODER_MODE_CET 

Enables the CET mode.

The CET isa-extension reuses (overrides) some of the widenop instruction opcodes.

This mode is enabled by default.

ZYDIS_DECODER_MODE_LZCNT 

Enables the LZCNT mode.

The LZCNT isa-extension reuses (overrides) some of the widenop instruction opcodes.

This mode is enabled by default.

ZYDIS_DECODER_MODE_TZCNT 

Enables the TZCNT mode.

The TZCNT isa-extension reuses (overrides) some of the widenop instruction opcodes.

This mode is enabled by default.

ZYDIS_DECODER_MODE_MAX_VALUE 

Maximum value of this enum.

Function Documentation

◆ ZydisDecoderDecodeBuffer()

ZYDIS_EXPORT ZydisStatus ZydisDecoderDecodeBuffer ( const ZydisDecoder decoder,
const void *  buffer,
ZydisUSize  bufferLen,
ZydisU64  instructionPointer,
ZydisDecodedInstruction instruction 
)

Decodes the instruction in the given input buffer.

Parameters
decoderA pointer to the ZydisDecoder instance.
bufferA pointer to the input buffer.
bufferLenThe length of the input buffer.
instructionPointerThe instruction-pointer.
instructionA pointer to the ZydisDecodedInstruction struct, that receives the details about the decoded instruction.
Returns
A zydis status code.

◆ ZydisDecoderEnableMode()

ZYDIS_EXPORT ZydisStatus ZydisDecoderEnableMode ( ZydisDecoder decoder,
ZydisDecoderMode  mode,
ZydisBool  enabled 
)

Enables or disables the specified decoder-mode.

Parameters
decoderA pointer to the ZydisDecoder instance.
modeThe decoder mode.
enabledZYDIS_TRUE to enable, or ZYDIS_FALSE to disable the specified decoder-mode.
Returns
A zydis status code.

◆ ZydisDecoderInit()

ZYDIS_EXPORT ZydisStatus ZydisDecoderInit ( ZydisDecoder decoder,
ZydisMachineMode  machineMode,
ZydisAddressWidth  addressWidth 
)

Initializes the given ZydisDecoder instance.

Parameters
decoderA pointer to the ZydisDecoder instance.
machineModeThe machine mode.
addressWidthThe address width.
Returns
A zydis status code.