Refactorings

- Renamed Types.h to CommonTypes.h
- Splitted DecoderTypes.h into SharedTypes.h and DecoderTypes.h
- Splitted InstructionTable.h into SharedData.h and DecoderData.h
- Implemented `ZydisGetEncodableInstructions` in EncoderData.h
- Some internal changes to the data-tables
This commit is contained in:
flobernd 2017-07-06 00:34:36 +02:00
parent f8f928a4a8
commit df2dbd9109
22 changed files with 23815 additions and 10260 deletions

View File

@ -81,23 +81,26 @@ endif ()
target_sources("Zydis"
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/CommonTypes.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Decoder.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Defines.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Formatter.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/DecoderTypes.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Mnemonic.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Register.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Status.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Types.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/SharedTypes.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Status.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Utils.h"
"${CMAKE_CURRENT_LIST_DIR}/include/Zydis/Zydis.h"
PRIVATE
"src/InstructionTable.h"
"src/DecoderData.h"
"src/SharedData.h"
"src/Decoder.c"
"src/DecoderData.c"
"src/Formatter.c"
"src/InstructionTable.c"
"src/Mnemonic.c"
"src/Register.c"
"src/SharedData.c"
"src/Utils.c"
"src/Zydis.c")
@ -107,8 +110,12 @@ endif ()
if (ZYDIS_FEATURE_ENCODER)
target_sources("Zydis"
PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include/Encoder.h"
PRIVATE "src/Encoder.c")
PUBLIC
"${CMAKE_CURRENT_LIST_DIR}/include/Encoder.h"
PRIVATE
"src/EncoderData.h"
"src/Encoder.c"
"src/EncoderData.c")
endif ()
# TODO: Install CMake config.

View File

@ -29,8 +29,8 @@
* @brief Includes and defines some default datatypes.
*/
#ifndef ZYDIS_TYPES_H
#define ZYDIS_TYPES_H
#ifndef ZYDIS_COMMONTYPES_H
#define ZYDIS_COMMONTYPES_H
/* ============================================================================================== */
/* Integral types */
@ -68,4 +68,4 @@ typedef uint8_t ZydisBool;
}
#endif
#endif /* ZYDIS_TYPES_H */
#endif /* ZYDIS_COMMONTYPES_H */

View File

@ -27,10 +27,10 @@
#ifndef ZYDIS_DECODER_H
#define ZYDIS_DECODER_H
#include <Zydis/Defines.h>
#include <Zydis/Types.h>
#include <Zydis/Status.h>
#include <Zydis/CommonTypes.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Defines.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
@ -72,7 +72,7 @@ enum ZydisDecodeGranularities
};
/**
* @brief Defines the @c ZydisDecoder datatype.
* @brief Defines the @c ZydisDecoder struct.
*/
typedef struct ZydisDecoder_
{

View File

@ -32,224 +32,18 @@
#ifndef ZYDIS_INSTRUCTIONINFO_H
#define ZYDIS_INSTRUCTIONINFO_H
#include <Zydis/Types.h>
#include <Zydis/CommonTypes.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_MAX_INSTRUCTION_LENGTH 15
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Operand info */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Operand type */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandType datatype.
*/
typedef uint8_t ZydisOperandType;
/**
* @brief Values that represent operand-types.
*/
enum ZydisOperandTypes
{
/**
* @brief The operand is not used.
*/
ZYDIS_OPERAND_TYPE_UNUSED,
/**
* @brief The operand is a register operand.
*/
ZYDIS_OPERAND_TYPE_REGISTER,
/**
* @brief The operand is a memory operand.
*/
ZYDIS_OPERAND_TYPE_MEMORY,
/**
* @brief The operand is a pointer operand with a segment:offset lvalue.
*/
ZYDIS_OPERAND_TYPE_POINTER,
/**
* @brief The operand is an immediate operand.
*/
ZYDIS_OPERAND_TYPE_IMMEDIATE
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandEncoding datatype.
*/
typedef uint8_t ZydisOperandEncoding;
/**
* @brief Values that represent operand-encodings.
*/
enum ZydisOperandEncodings
{
ZYDIS_OPERAND_ENCODING_NONE,
ZYDIS_OPERAND_ENCODING_MODRM_REG,
ZYDIS_OPERAND_ENCODING_MODRM_RM,
ZYDIS_OPERAND_ENCODING_OPCODE,
ZYDIS_OPERAND_ENCODING_NDSNDD,
ZYDIS_OPERAND_ENCODING_IS4,
ZYDIS_OPERAND_ENCODING_MASK,
ZYDIS_OPERAND_ENCODING_DISP8,
ZYDIS_OPERAND_ENCODING_DISP16,
ZYDIS_OPERAND_ENCODING_DISP32,
ZYDIS_OPERAND_ENCODING_DISP64,
ZYDIS_OPERAND_ENCODING_DISP16_32_64,
ZYDIS_OPERAND_ENCODING_DISP32_32_64,
ZYDIS_OPERAND_ENCODING_DISP16_32_32,
ZYDIS_OPERAND_ENCODING_UIMM8,
ZYDIS_OPERAND_ENCODING_UIMM16,
ZYDIS_OPERAND_ENCODING_UIMM32,
ZYDIS_OPERAND_ENCODING_UIMM64,
ZYDIS_OPERAND_ENCODING_UIMM16_32_64,
ZYDIS_OPERAND_ENCODING_UIMM32_32_64,
ZYDIS_OPERAND_ENCODING_UIMM16_32_32,
ZYDIS_OPERAND_ENCODING_SIMM8,
ZYDIS_OPERAND_ENCODING_SIMM16,
ZYDIS_OPERAND_ENCODING_SIMM32,
ZYDIS_OPERAND_ENCODING_SIMM64,
ZYDIS_OPERAND_ENCODING_SIMM16_32_64,
ZYDIS_OPERAND_ENCODING_SIMM32_32_64,
ZYDIS_OPERAND_ENCODING_SIMM16_32_32,
ZYDIS_OPERAND_ENCODING_JIMM8,
ZYDIS_OPERAND_ENCODING_JIMM16,
ZYDIS_OPERAND_ENCODING_JIMM32,
ZYDIS_OPERAND_ENCODING_JIMM64,
ZYDIS_OPERAND_ENCODING_JIMM16_32_64,
ZYDIS_OPERAND_ENCODING_JIMM32_32_64,
ZYDIS_OPERAND_ENCODING_JIMM16_32_32
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand visibility */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandVisibility datatype.
*/
typedef uint8_t ZydisOperandVisibility;
/**
* @brief Values that represent operand-visibilities.
*/
enum ZydisOperandVisibilities
{
ZYDIS_OPERAND_VISIBILITY_INVALID,
/**
* @brief The operand is explicitly encoded in the instruction.
*/
ZYDIS_OPERAND_VISIBILITY_EXPLICIT,
/**
* @brief The operand is part of the opcode, but listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_IMPLICIT,
/**
* @brief The operand is part of the opcode, and not typically listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_HIDDEN
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand action */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandAction datatype.
*/
typedef uint8_t ZydisOperandAction;
/**
* @brief Values that represent operand-actions.
*/
enum ZydisOperandActions
{
ZYDIS_OPERAND_ACTION_INVALID,
/**
* @brief The operand is read by the instruction.
*/
ZYDIS_OPERAND_ACTION_READ,
/**
* @brief The operand is written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_WRITE,
/**
* @brief The operand is read and written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_READWRITE,
/**
* @brief The operand is conditionally read by the instruction.
*/
ZYDIS_OPERAND_ACTION_CONDREAD,
/**
* @brief The operand is conditionally written by the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_CONDWRITE,
/**
* @brief The operand is read and conditionally written by the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_READ_CONDWRITE,
/**
* @brief The operand is written and conditionally read by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_CONDREAD_WRITE,
};
/* ---------------------------------------------------------------------------------------------- */
/* Elements */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisElementType datatype.
*/
typedef uint8_t ZydisElementType;
/**
* @brief Values that represent element-types.
*/
enum ZydisElementTypes
{
ZYDIS_ELEMENT_TYPE_INVALID,
ZYDIS_ELEMENT_TYPE_STRUCT,
ZYDIS_ELEMENT_TYPE_UINT,
ZYDIS_ELEMENT_TYPE_INT,
ZYDIS_ELEMENT_TYPE_FLOAT16,
ZYDIS_ELEMENT_TYPE_FLOAT32,
ZYDIS_ELEMENT_TYPE_FLOAT64,
ZYDIS_ELEMENT_TYPE_FLOAT80,
ZYDIS_ELEMENT_TYPE_LONGBCD
};
/**
* @brief Defines the @c ZydisElementSize datatype.
*/
typedef uint16_t ZydisElementSize;
/* ---------------------------------------------------------------------------------------------- */
/* Decoded operand */
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/**
* @brief Defines the @c ZydisDecodedOperand struct.
@ -370,134 +164,9 @@ typedef struct ZydisDecodedOperand_
} ZydisDecodedOperand;
/* ============================================================================================== */
/* Instruction info */
/* Decoded instruction */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Machine mode */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisMachineMode datatype.
*/
typedef uint8_t ZydisMachineMode;
/**
* @brief Values that represent machine modes.
*/
enum ZydisMachineModes
{
ZYDIS_MACHINE_MODE_INVALID = 0,
/**
* @brief 64 bit mode.
*/
ZYDIS_MACHINE_MODE_LONG_64 = 64,
/**
* @brief 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_32 = 32,
/**
* @brief 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_16 = 16,
/**
* @brief 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_32 = 32,
/**
* @brief 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_16 = 16,
/**
* @brief 16 bit real mode.
*/
ZYDIS_MACHINE_MODE_REAL_16 = 16
};
/* ---------------------------------------------------------------------------------------------- */
/* Address width */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisAddressWidth datatype.
*/
typedef uint8_t ZydisAddressWidth;
/**
* @brief Values that represent address widths.
*/
enum ZydisAddressWidths
{
ZYDIS_ADDRESS_WIDTH_INVALID = 0,
ZYDIS_ADDRESS_WIDTH_16 = 16,
ZYDIS_ADDRESS_WIDTH_32 = 32,
ZYDIS_ADDRESS_WIDTH_64 = 64
};
/* ---------------------------------------------------------------------------------------------- */
/* Instruction encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisInstructionEncoding datatype.
*/
typedef uint8_t ZydisInstructionEncoding;
/**
* @brief Values that represent instruction-encodings.
*/
enum ZydisInstructionEncodings
{
/**
* @brief The instruction uses the default encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_DEFAULT = 0x00,
/**
* @brief The instruction uses the AMD 3DNow-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_3DNOW = 0x01,
/**
* @brief The instruction uses the AMD XOP-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_XOP = 0x02,
/**
* @brief The instruction uses the VEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_VEX = 0x03,
/**
* @brief The instruction uses the EVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_EVEX = 0x04,
/**
* @brief The instruction uses the MVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_MVEX = 0x05
};
/* ---------------------------------------------------------------------------------------------- */
/* Opcode map */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOpcodeMap map.
*/
typedef uint8_t ZydisOpcodeMap;
/**
* @brief Values that represent opcode-maps.
*/
enum ZydisOpcodeMaps
{
ZYDIS_OPCODE_MAP_DEFAULT = 0x00,
ZYDIS_OPCODE_MAP_EX0 = 0x01,
ZYDIS_OPCODE_MAP_0F = 0x02,
ZYDIS_OPCODE_MAP_0F38 = 0x03,
ZYDIS_OPCODE_MAP_0F3A = 0x04,
ZYDIS_OPCODE_MAP_XOP8 = 0x05,
ZYDIS_OPCODE_MAP_XOP9 = 0x06,
ZYDIS_OPCODE_MAP_XOPA = 0x07
};
/* ---------------------------------------------------------------------------------------------- */
/* Instruction attributes */
/* ---------------------------------------------------------------------------------------------- */

View File

@ -137,6 +137,14 @@
/* Utils */
/* ============================================================================================== */
/**
* @brief Declares a bitfield.
*/
#define ZYDIS_BITFIELD(x) : x
/**
* @brief Calculates the size of an array.
*/
#define ZYDIS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
/* ============================================================================================== */

View File

@ -27,9 +27,9 @@
#ifndef ZYDIS_FORMATTER_H
#define ZYDIS_FORMATTER_H
#include <Zydis/DecoderTypes.h>
#include <Zydis/Defines.h>
#include <Zydis/Status.h>
#include <Zydis/DecoderTypes.h>
#ifdef __cplusplus
extern "C" {

View File

@ -28,7 +28,7 @@
#define ZYDIS_MNEMONIC_H
#include <Zydis/Defines.h>
#include <Zydis/Types.h>
#include <Zydis/CommonTypes.h>
#ifdef __cplusplus
extern "C" {

View File

@ -28,7 +28,7 @@
#define ZYDIS_REGISTER_H
#include <Zydis/Defines.h>
#include <Zydis/Types.h>
#include <Zydis/CommonTypes.h>
#include <Zydis/Status.h>
#ifdef __cplusplus

382
include/Zydis/SharedTypes.h Normal file
View File

@ -0,0 +1,382 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
/**
* @file
* @brief Defines decoder/encoder-shared macros and types.
*/
#ifndef ZYDIS_SHAREDTYPES_H
#define ZYDIS_SHAREDTYPES_H
#include <Zydis/CommonTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_MAX_INSTRUCTION_LENGTH 15
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Machine mode */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisMachineMode datatype.
*/
typedef uint8_t ZydisMachineMode;
/**
* @brief Values that represent machine modes.
*/
enum ZydisMachineModes
{
ZYDIS_MACHINE_MODE_INVALID = 0,
/**
* @brief 64 bit mode.
*/
ZYDIS_MACHINE_MODE_LONG_64 = 64,
/**
* @brief 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_32 = 32,
/**
* @brief 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_16 = 16,
/**
* @brief 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_32 = 32,
/**
* @brief 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_16 = 16,
/**
* @brief 16 bit real mode.
*/
ZYDIS_MACHINE_MODE_REAL_16 = 16
};
/* ---------------------------------------------------------------------------------------------- */
/* Address width */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisAddressWidth datatype.
*/
typedef uint8_t ZydisAddressWidth;
/**
* @brief Values that represent address widths.
*/
enum ZydisAddressWidths
{
ZYDIS_ADDRESS_WIDTH_INVALID = 0,
ZYDIS_ADDRESS_WIDTH_16 = 16,
ZYDIS_ADDRESS_WIDTH_32 = 32,
ZYDIS_ADDRESS_WIDTH_64 = 64
};
/* ---------------------------------------------------------------------------------------------- */
/* Element types */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisElementType datatype.
*/
typedef uint8_t ZydisElementType;
/**
* @brief Values that represent element-types.
*/
enum ZydisElementTypes
{
ZYDIS_ELEMENT_TYPE_INVALID,
ZYDIS_ELEMENT_TYPE_STRUCT,
ZYDIS_ELEMENT_TYPE_UINT,
ZYDIS_ELEMENT_TYPE_INT,
ZYDIS_ELEMENT_TYPE_FLOAT16,
ZYDIS_ELEMENT_TYPE_FLOAT32,
ZYDIS_ELEMENT_TYPE_FLOAT64,
ZYDIS_ELEMENT_TYPE_FLOAT80,
ZYDIS_ELEMENT_TYPE_LONGBCD
};
/**
* @brief Defines the @c ZydisElementSize datatype.
*/
typedef uint16_t ZydisElementSize;
/* ---------------------------------------------------------------------------------------------- */
/* Operand type */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandType datatype.
*/
typedef uint8_t ZydisOperandType;
/**
* @brief Values that represent operand-types.
*/
enum ZydisOperandTypes
{
/**
* @brief The operand is not used.
*/
ZYDIS_OPERAND_TYPE_UNUSED,
/**
* @brief The operand is a register operand.
*/
ZYDIS_OPERAND_TYPE_REGISTER,
/**
* @brief The operand is a memory operand.
*/
ZYDIS_OPERAND_TYPE_MEMORY,
/**
* @brief The operand is a pointer operand with a segment:offset lvalue.
*/
ZYDIS_OPERAND_TYPE_POINTER,
/**
* @brief The operand is an immediate operand.
*/
ZYDIS_OPERAND_TYPE_IMMEDIATE
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandEncoding datatype.
*/
typedef uint8_t ZydisOperandEncoding;
/**
* @brief Values that represent operand-encodings.
*/
enum ZydisOperandEncodings
{
ZYDIS_OPERAND_ENCODING_NONE,
ZYDIS_OPERAND_ENCODING_MODRM_REG,
ZYDIS_OPERAND_ENCODING_MODRM_RM,
ZYDIS_OPERAND_ENCODING_OPCODE,
ZYDIS_OPERAND_ENCODING_NDSNDD,
ZYDIS_OPERAND_ENCODING_IS4,
ZYDIS_OPERAND_ENCODING_MASK,
ZYDIS_OPERAND_ENCODING_DISP8,
ZYDIS_OPERAND_ENCODING_DISP16,
ZYDIS_OPERAND_ENCODING_DISP32,
ZYDIS_OPERAND_ENCODING_DISP64,
ZYDIS_OPERAND_ENCODING_DISP16_32_64,
ZYDIS_OPERAND_ENCODING_DISP32_32_64,
ZYDIS_OPERAND_ENCODING_DISP16_32_32,
ZYDIS_OPERAND_ENCODING_UIMM8,
ZYDIS_OPERAND_ENCODING_UIMM16,
ZYDIS_OPERAND_ENCODING_UIMM32,
ZYDIS_OPERAND_ENCODING_UIMM64,
ZYDIS_OPERAND_ENCODING_UIMM16_32_64,
ZYDIS_OPERAND_ENCODING_UIMM32_32_64,
ZYDIS_OPERAND_ENCODING_UIMM16_32_32,
ZYDIS_OPERAND_ENCODING_SIMM8,
ZYDIS_OPERAND_ENCODING_SIMM16,
ZYDIS_OPERAND_ENCODING_SIMM32,
ZYDIS_OPERAND_ENCODING_SIMM64,
ZYDIS_OPERAND_ENCODING_SIMM16_32_64,
ZYDIS_OPERAND_ENCODING_SIMM32_32_64,
ZYDIS_OPERAND_ENCODING_SIMM16_32_32,
ZYDIS_OPERAND_ENCODING_JIMM8,
ZYDIS_OPERAND_ENCODING_JIMM16,
ZYDIS_OPERAND_ENCODING_JIMM32,
ZYDIS_OPERAND_ENCODING_JIMM64,
ZYDIS_OPERAND_ENCODING_JIMM16_32_64,
ZYDIS_OPERAND_ENCODING_JIMM32_32_64,
ZYDIS_OPERAND_ENCODING_JIMM16_32_32
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand visibility */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandVisibility datatype.
*/
typedef uint8_t ZydisOperandVisibility;
/**
* @brief Values that represent operand-visibilities.
*/
enum ZydisOperandVisibilities
{
ZYDIS_OPERAND_VISIBILITY_INVALID,
/**
* @brief The operand is explicitly encoded in the instruction.
*/
ZYDIS_OPERAND_VISIBILITY_EXPLICIT,
/**
* @brief The operand is part of the opcode, but listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_IMPLICIT,
/**
* @brief The operand is part of the opcode, and not typically listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_HIDDEN
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand action */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOperandAction datatype.
*/
typedef uint8_t ZydisOperandAction;
/**
* @brief Values that represent operand-actions.
*/
enum ZydisOperandActions
{
ZYDIS_OPERAND_ACTION_INVALID,
/**
* @brief The operand is read by the instruction.
*/
ZYDIS_OPERAND_ACTION_READ,
/**
* @brief The operand is written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_WRITE,
/**
* @brief The operand is read and written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_READWRITE,
/**
* @brief The operand is conditionally read by the instruction.
*/
ZYDIS_OPERAND_ACTION_CONDREAD,
/**
* @brief The operand is conditionally written by the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_CONDWRITE,
/**
* @brief The operand is read and conditionally written by the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_READ_CONDWRITE,
/**
* @brief The operand is written and conditionally read by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_CONDREAD_WRITE,
};
/* ---------------------------------------------------------------------------------------------- */
/* Instruction encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisInstructionEncoding datatype.
*/
typedef uint8_t ZydisInstructionEncoding;
/**
* @brief Values that represent instruction-encodings.
*/
enum ZydisInstructionEncodings
{
ZYDIS_INSTRUCTION_ENCODING_INVALID,
/**
* @brief The instruction uses the default encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_DEFAULT,
/**
* @brief The instruction uses the AMD 3DNow-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_3DNOW,
/**
* @brief The instruction uses the AMD XOP-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_XOP,
/**
* @brief The instruction uses the VEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_VEX,
/**
* @brief The instruction uses the EVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_EVEX,
/**
* @brief The instruction uses the MVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_MVEX
};
/* ---------------------------------------------------------------------------------------------- */
/* Opcode map */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisOpcodeMap map.
*/
typedef uint8_t ZydisOpcodeMap;
/**
* @brief Values that represent opcode-maps.
*/
enum ZydisOpcodeMaps
{
ZYDIS_OPCODE_MAP_DEFAULT = 0x00,
ZYDIS_OPCODE_MAP_EX0 = 0x01,
ZYDIS_OPCODE_MAP_0F = 0x02,
ZYDIS_OPCODE_MAP_0F38 = 0x03,
ZYDIS_OPCODE_MAP_0F3A = 0x04,
ZYDIS_OPCODE_MAP_XOP8 = 0x05,
ZYDIS_OPCODE_MAP_XOP9 = 0x06,
ZYDIS_OPCODE_MAP_XOPA = 0x07
};
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_SHAREDTYPES_H */

View File

@ -27,7 +27,7 @@
#ifndef ZYDIS_STATUS_H
#define ZYDIS_STATUS_H
#include <Zydis/Types.h>
#include <Zydis/CommonTypes.h>
#ifdef __cplusplus
extern "C" {

View File

@ -27,14 +27,15 @@
#ifndef ZYDIS_H
#define ZYDIS_H
#include <Zydis/Defines.h>
#include <Zydis/Types.h>
#include <Zydis/Status.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/CommonTypes.h>
#include <Zydis/Decoder.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Defines.h>
#include <Zydis/Formatter.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#include <Zydis/Status.h>
#include <Zydis/Utils.h>
#ifdef __cplusplus

View File

@ -25,9 +25,10 @@
***************************************************************************************************/
#include <string.h>
#include <Zydis/Status.h>
#include <Zydis/Decoder.h>
#include <InstructionTable.h>
#include <Zydis/Status.h>
#include <DecoderData.h>
#include <SharedData.h>
/* ============================================================================================== */
/* Internal enums and types */
@ -3142,18 +3143,18 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context,
*
* @param context A pointer to the @c ZydisDecoderContext struct.
* @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param info A pointer to the @c ZydisInstructionParts struct.
* @param info A pointer to the @c ZydisInstructionEncodingInfo struct.
*
* @return A zydis status code.
*/
static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
ZydisDecodedInstruction* instruction, const ZydisPhysicalInstructionInfo* info)
static ZydisStatus ZydisDecodeOptionalInstructionParts(ZydisDecoderContext* context,
ZydisDecodedInstruction* instruction, const ZydisInstructionEncodingInfo* info)
{
ZYDIS_ASSERT(context);
ZYDIS_ASSERT(instruction);
ZYDIS_ASSERT(info);
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_MODRM)
if (info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_MODRM)
{
if (!instruction->raw.modrm.isDecoded)
{
@ -3163,7 +3164,7 @@ static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
}
uint8_t hasSIB = 0;
uint8_t displacementSize = 0;
if (!(info->flags & ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM))
if (!(info->flags & ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM))
{
switch (instruction->addressWidth)
{
@ -3235,13 +3236,13 @@ static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
}
}
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_DISP)
if (info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_DISP)
{
ZYDIS_CHECK(ZydisReadDisplacement(
context, instruction, info->disp.size[context->easzIndex]));
}
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_IMM0)
if (info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_IMM0)
{
if (info->imm[0].isRelative)
{
@ -3251,9 +3252,9 @@ static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
info->imm[0].size[context->eoszIndex], info->imm[0].isSigned, info->imm[0].isRelative));
}
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_IMM1)
if (info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_IMM1)
{
ZYDIS_ASSERT(!(info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_DISP));
ZYDIS_ASSERT(!(info->flags & ZYDIS_INSTR_ENC_FLAG_HAS_DISP));
ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 1,
info->imm[1].size[context->eoszIndex], info->imm[1].isSigned, info->imm[1].isRelative));
}
@ -4162,7 +4163,7 @@ static ZydisStatus ZydisCheckErrorConditions(ZydisDecoderContext* context,
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Uses the instruction-tree to decode the current instruction.
* @brief Uses the decoder-tree to decode the current instruction.
*
* @param context A pointer to the @c ZydisDecoderContext instance.
* @param instruction A pointer to the @c ZydisDecodedInstruction struct.
@ -4175,10 +4176,10 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
ZYDIS_ASSERT(context);
ZYDIS_ASSERT(instruction);
// Iterate through the instruction table
const ZydisInstructionTreeNode* node = ZydisInstructionTreeGetRootNode();
const ZydisInstructionTreeNode* temp = NULL;
ZydisInstructionTreeNodeType nodeType;
// Iterate through the decoder tree
const ZydisDecoderTreeNode* node = ZydisDecoderTreeGetRootNode();
const ZydisDecoderTreeNode* temp = NULL;
ZydisDecoderTreeNodeType nodeType;
do
{
nodeType = node->type;
@ -4231,7 +4232,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
break;
case ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX:
status = ZydisNodeHandlerMandatoryPrefix(context, instruction, &index);
temp = ZydisInstructionTreeGetChildNode(node, 0);
temp = ZydisDecoderTreeGetChildNode(node, 0);
// TODO: Return to this point, if index == 0 contains a value and the previous path
// TODO: was not successfull
// TODO: Restore consumed prefix
@ -4264,30 +4265,31 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
if (nodeType & ZYDIS_NODETYPE_DEFINITION_MASK)
{
const ZydisInstructionDefinition* definition;
ZydisGetInstructionDefinition(node, &definition);
ZydisGetInstructionDefinition(instruction->encoding, node->value, &definition);
ZydisSetEffectiveOperandSize(context, instruction, definition);
ZydisSetEffectiveAddressWidth(context, instruction);
const ZydisPhysicalInstructionInfo* info;
ZydisGetPhysicalInstructionInfo(node, &info);
ZYDIS_CHECK(ZydisDecodeInstructionPhysical(context, instruction, info));
const ZydisInstructionEncodingInfo* info;
ZydisGetInstructionEncodingInfo(node, &info);
ZYDIS_CHECK(ZydisDecodeOptionalInstructionParts(context, instruction, info));
if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_3DNOW)
{
// Get actual 3dnow opcode and definition
ZYDIS_CHECK(ZydisInputNext(context, instruction, &instruction->opcode));
node = ZydisInstructionTreeGetRootNode();
node = ZydisInstructionTreeGetChildNode(node, 0x0F);
node = ZydisInstructionTreeGetChildNode(node, 0x0F);
node = ZydisInstructionTreeGetChildNode(node, instruction->opcode);
node = ZydisDecoderTreeGetRootNode();
node = ZydisDecoderTreeGetChildNode(node, 0x0F);
node = ZydisDecoderTreeGetChildNode(node, 0x0F);
node = ZydisDecoderTreeGetChildNode(node, instruction->opcode);
if (node->type == ZYDIS_NODETYPE_INVALID)
{
return ZYDIS_STATUS_DECODING_ERROR;
}
ZYDIS_ASSERT(node->type == ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT);
node = ZydisInstructionTreeGetChildNode(
node = ZydisDecoderTreeGetChildNode(
node, (instruction->raw.modrm.mod == 0x3) ? 0 : 1);
ZydisGetInstructionDefinition(node, &definition);
ZYDIS_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK);
ZydisGetInstructionDefinition(instruction->encoding, node->value, &definition);
}
ZYDIS_CHECK(ZydisCheckErrorConditions(context, instruction, definition));
@ -4316,7 +4318,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
ZYDIS_UNREACHABLE;
}
ZYDIS_CHECK(status);
node = ZydisInstructionTreeGetChildNode(node, index);
node = ZydisDecoderTreeGetChildNode(node, index);
} while((nodeType != ZYDIS_NODETYPE_INVALID) && !(nodeType & ZYDIS_NODETYPE_DEFINITION_MASK));
return ZYDIS_STATUS_SUCCESS;
}
@ -4392,6 +4394,7 @@ ZydisStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, const void* bu
void* userData = instruction->userData;
memset(instruction, 0, sizeof(*instruction));
instruction->machineMode = decoder->machineMode;
instruction->encoding = ZYDIS_INSTRUCTION_ENCODING_DEFAULT;
instruction->instrAddress = instructionPointer;
instruction->userData = userData;

View File

@ -24,8 +24,7 @@
***************************************************************************************************/
#include <assert.h>
#include <InstructionTable.h>
#include <DecoderData.h>
/* ============================================================================================== */
/* Data tables */
@ -44,7 +43,7 @@
* 2 = xop9
* 3 = xopA
*/
extern const ZydisInstructionTreeNode filtersXOP[][4];
extern const ZydisDecoderTreeNode filtersXOP[][4];
/**
* @brief Contains all VEX-map filters.
@ -68,7 +67,7 @@ extern const ZydisInstructionTreeNode filtersXOP[][4];
* 0F = F2_0F38
* 10 = F2_0F3A
*/
extern const ZydisInstructionTreeNode filtersVEX[][17];
extern const ZydisDecoderTreeNode filtersVEX[][17];
/**
* @brief Contains all EVEX/MVEX-map filters.
@ -108,14 +107,14 @@ extern const ZydisInstructionTreeNode filtersVEX[][17];
* 1F = MVEX F2_0F38
* 20 = MVEX F2_0F3A
*/
extern const ZydisInstructionTreeNode filtersEMVEX[][33];
extern const ZydisDecoderTreeNode filtersEMVEX[][33];
/**
* @brief Contains all opcode filters.
*
* Indexed by the numeric value of the opcode.
*/
extern const ZydisInstructionTreeNode filtersOpcode[][256];
extern const ZydisDecoderTreeNode filtersOpcode[][256];
/**
* @brief Contains all instruction-mode filters.
@ -125,7 +124,7 @@ extern const ZydisInstructionTreeNode filtersOpcode[][256];
* 1 = 32 bit mode
* 2 = 64 bit mode
*/
extern const ZydisInstructionTreeNode filtersMode[][3];
extern const ZydisDecoderTreeNode filtersMode[][3];
/**
* @brief Contains all compacted instruction-mode filters.
@ -134,14 +133,14 @@ extern const ZydisInstructionTreeNode filtersMode[][3];
* 0 = 64 bit mode
* 1 = not 64 bit mode
*/
extern const ZydisInstructionTreeNode filtersModeCompact[][2];
extern const ZydisDecoderTreeNode filtersModeCompact[][2];
/**
* @brief Contains all ModRM.mod filters.
*
* Indexed by the ordinal value of the ModRM.mod field.
*/
extern const ZydisInstructionTreeNode filtersModrmMod[][4];
extern const ZydisDecoderTreeNode filtersModrmMod[][4];
/**
* @brief Contains all compacted ModRM.mod filters.
@ -150,21 +149,21 @@ extern const ZydisInstructionTreeNode filtersModrmMod[][4];
* 0 = [ModRM.mod == 11] = register
* 1 = [ModRM.mod == !11] = memory
*/
extern const ZydisInstructionTreeNode filtersModrmModCompact[][2];
extern const ZydisDecoderTreeNode filtersModrmModCompact[][2];
/**
* @brief Contains all ModRM.reg filters.
*
* Indexed by the numeric value of the ModRM.reg field.
*/
extern const ZydisInstructionTreeNode filtersModrmReg[][8];
extern const ZydisDecoderTreeNode filtersModrmReg[][8];
/**
* @brief Contains all ModRM.rm filters.
*
* Indexed by the numeric value of the ModRM.rm field.
*/
extern const ZydisInstructionTreeNode filtersModrmRm[][8];
extern const ZydisDecoderTreeNode filtersModrmRm[][8];
/**
* @brief Contains all mandatory-prefix switch tables.
@ -176,7 +175,7 @@ extern const ZydisInstructionTreeNode filtersModrmRm[][8];
* 3 = F3
* 4 = F2
*/
extern const ZydisInstructionTreeNode filtersMandatoryPrefix[][5];
extern const ZydisDecoderTreeNode filtersMandatoryPrefix[][5];
/**
* @brief Contains all operand-size filters.
@ -186,7 +185,7 @@ extern const ZydisInstructionTreeNode filtersMandatoryPrefix[][5];
* 1 = 32 bit
* 2 = 64 bit
*/
extern const ZydisInstructionTreeNode filtersOperandSize[][3];
extern const ZydisDecoderTreeNode filtersOperandSize[][3];
/**
* @brief Contains all address-size filters.
@ -196,7 +195,7 @@ extern const ZydisInstructionTreeNode filtersOperandSize[][3];
* 1 = 32 bit
* 2 = 64 bit
*/
extern const ZydisInstructionTreeNode filtersAddressSize[][3];
extern const ZydisDecoderTreeNode filtersAddressSize[][3];
/**
* @brief Contains all vector-length filters.
@ -206,81 +205,42 @@ extern const ZydisInstructionTreeNode filtersAddressSize[][3];
* 1 = 256 bit
* 2 = 512 bit
*/
extern const ZydisInstructionTreeNode filtersVectorLength[][3];
extern const ZydisDecoderTreeNode filtersVectorLength[][3];
/**
* @brief Contains all REX/VEX/EVEX.w filters.
*
* Indexed by the numeric value of the REX/VEX/EVEX.w field.
*/
extern const ZydisInstructionTreeNode filtersREXW[][2];
extern const ZydisDecoderTreeNode filtersREXW[][2];
/**
* @brief Contains all REX/VEX/EVEX.B filters.
*
* Indexed by the numeric value of the REX/VEX/EVEX.B field.
*/
extern const ZydisInstructionTreeNode filtersREXB[][2];
extern const ZydisDecoderTreeNode filtersREXB[][2];
/**
* @brief Contains all EVEX.b filters.
*
* Indexed by the numeric value of the EVEX.b field.
*/
extern const ZydisInstructionTreeNode filtersEVEXB[][2];
extern const ZydisDecoderTreeNode filtersEVEXB[][2];
/**
* @brief Contains all EVEX.z filters.
*
* Indexed by the numeric value of the EVEX.z field.
*/
extern const ZydisInstructionTreeNode filtersEVEXZ[][2];
extern const ZydisDecoderTreeNode filtersEVEXZ[][2];
/**
* @brief Contains all MVEX.E filters.
*
* Indexed by the numeric value of the MVEX.E field.
*/
extern const ZydisInstructionTreeNode filtersMVEXE[][2];
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Contains all operand-definitions.
*/
extern const ZydisOperandDefinition operandDefinitions[];
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Contains all instruction-definitions with @c DEFAULT encoding.
*/
extern const ZydisInstructionDefinitionDEFAULT instructionDefinitionsDEFAULT[];
/**
* @brief Contains all instruction-definitions with @c 3DNOW encoding.
*/
extern const ZydisInstructionDefinition3DNOW instructionDefinitions3DNOW[];
/**
* @brief Contains all instruction-definitions with @c XOP encoding.
*/
extern const ZydisInstructionDefinitionXOP instructionDefinitionsXOP[];
/**
* @brief Contains all instruction-definitions with @c VEX encoding.
*/
extern const ZydisInstructionDefinitionVEX instructionDefinitionsVEX[];
/**
* @brief Contains all instruction-definitions with @c EVEX encoding.
*/
extern const ZydisInstructionDefinitionEVEX instructionDefinitionsEVEX[];
/**
* @brief Contains all instruction-definitions with @c MVEX encoding.
*/
extern const ZydisInstructionDefinitionMVEX instructionDefinitionsMVEX[];
extern const ZydisDecoderTreeNode filtersMVEXE[][2];
/* ---------------------------------------------------------------------------------------------- */
/* Physical instruction encodings */
@ -289,15 +249,15 @@ extern const ZydisInstructionDefinitionMVEX instructionDefinitionsMVEX[];
#include <Generated/PhysicalEncodings.inc>
/* ---------------------------------------------------------------------------------------------- */
/* Instruction tree */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_INVALID \
{ ZYDIS_NODETYPE_INVALID, 0x00000000 }
#define ZYDIS_FILTER(type, id) \
{ type, id }
#define ZYDIS_DEFINITION(encoding, instrclass, id) \
{ ZYDIS_NODETYPE_DEFINITION_MASK | instrclass, (encoding << 13) | id }
#define ZYDIS_DEFINITION(encoding_id, id) \
{ ZYDIS_NODETYPE_DEFINITION_MASK | encoding_id, id }
#include <Generated/InstructionFilters.inc>
@ -306,40 +266,23 @@ extern const ZydisInstructionDefinitionMVEX instructionDefinitionsMVEX[];
#undef ZYDIS_DEFINITION
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definitions */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/InstructionDefinitions.inc>
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Operand definitions */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_OPERAND_DEFINITION(type, encoding, access) \
{ type, encoding, access }
#include <Generated/OperandDefinitions.inc>
#undef ZYDIS_OPERAND_DEFINITION
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction tree */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
const ZydisInstructionTreeNode* ZydisInstructionTreeGetRootNode()
const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode()
{
static const ZydisInstructionTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x00000000 };
static const ZydisDecoderTreeNode root = { ZYDIS_NODETYPE_FILTER_OPCODE, 0x00000000 };
return &root;
}
const ZydisInstructionTreeNode* ZydisInstructionTreeGetChildNode(
const ZydisInstructionTreeNode* parent, uint16_t index)
const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(const ZydisDecoderTreeNode* parent,
uint16_t index)
{
switch (parent->type)
{
@ -403,51 +346,12 @@ const ZydisInstructionTreeNode* ZydisInstructionTreeGetChildNode(
default:
ZYDIS_UNREACHABLE;
}
static const ZydisInstructionTreeNode invalid = { ZYDIS_NODETYPE_INVALID, 0x00000000 };
static const ZydisDecoderTreeNode invalid = { ZYDIS_NODETYPE_INVALID, 0x00000000 };
return &invalid;
}
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
void ZydisGetInstructionDefinition(const ZydisInstructionTreeNode* node,
const ZydisInstructionDefinition** definition)
{
ZYDIS_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK);
switch ((node->value >> 13) & 0x07)
{
case ZYDIS_INSTRUCTION_ENCODING_DEFAULT:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitionsDEFAULT[node->value & 0x1FFF];
break;
case ZYDIS_INSTRUCTION_ENCODING_3DNOW:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitions3DNOW[node->value & 0x1FFF];
break;
case ZYDIS_INSTRUCTION_ENCODING_XOP:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitionsXOP[node->value & 0x1FFF];
break;
case ZYDIS_INSTRUCTION_ENCODING_VEX:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitionsVEX[node->value & 0x1FFF];
break;
case ZYDIS_INSTRUCTION_ENCODING_EVEX:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitionsEVEX[node->value & 0x1FFF];
break;
case ZYDIS_INSTRUCTION_ENCODING_MVEX:
*definition =
(ZydisInstructionDefinition*)&instructionDefinitionsMVEX[node->value & 0x1FFF];
break;
default:
ZYDIS_UNREACHABLE;
}
}
void ZydisGetPhysicalInstructionInfo(const ZydisInstructionTreeNode* node,
const ZydisPhysicalInstructionInfo** info)
void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,
const ZydisInstructionEncodingInfo** info)
{
ZYDIS_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK);
uint8_t class = (node->type) & 0x7F;
@ -455,65 +359,4 @@ void ZydisGetPhysicalInstructionInfo(const ZydisInstructionTreeNode* node,
*info = &physicalEncodings[class];
}
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
uint8_t ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition,
const ZydisOperandDefinition** operands)
{
if (definition->operandCount == 0)
{
*operands = NULL;
return 0;
}
ZYDIS_ASSERT(definition->operandReference != 0xFFFF);
*operands = &operandDefinitions[definition->operandReference];
return definition->operandCount;
}
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
/* ---------------------------------------------------------------------------------------------- */
void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
ZydisElementSize* size)
{
static const struct
{
ZydisElementType type;
ZydisElementSize size;
} lookup[21] =
{
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_STRUCT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 0 },
{ ZYDIS_ELEMENT_TYPE_UINT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 1 },
{ ZYDIS_ELEMENT_TYPE_INT , 8 },
{ ZYDIS_ELEMENT_TYPE_INT , 16 },
{ ZYDIS_ELEMENT_TYPE_INT , 32 },
{ ZYDIS_ELEMENT_TYPE_INT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 8 },
{ ZYDIS_ELEMENT_TYPE_UINT , 16 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 },
{ ZYDIS_ELEMENT_TYPE_UINT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 128 },
{ ZYDIS_ELEMENT_TYPE_UINT , 256 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 16 },
{ ZYDIS_ELEMENT_TYPE_FLOAT32 , 32 },
{ ZYDIS_ELEMENT_TYPE_FLOAT64 , 64 },
{ ZYDIS_ELEMENT_TYPE_FLOAT80 , 80 },
{ ZYDIS_ELEMENT_TYPE_LONGBCD , 80 }
};
ZYDIS_ASSERT(element < ZYDIS_ARRAY_SIZE(lookup));
*type = lookup[element].type;
*size = lookup[element].size;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */

292
src/DecoderData.h Normal file
View File

@ -0,0 +1,292 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYDIS_INSTRUCTIONTABLE_H
#define ZYDIS_INSTRUCTIONTABLE_H
#include <Zydis/Defines.h>
#include <Zydis/DecoderTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
// MSVC does not like types other than (un-)signed int for bitfields
#ifdef ZYDIS_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisDecoderTreeNodeType datatype.
*/
typedef uint8_t ZydisDecoderTreeNodeType;
/**
* @brief Values that represent zydis decoder tree node types.
*/
enum ZydisDecoderTreeNodeTypes
{
ZYDIS_NODETYPE_INVALID = 0x00,
/**
* @brief Reference to an instruction-definition.
*/
ZYDIS_NODETYPE_DEFINITION_MASK = 0x80,
/**
* @brief Reference to an XOP-map filter.
*/
ZYDIS_NODETYPE_FILTER_XOP = 0x01,
/**
* @brief Reference to an VEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_VEX = 0x02,
/**
* @brief Reference to an EVEX/MVEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_EMVEX = 0x03,
/**
* @brief Reference to an opcode filter.
*/
ZYDIS_NODETYPE_FILTER_OPCODE = 0x04,
/**
* @brief Reference to an instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE = 0x05,
/**
* @brief Reference to an compacted instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x06,
/**
* @brief Reference to a ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x07,
/**
* @brief Reference to a compacted ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08,
/**
* @brief Reference to a ModRM.reg filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09,
/**
* @brief Reference to a ModRM.rm filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0A,
/**
* @brief Reference to a mandatory-prefix filter.
*/
ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0B,
/**
* @brief Reference to an operand-size filter.
*/
ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0C,
/**
* @brief Reference to an address-size filter.
*/
ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0D,
/**
* @brief Reference to a vector-length filter.
*/
ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x0E,
/**
* @brief Reference to an REX/VEX/EVEX.W filter.
*/
ZYDIS_NODETYPE_FILTER_REX_W = 0x0F,
/**
* @brief Reference to an REX/VEX/EVEX.B filter.
*/
ZYDIS_NODETYPE_FILTER_REX_B = 0x10,
/**
* @brief Reference to an EVEX.b filter.
*/
ZYDIS_NODETYPE_FILTER_EVEX_B = 0x11,
/**
* @brief Reference to an EVEX.z filter.
*/
ZYDIS_NODETYPE_FILTER_EVEX_Z = 0x12,
/**
* @brief Reference to an MVEX.E filter.
*/
ZYDIS_NODETYPE_FILTER_MVEX_E = 0x13,
};
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisDecoderTreeNodeValue datatype.
*/
typedef uint16_t ZydisDecoderTreeNodeValue;
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisDecoderTreeNode struct.
*/
typedef struct ZydisDecoderTreeNode_
{
ZydisDecoderTreeNodeType type;
ZydisDecoderTreeNodeValue value;
} ZydisDecoderTreeNode;
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYDIS_MSVC
# pragma warning(pop)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Physical instruction encoding info */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisInstructionEncodingFlags datatype.
*/
typedef uint8_t ZydisInstructionEncodingFlags;
/**
* @brief The instruction has an optional modrm byte.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01
/**
* @brief The instruction has an optional displacement value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02
/**
* @brief The instruction has an optional immediate value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04
/**
* @brief The instruction has a second optional immediate value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08
/**
* @brief The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3`
* ("reg, reg" - form).
*
* Instructions with this flag can't have a SIB byte or a displacement value.
*/
#define ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM 0x10
/**
* @brief Defines the @c ZydisInstructionEncodingInfo struct.
*/
typedef struct ZydisInstructionEncodingInfo_
{
/**
* @brief Contains flags with information about the physical instruction-encoding.
*/
ZydisInstructionEncodingFlags flags;
/**
* @brief Displacement info.
*/
struct
{
/**
* @brief The size of the displacement value.
*/
uint8_t size[3];
} disp;
/**
* @brief Immediate info.
*/
struct
{
/**
* @brief The size of the immediate value.
*/
uint8_t size[3];
/**
* @brief Signals, if the value is signed.
*/
ZydisBool isSigned;
/**
* @brief Signals, if the value is a relative offset.
*/
ZydisBool isRelative;
} imm[2];
} ZydisInstructionEncodingInfo;
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Returns the root node of the instruction tree.
*
* @return The root node of the instruction tree.
*/
ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode();
/**
* @brief Returns the child node of @c parent specified by @c index.
*
* @param parent The parent node.
* @param index The index of the child node to retrieve.
*
* @return The specified child node.
*/
ZYDIS_NO_EXPORT const ZydisDecoderTreeNode* ZydisDecoderTreeGetChildNode(
const ZydisDecoderTreeNode* parent, uint16_t index);
/**
* @brief Returns information about optional instruction parts (like modrm, displacement or
* immediates) for the instruction that is linked to the given @c node.
*
* @param node The instruction definition node.
* @param info A pointer to the @c ZydisInstructionParts struct.
*/
ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,
const ZydisInstructionEncodingInfo** info);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_INSTRUCTIONTABLE_H */

117
src/EncoderData.c Normal file
View File

@ -0,0 +1,117 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#include <EncoderData.h>
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
// MSVC does not like types other than (un-)signed int for bitfields
#ifdef ZYDIS_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Encodable instructions */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisEncodableInstructions struct.
*/
typedef struct ZydisEncodableInstructions_
{
uint8_t count;
uint16_t reference;
} ZydisEncodableInstructions;
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYDIS_MSVC
# pragma warning(pop)
#endif
/* ============================================================================================== */
/* Data tables */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Forward declarations */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Contains an item with a reference to all encodable instructions for every mnemonic.
*/
extern const ZydisEncodableInstructions mnemonicLookup[];
/**
* @brief Contains the definition-data for all encodable instructions.
*/
extern const ZydisEncodableInstruction encodableInstructions[];
/* ---------------------------------------------------------------------------------------------- */
/* Mnemonic lookup table */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/EncoderLookup.inc>
/* ---------------------------------------------------------------------------------------------- */
/* Encodable instructions */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/EncodableInstructions.inc>
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Encodable instructions */
/* ---------------------------------------------------------------------------------------------- */
uint8_t ZydisGetEncodableInstructions(ZydisMnemonic mnemonic,
const ZydisEncodableInstruction** instruction)
{
if (mnemonic >= ZYDIS_ARRAY_SIZE(mnemonicLookup))
{
*instruction = NULL;
return 0;
}
const ZydisEncodableInstructions* descriptor = &mnemonicLookup[mnemonic];
*instruction = &encodableInstructions[descriptor->reference];
return descriptor->count;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */

115
src/EncoderData.h Normal file
View File

@ -0,0 +1,115 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#ifndef ZYDIS_ENCODERDATA_H
#define ZYDIS_ENCODERDATA_H
#include <Zydis/Defines.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/SharedTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
// MSVC does not like types other than (un-)signed int for bitfields
#ifdef ZYDIS_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Encodable instruction */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisEncodableInstruction struct.
*/
typedef struct ZydisEncodableInstruction_
{
ZydisInstructionEncoding encoding ZYDIS_BITFIELD( 3);
uint16_t definitionReference ZYDIS_BITFIELD(13);
struct
{
uint8_t mode ZYDIS_BITFIELD( 2);
uint8_t modrmMod ZYDIS_BITFIELD( 3);
uint8_t modrmReg ZYDIS_BITFIELD( 4);
uint8_t modrmRm ZYDIS_BITFIELD( 4);
uint8_t mandatoryPrefix ZYDIS_BITFIELD( 3);
uint8_t operandSize ZYDIS_BITFIELD( 2);
uint8_t addressSize ZYDIS_BITFIELD( 2);
uint8_t vectorLength ZYDIS_BITFIELD( 2);
uint8_t rexW ZYDIS_BITFIELD( 2);
uint8_t rexB ZYDIS_BITFIELD( 2);
uint8_t evexB ZYDIS_BITFIELD( 2);
uint8_t evexZ ZYDIS_BITFIELD( 2);
uint8_t mvexE ZYDIS_BITFIELD( 2);
} filterIndizes;
} ZydisEncodableInstruction;
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYDIS_MSVC
# pragma warning(pop)
#endif
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Encodable instructions */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Returns all encodable instructions matching the given `mnemonic`.
*
* @param mnemonic The mnemonic.
* @param instruction A pointer to the variable that receives a pointer to the first
* `ZydisEncodableInstruction` struct.
*
* @return The number of encodable instructions for the given mnemonic.
*/
ZYDIS_NO_EXPORT uint8_t ZydisGetEncodableInstructions(ZydisMnemonic mnemonic,
const ZydisEncodableInstruction** instruction);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_ENCODERDATA_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,21 @@
static const ZydisPhysicalInstructionInfo physicalEncodings[] =
static const ZydisInstructionEncodingInfo physicalEncodings[] =
{
/*00*/ { 0, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*01*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*02*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*03*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*04*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*05*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*06*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*07*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*08*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*09*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0A*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0B*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0C*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0D*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_DISP, { { 16, 32, 64 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0E*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 64 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0F*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*10*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*11*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } }
/*01*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*02*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*03*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*04*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*05*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*06*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*07*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*08*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*09*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0A*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0B*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0C*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0D*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_DISP, { { 16, 32, 64 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0E*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 64 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0F*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_FORCE_REG_FORM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*10*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*11*/ { 0 | ZYDIS_INSTR_ENC_FLAG_HAS_MODRM | ZYDIS_INSTR_ENC_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } }
};

190
src/SharedData.c Normal file
View File

@ -0,0 +1,190 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
***************************************************************************************************/
#include <SharedData.h>
/* ============================================================================================== */
/* Data tables */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Forward declarations */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Contains all operand-definitions.
*/
extern const ZydisOperandDefinition operandDefinitions[];
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Contains all instruction-definitions with @c DEFAULT encoding.
*/
extern const ZydisInstructionDefinitionDEFAULT instructionDefinitionsDEFAULT[];
/**
* @brief Contains all instruction-definitions with @c 3DNOW encoding.
*/
extern const ZydisInstructionDefinition3DNOW instructionDefinitions3DNOW[];
/**
* @brief Contains all instruction-definitions with @c XOP encoding.
*/
extern const ZydisInstructionDefinitionXOP instructionDefinitionsXOP[];
/**
* @brief Contains all instruction-definitions with @c VEX encoding.
*/
extern const ZydisInstructionDefinitionVEX instructionDefinitionsVEX[];
/**
* @brief Contains all instruction-definitions with @c EVEX encoding.
*/
extern const ZydisInstructionDefinitionEVEX instructionDefinitionsEVEX[];
/**
* @brief Contains all instruction-definitions with @c MVEX encoding.
*/
extern const ZydisInstructionDefinitionMVEX instructionDefinitionsMVEX[];
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definitions */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/InstructionDefinitions.inc>
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Operand definitions */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_OPERAND_DEFINITION(type, encoding, access) \
{ type, encoding, access }
#include <Generated/OperandDefinitions.inc>
#undef ZYDIS_OPERAND_DEFINITION
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding, uint16_t id,
const ZydisInstructionDefinition** definition)
{
switch (encoding)
{
case ZYDIS_INSTRUCTION_ENCODING_DEFAULT:
*definition = (ZydisInstructionDefinition*)&instructionDefinitionsDEFAULT[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_3DNOW:
*definition = (ZydisInstructionDefinition*)&instructionDefinitions3DNOW[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_XOP:
*definition = (ZydisInstructionDefinition*)&instructionDefinitionsXOP[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_VEX:
*definition = (ZydisInstructionDefinition*)&instructionDefinitionsVEX[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_EVEX:
*definition = (ZydisInstructionDefinition*)&instructionDefinitionsEVEX[id];
break;
case ZYDIS_INSTRUCTION_ENCODING_MVEX:
*definition = (ZydisInstructionDefinition*)&instructionDefinitionsMVEX[id];
break;
default:
ZYDIS_UNREACHABLE;
}
}
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
uint8_t ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition,
const ZydisOperandDefinition** operand)
{
if (definition->operandCount == 0)
{
*operand = NULL;
return 0;
}
ZYDIS_ASSERT(definition->operandReference != 0xFFFF);
*operand = &operandDefinitions[definition->operandReference];
return definition->operandCount;
}
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
/* ---------------------------------------------------------------------------------------------- */
void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
ZydisElementSize* size)
{
static const struct
{
ZydisElementType type;
ZydisElementSize size;
} lookup[21] =
{
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_INVALID , 0 },
{ ZYDIS_ELEMENT_TYPE_STRUCT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 0 },
{ ZYDIS_ELEMENT_TYPE_UINT , 0 },
{ ZYDIS_ELEMENT_TYPE_INT , 1 },
{ ZYDIS_ELEMENT_TYPE_INT , 8 },
{ ZYDIS_ELEMENT_TYPE_INT , 16 },
{ ZYDIS_ELEMENT_TYPE_INT , 32 },
{ ZYDIS_ELEMENT_TYPE_INT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 8 },
{ ZYDIS_ELEMENT_TYPE_UINT , 16 },
{ ZYDIS_ELEMENT_TYPE_UINT , 32 },
{ ZYDIS_ELEMENT_TYPE_UINT , 64 },
{ ZYDIS_ELEMENT_TYPE_UINT , 128 },
{ ZYDIS_ELEMENT_TYPE_UINT , 256 },
{ ZYDIS_ELEMENT_TYPE_FLOAT16 , 16 },
{ ZYDIS_ELEMENT_TYPE_FLOAT32 , 32 },
{ ZYDIS_ELEMENT_TYPE_FLOAT64 , 64 },
{ ZYDIS_ELEMENT_TYPE_FLOAT80 , 80 },
{ ZYDIS_ELEMENT_TYPE_LONGBCD , 80 }
};
ZYDIS_ASSERT(element < ZYDIS_ARRAY_SIZE(lookup));
*type = lookup[element].type;
*size = lookup[element].size;
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */

View File

@ -24,19 +24,18 @@
***************************************************************************************************/
#ifndef ZYDIS_INSTRUCTIONTABLE_H
#define ZYDIS_INSTRUCTIONTABLE_H
#ifndef ZYDIS_SHAREDDATA_H
#define ZYDIS_SHAREDDATA_H
#include <Zydis/Defines.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ZYDIS_BITFIELD(x) : x
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
@ -49,117 +48,6 @@ extern "C" {
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Instruction tree */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisInstructionTreeNodeType datatype.
*/
typedef uint8_t ZydisInstructionTreeNodeType;
/**
* @brief Defines the @c ZydisInstructionTreeNodeValue datatype.
*/
typedef uint16_t ZydisInstructionTreeNodeValue;
/**
* @brief Defines the @c ZydisInstructionTreeNode struct.
*/
typedef struct ZydisInstructionTreeNode_
{
ZydisInstructionTreeNodeType type;
ZydisInstructionTreeNodeValue value;
} ZydisInstructionTreeNode;
/**
* @brief Values that represent zydis instruction tree node types.
*/
enum ZydisInstructionTreeNodeTypes
{
ZYDIS_NODETYPE_INVALID = 0x00,
/**
* @brief Reference to an instruction-definition.
*/
ZYDIS_NODETYPE_DEFINITION_MASK = 0x80,
/**
* @brief Reference to an XOP-map filter.
*/
ZYDIS_NODETYPE_FILTER_XOP = 0x01,
/**
* @brief Reference to an VEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_VEX = 0x02,
/**
* @brief Reference to an EVEX/MVEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_EMVEX = 0x03,
/**
* @brief Reference to an opcode filter.
*/
ZYDIS_NODETYPE_FILTER_OPCODE = 0x04,
/**
* @brief Reference to an instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE = 0x05,
/**
* @brief Reference to an compacted instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x06,
/**
* @brief Reference to a ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x07,
/**
* @brief Reference to a compacted ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08,
/**
* @brief Reference to a ModRM.reg filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09,
/**
* @brief Reference to a ModRM.rm filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0A,
/**
* @brief Reference to a mandatory-prefix filter.
*/
ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0B,
/**
* @brief Reference to an operand-size filter.
*/
ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0C,
/**
* @brief Reference to an address-size filter.
*/
ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0D,
/**
* @brief Reference to a vector-length filter.
*/
ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x0E,
/**
* @brief Reference to an REX/VEX/EVEX.W filter.
*/
ZYDIS_NODETYPE_FILTER_REX_W = 0x0F,
/**
* @brief Reference to an REX/VEX/EVEX.B filter.
*/
ZYDIS_NODETYPE_FILTER_REX_B = 0x10,
/**
* @brief Reference to an EVEX.b filter.
*/
ZYDIS_NODETYPE_FILTER_EVEX_B = 0x11,
/**
* @brief Reference to an EVEX.z filter.
*/
ZYDIS_NODETYPE_FILTER_EVEX_Z = 0x12,
/**
* @brief Reference to an MVEX.E filter.
*/
ZYDIS_NODETYPE_FILTER_MVEX_E = 0x13,
};
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
@ -733,146 +621,40 @@ typedef struct ZydisInstructionDefinitionMVEX_
# pragma warning(pop)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Physical instruction info */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisPhysicalInstructionInfoFlags datatype.
*/
typedef uint8_t ZydisPhysicalInstructionInfoFlags;
/**
* @brief The instruction has an optional modrm byte.
*/
#define ZYDIS_PHYSINSTR_FLAG_HAS_MODRM 0x01
/**
* @brief The instruction has an optional displacement value.
*/
#define ZYDIS_PHYSINSTR_FLAG_HAS_DISP 0x02
/**
* @brief The instruction has an optional immediate value.
*/
#define ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 0x04
/**
* @brief The instruction has a second optional immediate value.
*/
#define ZYDIS_PHYSINSTR_FLAG_HAS_IMM1 0x08
/**
* @brief The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3`
* ("reg, reg" - form).
*
* Instructions with this flag can't have a SIB byte or a displacement value.
*/
#define ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM 0x10
/**
* @brief Defines the @c ZydisPhysicalInstructionInfo struct.
*/
typedef struct ZydisPhysicalInstructionInfo_
{
/**
* @brief Contains flags with information about the physical instruction-encoding.
*/
ZydisPhysicalInstructionInfoFlags flags;
/**
* @brief Displacement info.
*/
struct
{
/**
* @brief The size of the displacement value.
*/
uint8_t size[3];
} disp;
/**
* @brief Immediate info.
*/
struct
{
/**
* @brief The size of the immediate value.
*/
uint8_t size[3];
/**
* @brief Signals, if the value is signed.
*/
ZydisBool isSigned;
/**
* @brief Signals, if the value is a relative offset.
*/
ZydisBool isRelative;
} imm[2];
} ZydisPhysicalInstructionInfo;
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction tree */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Returns the root node of the instruction tree.
*
* @return The root node of the instruction tree.
*/
ZYDIS_NO_EXPORT const ZydisInstructionTreeNode* ZydisInstructionTreeGetRootNode();
/**
* @brief Returns the child node of @c parent specified by @c index.
*
* @param parent The parent node.
* @param index The index of the child node to retrieve.
*
* @return The specified child node.
*/
ZYDIS_NO_EXPORT const ZydisInstructionTreeNode* ZydisInstructionTreeGetChildNode(
const ZydisInstructionTreeNode* parent, uint16_t index);
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Returns the instruction- and operand-definition that is linked to the given @c node.
* @brief Returns the instruction-definition with the given `encoding` and `id`.
*
* @param node The instruction definition node.
* @param definition A pointer to a variable that receives a pointer to the
* @param encoding The instruction-encoding.
* @param id The definition-id.
* @param definition A pointer to the variable that receives a pointer to the instruction-
* definition.
*/
ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(const ZydisInstructionTreeNode* node,
const ZydisInstructionDefinition** definition);
/**
* @brief Returns information about optional instruction parts (like modrm, displacement or
* immediates) for the instruction that is linked to the given @c node.
*
* @param node The instruction definition node.
* @param info A pointer to the @c ZydisInstructionParts struct.
*/
ZYDIS_NO_EXPORT void ZydisGetPhysicalInstructionInfo(const ZydisInstructionTreeNode* node,
const ZydisPhysicalInstructionInfo** info);
ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(ZydisInstructionEncoding encoding,
uint16_t id, const ZydisInstructionDefinition** definition);
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Returns the instruction- and operand-definition that is linked to the given @c node.
* @brief Returns the the operand-definitions for the given instruction-`definition`.
*
* @param definition A pointer to the instruction-definition.
* @param operands A pointer to a variable that receives a pointer to the first
* operand-definition of the instruction.
* @param definition A pointer to the instruction-definition.
* @param operand A pointer to the variable that receives a pointer to the first operand-
* definition of the instruction.
*
* @return The number of operands for the given instruction-definition.
*/
ZYDIS_NO_EXPORT uint8_t ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition,
const ZydisOperandDefinition** operands);
const ZydisOperandDefinition** operand);
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
@ -896,4 +678,4 @@ ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, Zydis
}
#endif
#endif /* ZYDIS_INSTRUCTIONTABLE_H */
#endif /* ZYDIS_SHAREDDATA_H */