externals: Add zydis

Merge commit '6ee9beab32' as 'externals/zydis'
This commit is contained in:
MerryMage 2021-05-25 21:23:39 +01:00
commit 343b21ff7b
452 changed files with 78725 additions and 0 deletions

237
externals/zydis/include/Zydis/Decoder.h vendored Normal file
View file

@ -0,0 +1,237 @@
/***************************************************************************************************
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
* Functions for decoding instructions.
*/
#ifndef ZYDIS_DECODER_H
#define ZYDIS_DECODER_H
#include <Zycore/Types.h>
#include <Zycore/Defines.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder mode */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisDecoderMode` enum.
*/
typedef enum ZydisDecoderMode_
{
/**
* 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_MINIMAL,
/**
* 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_AMD_BRANCHES,
/**
* 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_KNC,
/**
* 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_MPX,
/**
* 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_CET,
/**
* 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_LZCNT,
/**
* 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_TZCNT,
/**
* Enables the `WBNOINVD` mode.
*
* The `WBINVD` instruction is interpreted as `WBNOINVD` on ICL chips, if a `F3` prefix is
* used.
*
* This mode is disabled by default.
*/
ZYDIS_DECODER_MODE_WBNOINVD,
/**
* Enables the `CLDEMOTE` mode.
*
* The `CLDEMOTE` isa-extension reuses (overrides) some of the widenop instruction opcodes.
*
* This mode is enabled by default.
*/
ZYDIS_DECODER_MODE_CLDEMOTE,
/**
* Maximum value of this enum.
*/
ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_CLDEMOTE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_DECODER_MODE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_DECODER_MODE_MAX_VALUE)
} ZydisDecoderMode;
/* ---------------------------------------------------------------------------------------------- */
/* Decoder struct */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisDecoder` struct.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZydisDecoder_
{
/**
* The machine mode.
*/
ZydisMachineMode machine_mode;
/**
* The address width.
*/
ZydisAddressWidth address_width;
/**
* The decoder mode array.
*/
ZyanBool decoder_mode[ZYDIS_DECODER_MODE_MAX_VALUE + 1];
} ZydisDecoder;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup decoder Decoder
* Functions allowing decoding of instruction bytes to a machine interpretable struct.
* @{
*/
/**
* Initializes the given `ZydisDecoder` instance.
*
* @param decoder A pointer to the `ZydisDecoder` instance.
* @param machine_mode The machine mode.
* @param address_width The address width.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode,
ZydisAddressWidth address_width);
/**
* Enables or disables the specified decoder-mode.
*
* @param decoder A pointer to the `ZydisDecoder` instance.
* @param mode The decoder mode.
* @param enabled `ZYAN_TRUE` to enable, or `ZYAN_FALSE` to disable the specified decoder-mode.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode,
ZyanBool enabled);
/**
* Decodes the instruction in the given input `buffer`.
*
* @param decoder A pointer to the `ZydisDecoder` instance.
* @param buffer A pointer to the input buffer.
* @param length The length of the input buffer. Note that this can be bigger than the
* actual size of the instruction -- you don't have to know the size up
* front. This length is merely used to prevent Zydis from doing
* out-of-bounds reads on your buffer.
* @param instruction A pointer to the `ZydisDecodedInstruction` struct, that receives the
* details about the decoded instruction.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder,
const void* buffer, ZyanUSize length, ZydisDecodedInstruction* instruction);
/** @} */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_DECODER_H */

File diff suppressed because it is too large Load diff

1179
externals/zydis/include/Zydis/Formatter.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,306 @@
/***************************************************************************************************
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
* Implements the `ZydisFormatterToken` type and provides functions to use it.
*/
#ifndef ZYDIS_FORMATTER_TOKEN_H
#define ZYDIS_FORMATTER_TOKEN_H
#include <ZydisExportConfig.h>
#include <Zycore/String.h>
#include <Zycore/Types.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Constants */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Token types */
/* ---------------------------------------------------------------------------------------------- */
/**
* @biref Defines the `ZydisTokenType` data-type.
*/
typedef ZyanU8 ZydisTokenType;
#define ZYDIS_TOKEN_INVALID 0x00
/**
* A whitespace character.
*/
#define ZYDIS_TOKEN_WHITESPACE 0x01
/**
* A delimiter character (like `','`, `':'`, `'+'`, `'-'`, `'*'`).
*/
#define ZYDIS_TOKEN_DELIMITER 0x02
/**
* An opening parenthesis character (like `'('`, `'['`, `'{'`).
*/
#define ZYDIS_TOKEN_PARENTHESIS_OPEN 0x03
/**
* A closing parenthesis character (like `')'`, `']'`, `'}'`).
*/
#define ZYDIS_TOKEN_PARENTHESIS_CLOSE 0x04
/**
* A prefix literal (like `"LOCK"`, `"REP"`).
*/
#define ZYDIS_TOKEN_PREFIX 0x05
/**
* A mnemonic literal (like `"MOV"`, `"VCMPPSD"`, `"LCALL"`).
*/
#define ZYDIS_TOKEN_MNEMONIC 0x06
/**
* A register literal (like `"RAX"`, `"DS"`, `"%ECX"`).
*/
#define ZYDIS_TOKEN_REGISTER 0x07
/**
* An absolute address literal (like `0x00400000`).
*/
#define ZYDIS_TOKEN_ADDRESS_ABS 0x08
/**
* A relative address literal (like `-0x100`).
*/
#define ZYDIS_TOKEN_ADDRESS_REL 0x09
/**
* A displacement literal (like `0xFFFFFFFF`, `-0x100`, `+0x1234`).
*/
#define ZYDIS_TOKEN_DISPLACEMENT 0x0A
/**
* An immediate literal (like `0xC0`, `-0x1234`, `$0x0000`).
*/
#define ZYDIS_TOKEN_IMMEDIATE 0x0B
/**
* A typecast literal (like `DWORD PTR`).
*/
#define ZYDIS_TOKEN_TYPECAST 0x0C
/**
* A decorator literal (like `"Z"`, `"1TO4"`).
*/
#define ZYDIS_TOKEN_DECORATOR 0x0D
/**
* A symbol literal.
*/
#define ZYDIS_TOKEN_SYMBOL 0x0E
/**
* The base for user-defined token types.
*/
#define ZYDIS_TOKEN_USER 0x80
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Token */
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(push, 1)
/**
* Defines the `ZydisFormatterToken` struct.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZydisFormatterToken_
{
/**
* The token type.
*/
ZydisTokenType type;
/**
* An offset to the next token, or `0`.
*/
ZyanU8 next;
} ZydisFormatterToken;
#pragma pack(pop)
/**
* Defines the `ZydisFormatterTokenConst` data-type.
*/
typedef const ZydisFormatterToken ZydisFormatterTokenConst;
/* ---------------------------------------------------------------------------------------------- */
/* Buffer */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisFormatterBuffer` struct.
*
* All fields in this struct should be considered as "private". Any changes may
* lead to unexpected behavior.
*/
typedef struct ZydisFormatterBuffer_
{
/**
* `ZYAN_TRUE`, if the buffer contains a token stream or `ZYAN_FALSE, if it
* contains a simple string.
*/
ZyanBool is_token_list;
/**
* The remaining capacity of the buffer.
*/
ZyanUSize capacity;
/**
* The `ZyanString` instance that refers to the literal value of the most
* recently added token.
*/
ZyanString string;
} ZydisFormatterBuffer;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Token */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the `type` and the string `value` of the given `token`.
*
* @param token A pointer to the `ZydisFormatterToken` struct.
* @param type Receives the token type.
* @param value Receives a pointer to the string value of the token.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterTokenGetValue(const ZydisFormatterToken* token,
ZydisTokenType* type, ZyanConstCharPointer* value);
/**
* Obtains the next `token` linked to the passed one.
*
* @param token Receives a pointer to the next `ZydisFormatterToken` struct
* linked to the passed one.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterTokenNext(ZydisFormatterTokenConst** token);
/* ---------------------------------------------------------------------------------------------- */
/* Buffer */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the current (most recently added) token.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param token Receives a pointer to the current token.
*
* @return A zyan status code.
*
* This function returns `ZYAN_STATUS_INVALID_OPERATION`, if the buffer does not contain at least
* one token.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferGetToken(const ZydisFormatterBuffer* buffer,
ZydisFormatterTokenConst** token);
/**
* Returns the `ZyanString` instance associated with the given buffer.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param string Receives a pointer to the `ZyanString` instance associated with the given
* buffer.
*
* @return A zyan status code.
*
* This function returns `ZYAN_STATUS_INVALID_OPERATION`, if the buffer does not contain at least
* one token.
*
* The returned string always refers to the literal value of the current (most recently added)
* token and will remain valid until the buffer is destroyed.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferGetString(ZydisFormatterBuffer* buffer,
ZyanString** string);
/**
* Appends a new token to the `buffer`.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param type The type of the new token.
*
* @return A zyan status code.
*
* Note that the `ZyanString` instance returned by `ZydisFormatterBufferGetString` will
* automatically be updated by calling this function.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferAppend(ZydisFormatterBuffer* buffer,
ZydisTokenType type);
/**
* Returns a snapshot of the buffer-state.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param state Receives a snapshot of the buffer-state.
*
* @return A zyan status code.
*
* Note that the buffer-state is saved inside the buffer itself and thus becomes invalid as soon
* as the buffer gets overwritten or destroyed.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferRemember(const ZydisFormatterBuffer* buffer,
ZyanUPointer* state);
/**
* Restores a previously saved buffer-state.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param state The buffer-state to restore.
*
* @return A zyan status code.
*
* All tokens added after obtaining the given `state` snapshot will be removed. This function
* does NOT restore any string content.
*
* Note that the `ZyanString` instance returned by `ZydisFormatterBufferGetString` will
* automatically be updated by calling this function.
*/
ZYDIS_EXPORT ZyanStatus ZydisFormatterBufferRestore(ZydisFormatterBuffer* buffer,
ZyanUPointer state);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_FORMATTER_TOKEN_H */

View file

@ -0,0 +1,98 @@
/**
* Defines the `ZydisISAExt` enum.
*/
typedef enum ZydisISAExt_
{
ZYDIS_ISA_EXT_INVALID,
ZYDIS_ISA_EXT_ADOX_ADCX,
ZYDIS_ISA_EXT_AES,
ZYDIS_ISA_EXT_AMD3DNOW,
ZYDIS_ISA_EXT_AMD3DNOW_PREFETCH,
ZYDIS_ISA_EXT_AMD_INVLPGB,
ZYDIS_ISA_EXT_AMX_BF16,
ZYDIS_ISA_EXT_AMX_INT8,
ZYDIS_ISA_EXT_AMX_TILE,
ZYDIS_ISA_EXT_AVX,
ZYDIS_ISA_EXT_AVX2,
ZYDIS_ISA_EXT_AVX2GATHER,
ZYDIS_ISA_EXT_AVX512EVEX,
ZYDIS_ISA_EXT_AVX512VEX,
ZYDIS_ISA_EXT_AVXAES,
ZYDIS_ISA_EXT_BASE,
ZYDIS_ISA_EXT_BMI1,
ZYDIS_ISA_EXT_BMI2,
ZYDIS_ISA_EXT_CET,
ZYDIS_ISA_EXT_CLDEMOTE,
ZYDIS_ISA_EXT_CLFLUSHOPT,
ZYDIS_ISA_EXT_CLFSH,
ZYDIS_ISA_EXT_CLWB,
ZYDIS_ISA_EXT_CLZERO,
ZYDIS_ISA_EXT_ENQCMD,
ZYDIS_ISA_EXT_F16C,
ZYDIS_ISA_EXT_FMA,
ZYDIS_ISA_EXT_FMA4,
ZYDIS_ISA_EXT_GFNI,
ZYDIS_ISA_EXT_INVPCID,
ZYDIS_ISA_EXT_KNC,
ZYDIS_ISA_EXT_KNCE,
ZYDIS_ISA_EXT_KNCV,
ZYDIS_ISA_EXT_LONGMODE,
ZYDIS_ISA_EXT_LZCNT,
ZYDIS_ISA_EXT_MCOMMIT,
ZYDIS_ISA_EXT_MMX,
ZYDIS_ISA_EXT_MONITOR,
ZYDIS_ISA_EXT_MONITORX,
ZYDIS_ISA_EXT_MOVBE,
ZYDIS_ISA_EXT_MOVDIR,
ZYDIS_ISA_EXT_MPX,
ZYDIS_ISA_EXT_PADLOCK,
ZYDIS_ISA_EXT_PAUSE,
ZYDIS_ISA_EXT_PCLMULQDQ,
ZYDIS_ISA_EXT_PCONFIG,
ZYDIS_ISA_EXT_PKU,
ZYDIS_ISA_EXT_PREFETCHWT1,
ZYDIS_ISA_EXT_PT,
ZYDIS_ISA_EXT_RDPID,
ZYDIS_ISA_EXT_RDPRU,
ZYDIS_ISA_EXT_RDRAND,
ZYDIS_ISA_EXT_RDSEED,
ZYDIS_ISA_EXT_RDTSCP,
ZYDIS_ISA_EXT_RDWRFSGS,
ZYDIS_ISA_EXT_RTM,
ZYDIS_ISA_EXT_SERIALIZE,
ZYDIS_ISA_EXT_SGX,
ZYDIS_ISA_EXT_SGX_ENCLV,
ZYDIS_ISA_EXT_SHA,
ZYDIS_ISA_EXT_SMAP,
ZYDIS_ISA_EXT_SMX,
ZYDIS_ISA_EXT_SNP,
ZYDIS_ISA_EXT_SSE,
ZYDIS_ISA_EXT_SSE2,
ZYDIS_ISA_EXT_SSE3,
ZYDIS_ISA_EXT_SSE4,
ZYDIS_ISA_EXT_SSE4A,
ZYDIS_ISA_EXT_SSSE3,
ZYDIS_ISA_EXT_SVM,
ZYDIS_ISA_EXT_TBM,
ZYDIS_ISA_EXT_TSX_LDTRK,
ZYDIS_ISA_EXT_VAES,
ZYDIS_ISA_EXT_VMFUNC,
ZYDIS_ISA_EXT_VPCLMULQDQ,
ZYDIS_ISA_EXT_VTX,
ZYDIS_ISA_EXT_WAITPKG,
ZYDIS_ISA_EXT_X87,
ZYDIS_ISA_EXT_XOP,
ZYDIS_ISA_EXT_XSAVE,
ZYDIS_ISA_EXT_XSAVEC,
ZYDIS_ISA_EXT_XSAVEOPT,
ZYDIS_ISA_EXT_XSAVES,
/**
* Maximum value of this enum.
*/
ZYDIS_ISA_EXT_MAX_VALUE = ZYDIS_ISA_EXT_XSAVES,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_ISA_EXT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ISA_EXT_MAX_VALUE)
} ZydisISAExt;

View file

@ -0,0 +1,184 @@
/**
* Defines the `ZydisISASet` enum.
*/
typedef enum ZydisISASet_
{
ZYDIS_ISA_SET_INVALID,
ZYDIS_ISA_SET_ADOX_ADCX,
ZYDIS_ISA_SET_AES,
ZYDIS_ISA_SET_AMD,
ZYDIS_ISA_SET_AMD3DNOW,
ZYDIS_ISA_SET_AMX_BF16,
ZYDIS_ISA_SET_AMX_INT8,
ZYDIS_ISA_SET_AMX_TILE,
ZYDIS_ISA_SET_AVX,
ZYDIS_ISA_SET_AVX2,
ZYDIS_ISA_SET_AVX2GATHER,
ZYDIS_ISA_SET_AVX512BW_128,
ZYDIS_ISA_SET_AVX512BW_128N,
ZYDIS_ISA_SET_AVX512BW_256,
ZYDIS_ISA_SET_AVX512BW_512,
ZYDIS_ISA_SET_AVX512BW_KOP,
ZYDIS_ISA_SET_AVX512CD_128,
ZYDIS_ISA_SET_AVX512CD_256,
ZYDIS_ISA_SET_AVX512CD_512,
ZYDIS_ISA_SET_AVX512DQ_128,
ZYDIS_ISA_SET_AVX512DQ_128N,
ZYDIS_ISA_SET_AVX512DQ_256,
ZYDIS_ISA_SET_AVX512DQ_512,
ZYDIS_ISA_SET_AVX512DQ_KOP,
ZYDIS_ISA_SET_AVX512DQ_SCALAR,
ZYDIS_ISA_SET_AVX512ER_512,
ZYDIS_ISA_SET_AVX512ER_SCALAR,
ZYDIS_ISA_SET_AVX512F_128,
ZYDIS_ISA_SET_AVX512F_128N,
ZYDIS_ISA_SET_AVX512F_256,
ZYDIS_ISA_SET_AVX512F_512,
ZYDIS_ISA_SET_AVX512F_KOP,
ZYDIS_ISA_SET_AVX512F_SCALAR,
ZYDIS_ISA_SET_AVX512PF_512,
ZYDIS_ISA_SET_AVX512_4FMAPS_512,
ZYDIS_ISA_SET_AVX512_4FMAPS_SCALAR,
ZYDIS_ISA_SET_AVX512_4VNNIW_512,
ZYDIS_ISA_SET_AVX512_BF16_128,
ZYDIS_ISA_SET_AVX512_BF16_256,
ZYDIS_ISA_SET_AVX512_BF16_512,
ZYDIS_ISA_SET_AVX512_BITALG_128,
ZYDIS_ISA_SET_AVX512_BITALG_256,
ZYDIS_ISA_SET_AVX512_BITALG_512,
ZYDIS_ISA_SET_AVX512_GFNI_128,
ZYDIS_ISA_SET_AVX512_GFNI_256,
ZYDIS_ISA_SET_AVX512_GFNI_512,
ZYDIS_ISA_SET_AVX512_IFMA_128,
ZYDIS_ISA_SET_AVX512_IFMA_256,
ZYDIS_ISA_SET_AVX512_IFMA_512,
ZYDIS_ISA_SET_AVX512_VAES_128,
ZYDIS_ISA_SET_AVX512_VAES_256,
ZYDIS_ISA_SET_AVX512_VAES_512,
ZYDIS_ISA_SET_AVX512_VBMI2_128,
ZYDIS_ISA_SET_AVX512_VBMI2_256,
ZYDIS_ISA_SET_AVX512_VBMI2_512,
ZYDIS_ISA_SET_AVX512_VBMI_128,
ZYDIS_ISA_SET_AVX512_VBMI_256,
ZYDIS_ISA_SET_AVX512_VBMI_512,
ZYDIS_ISA_SET_AVX512_VNNI_128,
ZYDIS_ISA_SET_AVX512_VNNI_256,
ZYDIS_ISA_SET_AVX512_VNNI_512,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_128,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_256,
ZYDIS_ISA_SET_AVX512_VP2INTERSECT_512,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_128,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_256,
ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_512,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_128,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_256,
ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_512,
ZYDIS_ISA_SET_AVXAES,
ZYDIS_ISA_SET_AVX_GFNI,
ZYDIS_ISA_SET_BMI1,
ZYDIS_ISA_SET_BMI2,
ZYDIS_ISA_SET_CET,
ZYDIS_ISA_SET_CLDEMOTE,
ZYDIS_ISA_SET_CLFLUSHOPT,
ZYDIS_ISA_SET_CLFSH,
ZYDIS_ISA_SET_CLWB,
ZYDIS_ISA_SET_CLZERO,
ZYDIS_ISA_SET_CMOV,
ZYDIS_ISA_SET_CMPXCHG16B,
ZYDIS_ISA_SET_ENQCMD,
ZYDIS_ISA_SET_F16C,
ZYDIS_ISA_SET_FAT_NOP,
ZYDIS_ISA_SET_FCMOV,
ZYDIS_ISA_SET_FMA,
ZYDIS_ISA_SET_FMA4,
ZYDIS_ISA_SET_FXSAVE,
ZYDIS_ISA_SET_FXSAVE64,
ZYDIS_ISA_SET_GFNI,
ZYDIS_ISA_SET_I186,
ZYDIS_ISA_SET_I286PROTECTED,
ZYDIS_ISA_SET_I286REAL,
ZYDIS_ISA_SET_I386,
ZYDIS_ISA_SET_I486,
ZYDIS_ISA_SET_I486REAL,
ZYDIS_ISA_SET_I86,
ZYDIS_ISA_SET_INVPCID,
ZYDIS_ISA_SET_KNCE,
ZYDIS_ISA_SET_KNCJKBR,
ZYDIS_ISA_SET_KNCSTREAM,
ZYDIS_ISA_SET_KNCV,
ZYDIS_ISA_SET_KNC_MISC,
ZYDIS_ISA_SET_KNC_PF_HINT,
ZYDIS_ISA_SET_LAHF,
ZYDIS_ISA_SET_LONGMODE,
ZYDIS_ISA_SET_LZCNT,
ZYDIS_ISA_SET_MCOMMIT,
ZYDIS_ISA_SET_MONITOR,
ZYDIS_ISA_SET_MONITORX,
ZYDIS_ISA_SET_MOVBE,
ZYDIS_ISA_SET_MOVDIR,
ZYDIS_ISA_SET_MPX,
ZYDIS_ISA_SET_PADLOCK_ACE,
ZYDIS_ISA_SET_PADLOCK_PHE,
ZYDIS_ISA_SET_PADLOCK_PMM,
ZYDIS_ISA_SET_PADLOCK_RNG,
ZYDIS_ISA_SET_PAUSE,
ZYDIS_ISA_SET_PCLMULQDQ,
ZYDIS_ISA_SET_PCONFIG,
ZYDIS_ISA_SET_PENTIUMMMX,
ZYDIS_ISA_SET_PENTIUMREAL,
ZYDIS_ISA_SET_PKU,
ZYDIS_ISA_SET_POPCNT,
ZYDIS_ISA_SET_PPRO,
ZYDIS_ISA_SET_PREFETCHWT1,
ZYDIS_ISA_SET_PREFETCH_NOP,
ZYDIS_ISA_SET_PT,
ZYDIS_ISA_SET_RDPID,
ZYDIS_ISA_SET_RDPMC,
ZYDIS_ISA_SET_RDPRU,
ZYDIS_ISA_SET_RDRAND,
ZYDIS_ISA_SET_RDSEED,
ZYDIS_ISA_SET_RDTSCP,
ZYDIS_ISA_SET_RDWRFSGS,
ZYDIS_ISA_SET_RTM,
ZYDIS_ISA_SET_SERIALIZE,
ZYDIS_ISA_SET_SGX,
ZYDIS_ISA_SET_SGX_ENCLV,
ZYDIS_ISA_SET_SHA,
ZYDIS_ISA_SET_SMAP,
ZYDIS_ISA_SET_SMX,
ZYDIS_ISA_SET_SSE,
ZYDIS_ISA_SET_SSE2,
ZYDIS_ISA_SET_SSE2MMX,
ZYDIS_ISA_SET_SSE3,
ZYDIS_ISA_SET_SSE3X87,
ZYDIS_ISA_SET_SSE4,
ZYDIS_ISA_SET_SSE42,
ZYDIS_ISA_SET_SSE4A,
ZYDIS_ISA_SET_SSEMXCSR,
ZYDIS_ISA_SET_SSE_PREFETCH,
ZYDIS_ISA_SET_SSSE3,
ZYDIS_ISA_SET_SSSE3MMX,
ZYDIS_ISA_SET_SVM,
ZYDIS_ISA_SET_TBM,
ZYDIS_ISA_SET_TSX_LDTRK,
ZYDIS_ISA_SET_VAES,
ZYDIS_ISA_SET_VMFUNC,
ZYDIS_ISA_SET_VPCLMULQDQ,
ZYDIS_ISA_SET_VTX,
ZYDIS_ISA_SET_WAITPKG,
ZYDIS_ISA_SET_X87,
ZYDIS_ISA_SET_XOP,
ZYDIS_ISA_SET_XSAVE,
ZYDIS_ISA_SET_XSAVEC,
ZYDIS_ISA_SET_XSAVEOPT,
ZYDIS_ISA_SET_XSAVES,
/**
* Maximum value of this enum.
*/
ZYDIS_ISA_SET_MAX_VALUE = ZYDIS_ISA_SET_XSAVES,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_ISA_SET_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ISA_SET_MAX_VALUE)
} ZydisISASet;

View file

@ -0,0 +1,117 @@
/**
* Defines the `ZydisInstructionCategory` enum.
*/
typedef enum ZydisInstructionCategory_
{
ZYDIS_CATEGORY_INVALID,
ZYDIS_CATEGORY_ADOX_ADCX,
ZYDIS_CATEGORY_AES,
ZYDIS_CATEGORY_AMD3DNOW,
ZYDIS_CATEGORY_AMX_TILE,
ZYDIS_CATEGORY_AVX,
ZYDIS_CATEGORY_AVX2,
ZYDIS_CATEGORY_AVX2GATHER,
ZYDIS_CATEGORY_AVX512,
ZYDIS_CATEGORY_AVX512_4FMAPS,
ZYDIS_CATEGORY_AVX512_4VNNIW,
ZYDIS_CATEGORY_AVX512_BITALG,
ZYDIS_CATEGORY_AVX512_VBMI,
ZYDIS_CATEGORY_AVX512_VP2INTERSECT,
ZYDIS_CATEGORY_BINARY,
ZYDIS_CATEGORY_BITBYTE,
ZYDIS_CATEGORY_BLEND,
ZYDIS_CATEGORY_BMI1,
ZYDIS_CATEGORY_BMI2,
ZYDIS_CATEGORY_BROADCAST,
ZYDIS_CATEGORY_CALL,
ZYDIS_CATEGORY_CET,
ZYDIS_CATEGORY_CLDEMOTE,
ZYDIS_CATEGORY_CLFLUSHOPT,
ZYDIS_CATEGORY_CLWB,
ZYDIS_CATEGORY_CLZERO,
ZYDIS_CATEGORY_CMOV,
ZYDIS_CATEGORY_COMPRESS,
ZYDIS_CATEGORY_COND_BR,
ZYDIS_CATEGORY_CONFLICT,
ZYDIS_CATEGORY_CONVERT,
ZYDIS_CATEGORY_DATAXFER,
ZYDIS_CATEGORY_DECIMAL,
ZYDIS_CATEGORY_ENQCMD,
ZYDIS_CATEGORY_EXPAND,
ZYDIS_CATEGORY_FCMOV,
ZYDIS_CATEGORY_FLAGOP,
ZYDIS_CATEGORY_FMA4,
ZYDIS_CATEGORY_GATHER,
ZYDIS_CATEGORY_GFNI,
ZYDIS_CATEGORY_IFMA,
ZYDIS_CATEGORY_INTERRUPT,
ZYDIS_CATEGORY_IO,
ZYDIS_CATEGORY_IOSTRINGOP,
ZYDIS_CATEGORY_KMASK,
ZYDIS_CATEGORY_KNC,
ZYDIS_CATEGORY_KNCMASK,
ZYDIS_CATEGORY_KNCSCALAR,
ZYDIS_CATEGORY_LOGICAL,
ZYDIS_CATEGORY_LOGICAL_FP,
ZYDIS_CATEGORY_LZCNT,
ZYDIS_CATEGORY_MISC,
ZYDIS_CATEGORY_MMX,
ZYDIS_CATEGORY_MOVDIR,
ZYDIS_CATEGORY_MPX,
ZYDIS_CATEGORY_NOP,
ZYDIS_CATEGORY_PADLOCK,
ZYDIS_CATEGORY_PCLMULQDQ,
ZYDIS_CATEGORY_PCONFIG,
ZYDIS_CATEGORY_PKU,
ZYDIS_CATEGORY_POP,
ZYDIS_CATEGORY_PREFETCH,
ZYDIS_CATEGORY_PREFETCHWT1,
ZYDIS_CATEGORY_PT,
ZYDIS_CATEGORY_PUSH,
ZYDIS_CATEGORY_RDPID,
ZYDIS_CATEGORY_RDPRU,
ZYDIS_CATEGORY_RDRAND,
ZYDIS_CATEGORY_RDSEED,
ZYDIS_CATEGORY_RDWRFSGS,
ZYDIS_CATEGORY_RET,
ZYDIS_CATEGORY_ROTATE,
ZYDIS_CATEGORY_SCATTER,
ZYDIS_CATEGORY_SEGOP,
ZYDIS_CATEGORY_SEMAPHORE,
ZYDIS_CATEGORY_SERIALIZE,
ZYDIS_CATEGORY_SETCC,
ZYDIS_CATEGORY_SGX,
ZYDIS_CATEGORY_SHA,
ZYDIS_CATEGORY_SHIFT,
ZYDIS_CATEGORY_SMAP,
ZYDIS_CATEGORY_SSE,
ZYDIS_CATEGORY_STRINGOP,
ZYDIS_CATEGORY_STTNI,
ZYDIS_CATEGORY_SYSCALL,
ZYDIS_CATEGORY_SYSRET,
ZYDIS_CATEGORY_SYSTEM,
ZYDIS_CATEGORY_TBM,
ZYDIS_CATEGORY_TSX_LDTRK,
ZYDIS_CATEGORY_UFMA,
ZYDIS_CATEGORY_UNCOND_BR,
ZYDIS_CATEGORY_VAES,
ZYDIS_CATEGORY_VBMI2,
ZYDIS_CATEGORY_VFMA,
ZYDIS_CATEGORY_VPCLMULQDQ,
ZYDIS_CATEGORY_VTX,
ZYDIS_CATEGORY_WAITPKG,
ZYDIS_CATEGORY_WIDENOP,
ZYDIS_CATEGORY_X87_ALU,
ZYDIS_CATEGORY_XOP,
ZYDIS_CATEGORY_XSAVE,
ZYDIS_CATEGORY_XSAVEOPT,
/**
* Maximum value of this enum.
*/
ZYDIS_CATEGORY_MAX_VALUE = ZYDIS_CATEGORY_XSAVEOPT,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_CATEGORY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CATEGORY_MAX_VALUE)
} ZydisInstructionCategory;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,301 @@
/**
* Defines the `ZydisRegister` enum.
*/
typedef enum ZydisRegister_
{
ZYDIS_REGISTER_NONE,
// General purpose registers 8-bit
ZYDIS_REGISTER_AL,
ZYDIS_REGISTER_CL,
ZYDIS_REGISTER_DL,
ZYDIS_REGISTER_BL,
ZYDIS_REGISTER_AH,
ZYDIS_REGISTER_CH,
ZYDIS_REGISTER_DH,
ZYDIS_REGISTER_BH,
ZYDIS_REGISTER_SPL,
ZYDIS_REGISTER_BPL,
ZYDIS_REGISTER_SIL,
ZYDIS_REGISTER_DIL,
ZYDIS_REGISTER_R8B,
ZYDIS_REGISTER_R9B,
ZYDIS_REGISTER_R10B,
ZYDIS_REGISTER_R11B,
ZYDIS_REGISTER_R12B,
ZYDIS_REGISTER_R13B,
ZYDIS_REGISTER_R14B,
ZYDIS_REGISTER_R15B,
// General purpose registers 16-bit
ZYDIS_REGISTER_AX,
ZYDIS_REGISTER_CX,
ZYDIS_REGISTER_DX,
ZYDIS_REGISTER_BX,
ZYDIS_REGISTER_SP,
ZYDIS_REGISTER_BP,
ZYDIS_REGISTER_SI,
ZYDIS_REGISTER_DI,
ZYDIS_REGISTER_R8W,
ZYDIS_REGISTER_R9W,
ZYDIS_REGISTER_R10W,
ZYDIS_REGISTER_R11W,
ZYDIS_REGISTER_R12W,
ZYDIS_REGISTER_R13W,
ZYDIS_REGISTER_R14W,
ZYDIS_REGISTER_R15W,
// General purpose registers 32-bit
ZYDIS_REGISTER_EAX,
ZYDIS_REGISTER_ECX,
ZYDIS_REGISTER_EDX,
ZYDIS_REGISTER_EBX,
ZYDIS_REGISTER_ESP,
ZYDIS_REGISTER_EBP,
ZYDIS_REGISTER_ESI,
ZYDIS_REGISTER_EDI,
ZYDIS_REGISTER_R8D,
ZYDIS_REGISTER_R9D,
ZYDIS_REGISTER_R10D,
ZYDIS_REGISTER_R11D,
ZYDIS_REGISTER_R12D,
ZYDIS_REGISTER_R13D,
ZYDIS_REGISTER_R14D,
ZYDIS_REGISTER_R15D,
// General purpose registers 64-bit
ZYDIS_REGISTER_RAX,
ZYDIS_REGISTER_RCX,
ZYDIS_REGISTER_RDX,
ZYDIS_REGISTER_RBX,
ZYDIS_REGISTER_RSP,
ZYDIS_REGISTER_RBP,
ZYDIS_REGISTER_RSI,
ZYDIS_REGISTER_RDI,
ZYDIS_REGISTER_R8,
ZYDIS_REGISTER_R9,
ZYDIS_REGISTER_R10,
ZYDIS_REGISTER_R11,
ZYDIS_REGISTER_R12,
ZYDIS_REGISTER_R13,
ZYDIS_REGISTER_R14,
ZYDIS_REGISTER_R15,
// Floating point legacy registers
ZYDIS_REGISTER_ST0,
ZYDIS_REGISTER_ST1,
ZYDIS_REGISTER_ST2,
ZYDIS_REGISTER_ST3,
ZYDIS_REGISTER_ST4,
ZYDIS_REGISTER_ST5,
ZYDIS_REGISTER_ST6,
ZYDIS_REGISTER_ST7,
ZYDIS_REGISTER_X87CONTROL,
ZYDIS_REGISTER_X87STATUS,
ZYDIS_REGISTER_X87TAG,
// Floating point multimedia registers
ZYDIS_REGISTER_MM0,
ZYDIS_REGISTER_MM1,
ZYDIS_REGISTER_MM2,
ZYDIS_REGISTER_MM3,
ZYDIS_REGISTER_MM4,
ZYDIS_REGISTER_MM5,
ZYDIS_REGISTER_MM6,
ZYDIS_REGISTER_MM7,
// Floating point vector registers 128-bit
ZYDIS_REGISTER_XMM0,
ZYDIS_REGISTER_XMM1,
ZYDIS_REGISTER_XMM2,
ZYDIS_REGISTER_XMM3,
ZYDIS_REGISTER_XMM4,
ZYDIS_REGISTER_XMM5,
ZYDIS_REGISTER_XMM6,
ZYDIS_REGISTER_XMM7,
ZYDIS_REGISTER_XMM8,
ZYDIS_REGISTER_XMM9,
ZYDIS_REGISTER_XMM10,
ZYDIS_REGISTER_XMM11,
ZYDIS_REGISTER_XMM12,
ZYDIS_REGISTER_XMM13,
ZYDIS_REGISTER_XMM14,
ZYDIS_REGISTER_XMM15,
ZYDIS_REGISTER_XMM16,
ZYDIS_REGISTER_XMM17,
ZYDIS_REGISTER_XMM18,
ZYDIS_REGISTER_XMM19,
ZYDIS_REGISTER_XMM20,
ZYDIS_REGISTER_XMM21,
ZYDIS_REGISTER_XMM22,
ZYDIS_REGISTER_XMM23,
ZYDIS_REGISTER_XMM24,
ZYDIS_REGISTER_XMM25,
ZYDIS_REGISTER_XMM26,
ZYDIS_REGISTER_XMM27,
ZYDIS_REGISTER_XMM28,
ZYDIS_REGISTER_XMM29,
ZYDIS_REGISTER_XMM30,
ZYDIS_REGISTER_XMM31,
// Floating point vector registers 256-bit
ZYDIS_REGISTER_YMM0,
ZYDIS_REGISTER_YMM1,
ZYDIS_REGISTER_YMM2,
ZYDIS_REGISTER_YMM3,
ZYDIS_REGISTER_YMM4,
ZYDIS_REGISTER_YMM5,
ZYDIS_REGISTER_YMM6,
ZYDIS_REGISTER_YMM7,
ZYDIS_REGISTER_YMM8,
ZYDIS_REGISTER_YMM9,
ZYDIS_REGISTER_YMM10,
ZYDIS_REGISTER_YMM11,
ZYDIS_REGISTER_YMM12,
ZYDIS_REGISTER_YMM13,
ZYDIS_REGISTER_YMM14,
ZYDIS_REGISTER_YMM15,
ZYDIS_REGISTER_YMM16,
ZYDIS_REGISTER_YMM17,
ZYDIS_REGISTER_YMM18,
ZYDIS_REGISTER_YMM19,
ZYDIS_REGISTER_YMM20,
ZYDIS_REGISTER_YMM21,
ZYDIS_REGISTER_YMM22,
ZYDIS_REGISTER_YMM23,
ZYDIS_REGISTER_YMM24,
ZYDIS_REGISTER_YMM25,
ZYDIS_REGISTER_YMM26,
ZYDIS_REGISTER_YMM27,
ZYDIS_REGISTER_YMM28,
ZYDIS_REGISTER_YMM29,
ZYDIS_REGISTER_YMM30,
ZYDIS_REGISTER_YMM31,
// Floating point vector registers 512-bit
ZYDIS_REGISTER_ZMM0,
ZYDIS_REGISTER_ZMM1,
ZYDIS_REGISTER_ZMM2,
ZYDIS_REGISTER_ZMM3,
ZYDIS_REGISTER_ZMM4,
ZYDIS_REGISTER_ZMM5,
ZYDIS_REGISTER_ZMM6,
ZYDIS_REGISTER_ZMM7,
ZYDIS_REGISTER_ZMM8,
ZYDIS_REGISTER_ZMM9,
ZYDIS_REGISTER_ZMM10,
ZYDIS_REGISTER_ZMM11,
ZYDIS_REGISTER_ZMM12,
ZYDIS_REGISTER_ZMM13,
ZYDIS_REGISTER_ZMM14,
ZYDIS_REGISTER_ZMM15,
ZYDIS_REGISTER_ZMM16,
ZYDIS_REGISTER_ZMM17,
ZYDIS_REGISTER_ZMM18,
ZYDIS_REGISTER_ZMM19,
ZYDIS_REGISTER_ZMM20,
ZYDIS_REGISTER_ZMM21,
ZYDIS_REGISTER_ZMM22,
ZYDIS_REGISTER_ZMM23,
ZYDIS_REGISTER_ZMM24,
ZYDIS_REGISTER_ZMM25,
ZYDIS_REGISTER_ZMM26,
ZYDIS_REGISTER_ZMM27,
ZYDIS_REGISTER_ZMM28,
ZYDIS_REGISTER_ZMM29,
ZYDIS_REGISTER_ZMM30,
ZYDIS_REGISTER_ZMM31,
// Matrix registers
ZYDIS_REGISTER_TMM0,
ZYDIS_REGISTER_TMM1,
ZYDIS_REGISTER_TMM2,
ZYDIS_REGISTER_TMM3,
ZYDIS_REGISTER_TMM4,
ZYDIS_REGISTER_TMM5,
ZYDIS_REGISTER_TMM6,
ZYDIS_REGISTER_TMM7,
// Flags registers
ZYDIS_REGISTER_FLAGS,
ZYDIS_REGISTER_EFLAGS,
ZYDIS_REGISTER_RFLAGS,
// Instruction-pointer registers
ZYDIS_REGISTER_IP,
ZYDIS_REGISTER_EIP,
ZYDIS_REGISTER_RIP,
// Segment registers
ZYDIS_REGISTER_ES,
ZYDIS_REGISTER_CS,
ZYDIS_REGISTER_SS,
ZYDIS_REGISTER_DS,
ZYDIS_REGISTER_FS,
ZYDIS_REGISTER_GS,
// Table registers
ZYDIS_REGISTER_GDTR,
ZYDIS_REGISTER_LDTR,
ZYDIS_REGISTER_IDTR,
ZYDIS_REGISTER_TR,
// Test registers
ZYDIS_REGISTER_TR0,
ZYDIS_REGISTER_TR1,
ZYDIS_REGISTER_TR2,
ZYDIS_REGISTER_TR3,
ZYDIS_REGISTER_TR4,
ZYDIS_REGISTER_TR5,
ZYDIS_REGISTER_TR6,
ZYDIS_REGISTER_TR7,
// Control registers
ZYDIS_REGISTER_CR0,
ZYDIS_REGISTER_CR1,
ZYDIS_REGISTER_CR2,
ZYDIS_REGISTER_CR3,
ZYDIS_REGISTER_CR4,
ZYDIS_REGISTER_CR5,
ZYDIS_REGISTER_CR6,
ZYDIS_REGISTER_CR7,
ZYDIS_REGISTER_CR8,
ZYDIS_REGISTER_CR9,
ZYDIS_REGISTER_CR10,
ZYDIS_REGISTER_CR11,
ZYDIS_REGISTER_CR12,
ZYDIS_REGISTER_CR13,
ZYDIS_REGISTER_CR14,
ZYDIS_REGISTER_CR15,
// Debug registers
ZYDIS_REGISTER_DR0,
ZYDIS_REGISTER_DR1,
ZYDIS_REGISTER_DR2,
ZYDIS_REGISTER_DR3,
ZYDIS_REGISTER_DR4,
ZYDIS_REGISTER_DR5,
ZYDIS_REGISTER_DR6,
ZYDIS_REGISTER_DR7,
ZYDIS_REGISTER_DR8,
ZYDIS_REGISTER_DR9,
ZYDIS_REGISTER_DR10,
ZYDIS_REGISTER_DR11,
ZYDIS_REGISTER_DR12,
ZYDIS_REGISTER_DR13,
ZYDIS_REGISTER_DR14,
ZYDIS_REGISTER_DR15,
// Mask registers
ZYDIS_REGISTER_K0,
ZYDIS_REGISTER_K1,
ZYDIS_REGISTER_K2,
ZYDIS_REGISTER_K3,
ZYDIS_REGISTER_K4,
ZYDIS_REGISTER_K5,
ZYDIS_REGISTER_K6,
ZYDIS_REGISTER_K7,
// Bound registers
ZYDIS_REGISTER_BND0,
ZYDIS_REGISTER_BND1,
ZYDIS_REGISTER_BND2,
ZYDIS_REGISTER_BND3,
ZYDIS_REGISTER_BNDCFG,
ZYDIS_REGISTER_BNDSTATUS,
// Uncategorized
ZYDIS_REGISTER_MXCSR,
ZYDIS_REGISTER_PKRU,
ZYDIS_REGISTER_XCR0,
/**
* Maximum value of this enum.
*/
ZYDIS_REGISTER_MAX_VALUE = ZYDIS_REGISTER_XCR0,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_REGISTER_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGISTER_MAX_VALUE)
} ZydisRegister;

View file

@ -0,0 +1,331 @@
/***************************************************************************************************
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_INTERNAL_DECODERDATA_H
#define ZYDIS_INTERNAL_DECODERDATA_H
#include <Zycore/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 bit-fields
#ifdef ZYAN_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisDecoderTreeNodeType` data-type.
*/
typedef ZyanU8 ZydisDecoderTreeNodeType;
/**
* Values that represent zydis decoder tree node types.
*/
enum ZydisDecoderTreeNodeTypes
{
ZYDIS_NODETYPE_INVALID = 0x00,
/**
* Reference to an instruction-definition.
*/
ZYDIS_NODETYPE_DEFINITION_MASK = 0x80,
/**
* Reference to an XOP-map filter.
*/
ZYDIS_NODETYPE_FILTER_XOP = 0x01,
/**
* Reference to an VEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_VEX = 0x02,
/**
* Reference to an EVEX/MVEX-map filter.
*/
ZYDIS_NODETYPE_FILTER_EMVEX = 0x03,
/**
* Reference to an opcode filter.
*/
ZYDIS_NODETYPE_FILTER_OPCODE = 0x04,
/**
* Reference to an instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE = 0x05,
/**
* Reference to an compacted instruction-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_COMPACT = 0x06,
/**
* Reference to a ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD = 0x07,
/**
* Reference to a compacted ModRM.mod filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_MOD_COMPACT = 0x08,
/**
* Reference to a ModRM.reg filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_REG = 0x09,
/**
* Reference to a ModRM.rm filter.
*/
ZYDIS_NODETYPE_FILTER_MODRM_RM = 0x0A,
/**
* Reference to a PrefixGroup1 filter.
*/
ZYDIS_NODETYPE_FILTER_PREFIX_GROUP1 = 0x0B,
/**
* Reference to a mandatory-prefix filter.
*/
ZYDIS_NODETYPE_FILTER_MANDATORY_PREFIX = 0x0C,
/**
* Reference to an operand-size filter.
*/
ZYDIS_NODETYPE_FILTER_OPERAND_SIZE = 0x0D,
/**
* Reference to an address-size filter.
*/
ZYDIS_NODETYPE_FILTER_ADDRESS_SIZE = 0x0E,
/**
* Reference to a vector-length filter.
*/
ZYDIS_NODETYPE_FILTER_VECTOR_LENGTH = 0x0F,
/**
* Reference to an REX/VEX/EVEX.W filter.
*/
ZYDIS_NODETYPE_FILTER_REX_W = 0x10,
/**
* Reference to an REX/VEX/EVEX.B filter.
*/
ZYDIS_NODETYPE_FILTER_REX_B = 0x11,
/**
* Reference to an EVEX.b filter.
*/
ZYDIS_NODETYPE_FILTER_EVEX_B = 0x12,
/**
* Reference to an MVEX.E filter.
*/
ZYDIS_NODETYPE_FILTER_MVEX_E = 0x13,
/**
* Reference to a AMD-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_AMD = 0x14,
/**
* Reference to a KNC-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_KNC = 0x15,
/**
* Reference to a MPX-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_MPX = 0x16,
/**
* Reference to a CET-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_CET = 0x17,
/**
* Reference to a LZCNT-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_LZCNT = 0x18,
/**
* Reference to a TZCNT-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_TZCNT = 0x19,
/**
* Reference to a WBNOINVD-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_WBNOINVD = 0x1A,
/**
* Reference to a CLDEMOTE-mode filter.
*/
ZYDIS_NODETYPE_FILTER_MODE_CLDEMOTE = 0x1B
};
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisDecoderTreeNodeValue` data-type.
*/
typedef ZyanU16 ZydisDecoderTreeNodeValue;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisDecoderTreeNode` struct.
*/
typedef struct ZydisDecoderTreeNode_
{
ZydisDecoderTreeNodeType type;
ZydisDecoderTreeNodeValue value;
} ZydisDecoderTreeNode;
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYAN_MSVC
# pragma warning(pop)
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Physical instruction encoding info */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInstructionEncodingFlags` data-type.
*/
typedef ZyanU8 ZydisInstructionEncodingFlags;
/**
* The instruction has an optional modrm byte.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_MODRM 0x01
/**
* The instruction has an optional displacement value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_DISP 0x02
/**
* The instruction has an optional immediate value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM0 0x04
/**
* The instruction has a second optional immediate value.
*/
#define ZYDIS_INSTR_ENC_FLAG_HAS_IMM1 0x08
/**
* 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
/**
* Defines the `ZydisInstructionEncodingInfo` struct.
*/
typedef struct ZydisInstructionEncodingInfo_
{
/**
* Contains flags with information about the physical instruction-encoding.
*/
ZydisInstructionEncodingFlags flags;
/**
* Displacement info.
*/
struct
{
/**
* The size of the displacement value.
*/
ZyanU8 size[3];
} disp;
/**
* Immediate info.
*/
struct
{
/**
* The size of the immediate value.
*/
ZyanU8 size[3];
/**
* Signals, if the value is signed.
*/
ZyanBool is_signed;
/**
* Signals, if the value is a relative offset.
*/
ZyanBool is_relative;
} imm[2];
} ZydisInstructionEncodingInfo;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder tree */
/* ---------------------------------------------------------------------------------------------- */
extern const ZydisDecoderTreeNode zydis_decoder_tree_root;
/**
* Returns the root node of the instruction tree.
*
* @return The root node of the instruction tree.
*/
ZYAN_INLINE const ZydisDecoderTreeNode* ZydisDecoderTreeGetRootNode(void)
{
return &zydis_decoder_tree_root;
}
/**
* Returns the child node of `parent` specified by `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, ZyanU16 index);
/**
* Returns information about optional instruction parts (like modrm, displacement or
* immediates) for the instruction that is linked to the given `node`.
*
* @param node The instruction definition node.
* @param info A pointer to the `ZydisInstructionParts` struct.
*/
ZYDIS_NO_EXPORT void ZydisGetInstructionEncodingInfo(const ZydisDecoderTreeNode* node,
const ZydisInstructionEncodingInfo** info);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_INTERNAL_DECODERDATA_H */

View file

@ -0,0 +1,178 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd, Joel Hoener
* 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
* Implements the `AT&T` style instruction-formatter.
*/
#ifndef ZYDIS_FORMATTER_ATT_H
#define ZYDIS_FORMATTER_ATT_H
#include <Zydis/Formatter.h>
#include <Zydis/Internal/FormatterBase.h>
#include <Zydis/Internal/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Formatter functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTFormatInstruction(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Operands */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Elemental tokens */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterATTPrintMnemonic(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterATTPrintRegister(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);
ZyanStatus ZydisFormatterATTPrintDISP(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterATTPrintIMM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Fomatter presets */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* AT&T */
/* ---------------------------------------------------------------------------------------------- */
/**
* The default formatter configuration for `AT&T` style disassembly.
*/
static const ZydisFormatter FORMATTER_ATT =
{
/* style */ ZYDIS_FORMATTER_STYLE_ATT,
/* force_memory_size */ ZYAN_FALSE,
/* force_memory_seg */ ZYAN_FALSE,
/* force_relative_branches */ ZYAN_FALSE,
/* force_relative_riprel */ ZYAN_FALSE,
/* print_branch_size */ ZYAN_FALSE,
/* detailed_prefixes */ ZYAN_FALSE,
/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* addr_padding_absolute */ ZYDIS_PADDING_AUTO,
/* addr_padding_relative */ 2,
/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* disp_padding */ 2,
/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
/* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,
/* imm_padding */ 2,
/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
/* hex_uppercase */ ZYAN_TRUE,
/* number_format */
{
// ZYDIS_NUMERIC_BASE_DEC
{
// Prefix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
},
// ZYDIS_NUMERIC_BASE_HEX
{
// Prefix
{
/* string */ &FORMATTER_ATT.number_format[
ZYDIS_NUMERIC_BASE_HEX][0].string_data,
/* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
}
},
/* func_pre_instruction */ ZYAN_NULL,
/* func_post_instruction */ ZYAN_NULL,
/* func_format_instruction */ &ZydisFormatterATTFormatInstruction,
/* func_pre_operand */ ZYAN_NULL,
/* func_post_operand */ ZYAN_NULL,
/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
/* func_format_operand_mem */ &ZydisFormatterATTFormatOperandMEM,
/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
/* func_print_mnemonic */ &ZydisFormatterATTPrintMnemonic,
/* func_print_register */ &ZydisFormatterATTPrintRegister,
/* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS,
/* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,
/* func_print_disp */ &ZydisFormatterATTPrintDISP,
/* func_print_imm */ &ZydisFormatterATTPrintIMM,
/* func_print_typecast */ ZYAN_NULL,
/* func_print_segment */ &ZydisFormatterBasePrintSegment,
/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
/* func_print_decorator */ &ZydisFormatterBasePrintDecorator
};
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYDIS_FORMATTER_ATT_H

View file

@ -0,0 +1,318 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd, Joel Hoener
* 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
* Provides formatter functions that are shared between the different formatters.
*/
#ifndef ZYDIS_FORMATTER_BASE_H
#define ZYDIS_FORMATTER_BASE_H
#include <Zydis/Formatter.h>
#include <Zydis/Internal/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* String */
/* ---------------------------------------------------------------------------------------------- */
/**
* Appends an unsigned numeric value to the given string.
*
* @param formatter A pointer to the `ZydisFormatter` instance.
* @param base The numeric base.
* @param str The destination string.
* @param value The value.
* @param padding_length The padding length.
*/
#define ZYDIS_STRING_APPEND_NUM_U(formatter, base, str, value, padding_length) \
switch (base) \
{ \
case ZYDIS_NUMERIC_BASE_DEC: \
ZYAN_CHECK(ZydisStringAppendDecU(str, value, padding_length, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
case ZYDIS_NUMERIC_BASE_HEX: \
ZYAN_CHECK(ZydisStringAppendHexU(str, value, padding_length, \
(formatter)->hex_uppercase, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
default: \
return ZYAN_STATUS_INVALID_ARGUMENT; \
}
/**
* Appends a signed numeric value to the given string.
*
* @param formatter A pointer to the `ZydisFormatter` instance.
* @param base The numeric base.
* @param str The destination string.
* @param value The value.
* @param padding_length The padding length.
* @param force_sign Forces printing of the '+' sign for positive numbers.
*/
#define ZYDIS_STRING_APPEND_NUM_S(formatter, base, str, value, padding_length, force_sign) \
switch (base) \
{ \
case ZYDIS_NUMERIC_BASE_DEC: \
ZYAN_CHECK(ZydisStringAppendDecS(str, value, padding_length, force_sign, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
case ZYDIS_NUMERIC_BASE_HEX: \
ZYAN_CHECK(ZydisStringAppendHexS(str, value, padding_length, \
(formatter)->hex_uppercase, force_sign, \
(formatter)->number_format[base][0].string, \
(formatter)->number_format[base][1].string)); \
break; \
default: \
return ZYAN_STATUS_INVALID_ARGUMENT; \
}
/* ---------------------------------------------------------------------------------------------- */
/* Buffer */
/* ---------------------------------------------------------------------------------------------- */
/**
* Invokes the `ZydisFormatterBufferAppend` routine, if tokenization is enabled for the
* current pass.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param type The token type.
*
* Using this macro instead of direct calls to `ZydisFormatterBufferAppend` greatly improves the
* performance for non-tokenizing passes.
*/
#define ZYDIS_BUFFER_APPEND_TOKEN(buffer, type) \
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppend(buffer, type)); \
}
/**
* Returns a snapshot of the buffer-state.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param state Receives a snapshot of the buffer-state.
*
* Using this macro instead of direct calls to `ZydisFormatterBufferRemember` improves the
* performance for non-tokenizing passes.
*/
#define ZYDIS_BUFFER_REMEMBER(buffer, state) \
if ((buffer)->is_token_list) \
{ \
(state) = (ZyanUPointer)(buffer)->string.vector.data; \
} else \
{ \
(state) = (ZyanUPointer)(buffer)->string.vector.size; \
}
/**
* Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param name The base name (without prefix) of the string- or token.
*/
#define ZYDIS_BUFFER_APPEND(buffer, name) \
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppendPredefined(buffer, TOK_ ## name)); \
} else \
{ \
ZYAN_CHECK(ZydisStringAppendShort(&buffer->string, &STR_ ## name)); \
}
// TODO: Implement `letter_case` for predefined tokens
/**
* Appends a string (`STR_`-prefix) or a predefined token-list (`TOK_`-prefix).
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param name The base name (without prefix) of the string- or token.
* @param letter-case The desired letter-case.
*/
#define ZYDIS_BUFFER_APPEND_CASE(buffer, name, letter_case) \
if ((buffer)->is_token_list) \
{ \
ZYAN_CHECK(ZydisFormatterBufferAppendPredefined(buffer, TOK_ ## name)); \
} else \
{ \
ZYAN_CHECK(ZydisStringAppendShortCase(&buffer->string, &STR_ ## name, letter_case)); \
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Helper functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Buffer */
/* ---------------------------------------------------------------------------------------------- */
// MSVC does not like the C99 flexible-array extension
#ifdef ZYAN_MSVC
# pragma warning(push)
# pragma warning(disable:4200)
#endif
#pragma pack(push, 1)
typedef struct ZydisPredefinedToken_
{
ZyanU8 size;
ZyanU8 next;
ZyanU8 data[];
} ZydisPredefinedToken;
#pragma pack(pop)
#ifdef ZYAN_MSVC
# pragma warning(pop)
#endif
/**
* Appends a predefined token-list to the `buffer`.
*
* @param buffer A pointer to the `ZydisFormatterBuffer` struct.
* @param data A pointer to the `ZydisPredefinedToken` struct.
*
* @return A zycore status code.
*
* This function is internally used to improve performance while adding static strings or multiple
* tokens at once.
*/
ZYAN_INLINE ZyanStatus ZydisFormatterBufferAppendPredefined(ZydisFormatterBuffer* buffer,
const ZydisPredefinedToken* data)
{
ZYAN_ASSERT(buffer);
ZYAN_ASSERT(data);
const ZyanUSize len = buffer->string.vector.size;
ZYAN_ASSERT((len > 0) && (len < 256));
if (buffer->capacity <= len + data->size)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZydisFormatterToken* const last = (ZydisFormatterToken*)buffer->string.vector.data - 1;
last->next = (ZyanU8)len;
ZYAN_MEMCPY((ZyanU8*)buffer->string.vector.data + len, &data->data[0], data->size);
const ZyanUSize delta = len + data->next;
buffer->capacity -= delta;
buffer->string.vector.data = (ZyanU8*)buffer->string.vector.data + delta;
buffer->string.vector.size = data->size - data->next;
buffer->string.vector.capacity = ZYAN_MIN(buffer->capacity, 255);
return ZYAN_STATUS_SUCCESS;
}
/* ---------------------------------------------------------------------------------------------- */
/* General */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the size to be used as explicit size suffix (`AT&T`) or explicit typecast
* (`INTEL`), if required.
*
* @param formatter A pointer to the `ZydisFormatter` instance.
* @param context A pointer to the `ZydisFormatterContext` struct.
* @param memop_id The operand-id of the instructions first memory operand.
*
* @return Returns the explicit size, if required, or `0`, if not needed.
*
* This function always returns a size different to `0`, if the `ZYDIS_FORMATTER_PROP_FORCE_SIZE`
* is set to `ZYAN_TRUE`.
*/
ZyanU32 ZydisFormatterHelperGetExplicitSize(const ZydisFormatter* formatter,
ZydisFormatterContext* context, ZyanU8 memop_id);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Formatter functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Operands */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterBaseFormatOperandREG(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBaseFormatOperandPTR(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBaseFormatOperandIMM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Elemental tokens */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterBasePrintAddressABS(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBasePrintAddressREL(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBasePrintIMM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* Optional tokens */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterBasePrintSegment(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBasePrintPrefixes(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterBasePrintDecorator(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisDecorator decorator);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYDIS_FORMATTER_BASE_H

View file

@ -0,0 +1,267 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd, Joel Hoener
* 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
* Implements the `INTEL` style instruction-formatter.
*/
#ifndef ZYDIS_FORMATTER_INTEL_H
#define ZYDIS_FORMATTER_INTEL_H
#include <Zydis/Formatter.h>
#include <Zydis/Internal/FormatterBase.h>
#include <Zydis/Internal/String.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Formatter functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Intel */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterIntelFormatInstruction(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterIntelPrintMnemonic(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterIntelPrintRegister(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg);
ZyanStatus ZydisFormatterIntelPrintDISP(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterIntelPrintTypecast(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* MASM */
/* ---------------------------------------------------------------------------------------------- */
ZyanStatus ZydisFormatterIntelFormatInstructionMASM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter,
ZydisFormatterBuffer* buffer, ZydisFormatterContext* context);
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Fomatter presets */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* INTEL */
/* ---------------------------------------------------------------------------------------------- */
/**
* The default formatter configuration for `INTEL` style disassembly.
*/
static const ZydisFormatter FORMATTER_INTEL =
{
/* style */ ZYDIS_FORMATTER_STYLE_INTEL,
/* force_memory_size */ ZYAN_FALSE,
/* force_memory_seg */ ZYAN_FALSE,
/* force_relative_branches */ ZYAN_FALSE,
/* force_relative_riprel */ ZYAN_FALSE,
/* print_branch_size */ ZYAN_FALSE,
/* detailed_prefixes */ ZYAN_FALSE,
/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* addr_padding_absolute */ ZYDIS_PADDING_AUTO,
/* addr_padding_relative */ 2,
/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* disp_padding */ 2,
/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
/* imm_signedness */ ZYDIS_SIGNEDNESS_UNSIGNED,
/* imm_padding */ 2,
/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
/* hex_uppercase */ ZYAN_TRUE,
/* number_format */
{
// ZYDIS_NUMERIC_BASE_DEC
{
// Prefix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
},
// ZYDIS_NUMERIC_BASE_HEX
{
// Prefix
{
/* string */ &FORMATTER_INTEL.number_format[
ZYDIS_NUMERIC_BASE_HEX][0].string_data,
/* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
}
},
/* func_pre_instruction */ ZYAN_NULL,
/* func_post_instruction */ ZYAN_NULL,
/* func_format_instruction */ &ZydisFormatterIntelFormatInstruction,
/* func_pre_operand */ ZYAN_NULL,
/* func_post_operand */ ZYAN_NULL,
/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
/* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
/* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
/* func_print_register */ &ZydisFormatterIntelPrintRegister,
/* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS,
/* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL,
/* func_print_disp */ &ZydisFormatterIntelPrintDISP,
/* func_print_imm */ &ZydisFormatterBasePrintIMM,
/* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
/* func_print_segment */ &ZydisFormatterBasePrintSegment,
/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
/* func_print_decorator */ &ZydisFormatterBasePrintDecorator
};
/* ---------------------------------------------------------------------------------------------- */
/* MASM */
/* ---------------------------------------------------------------------------------------------- */
/**
* The default formatter configuration for `MASM` style disassembly.
*/
static const ZydisFormatter FORMATTER_INTEL_MASM =
{
/* style */ ZYDIS_FORMATTER_STYLE_INTEL_MASM,
/* force_memory_size */ ZYAN_TRUE,
/* force_memory_seg */ ZYAN_FALSE,
/* force_relative_branches */ ZYAN_FALSE,
/* force_relative_riprel */ ZYAN_FALSE,
/* print_branch_size */ ZYAN_FALSE,
/* detailed_prefixes */ ZYAN_FALSE,
/* addr_base */ ZYDIS_NUMERIC_BASE_HEX,
/* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* addr_padding_absolute */ ZYDIS_PADDING_DISABLED,
/* addr_padding_relative */ ZYDIS_PADDING_DISABLED,
/* disp_base */ ZYDIS_NUMERIC_BASE_HEX,
/* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED,
/* disp_padding */ ZYDIS_PADDING_DISABLED,
/* imm_base */ ZYDIS_NUMERIC_BASE_HEX,
/* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO,
/* imm_padding */ ZYDIS_PADDING_DISABLED,
/* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_registers */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT,
/* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT,
/* hex_uppercase */ ZYAN_TRUE,
/* number_format */
{
// ZYDIS_NUMERIC_BASE_DEC
{
// Prefix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
},
// ZYDIS_NUMERIC_BASE_HEX
{
// Prefix
{
/* string */ ZYAN_NULL,
/* string_data */ ZYAN_DEFINE_STRING_VIEW(""),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
},
// Suffix
{
/* string */ &FORMATTER_INTEL_MASM.number_format[
ZYDIS_NUMERIC_BASE_HEX][1].string_data,
/* string_data */ ZYAN_DEFINE_STRING_VIEW("h"),
/* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
}
}
},
/* func_pre_instruction */ ZYAN_NULL,
/* func_post_instruction */ ZYAN_NULL,
/* func_format_instruction */ &ZydisFormatterIntelFormatInstructionMASM,
/* func_pre_operand */ ZYAN_NULL,
/* func_post_operand */ ZYAN_NULL,
/* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG,
/* func_format_operand_mem */ &ZydisFormatterIntelFormatOperandMEM,
/* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR,
/* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM,
/* func_print_mnemonic */ &ZydisFormatterIntelPrintMnemonic,
/* func_print_register */ &ZydisFormatterIntelPrintRegister,
/* func_print_address_abs */ &ZydisFormatterIntelPrintAddressMASM,
/* func_print_address_rel */ &ZydisFormatterIntelPrintAddressMASM,
/* func_print_disp */ &ZydisFormatterIntelPrintDISP,
/* func_print_imm */ &ZydisFormatterBasePrintIMM,
/* func_print_typecast */ &ZydisFormatterIntelPrintTypecast,
/* func_print_segment */ &ZydisFormatterBasePrintSegment,
/* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes,
/* func_print_decorator */ &ZydisFormatterBasePrintDecorator
};
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYDIS_FORMATTER_INTEL_H

View file

@ -0,0 +1,975 @@
/***************************************************************************************************
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_INTERNAL_SHAREDDATA_H
#define ZYDIS_INTERNAL_SHAREDDATA_H
#include <Zycore/Defines.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#include <Zydis/DecoderTypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
// MSVC does not like types other than (un-)signed int for bit-fields
#ifdef ZYAN_MSVC
# pragma warning(push)
# pragma warning(disable:4214)
#endif
#pragma pack(push, 1)
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisSemanticOperandType` enum.
*/
typedef enum ZydisSemanticOperandType_
{
ZYDIS_SEMANTIC_OPTYPE_UNUSED,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_REG,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_MEM,
ZYDIS_SEMANTIC_OPTYPE_IMPLICIT_IMM1,
ZYDIS_SEMANTIC_OPTYPE_GPR8,
ZYDIS_SEMANTIC_OPTYPE_GPR16,
ZYDIS_SEMANTIC_OPTYPE_GPR32,
ZYDIS_SEMANTIC_OPTYPE_GPR64,
ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64,
ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64,
ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32,
ZYDIS_SEMANTIC_OPTYPE_GPR_ASZ,
ZYDIS_SEMANTIC_OPTYPE_FPR,
ZYDIS_SEMANTIC_OPTYPE_MMX,
ZYDIS_SEMANTIC_OPTYPE_XMM,
ZYDIS_SEMANTIC_OPTYPE_YMM,
ZYDIS_SEMANTIC_OPTYPE_ZMM,
ZYDIS_SEMANTIC_OPTYPE_TMM,
ZYDIS_SEMANTIC_OPTYPE_BND,
ZYDIS_SEMANTIC_OPTYPE_SREG,
ZYDIS_SEMANTIC_OPTYPE_CR,
ZYDIS_SEMANTIC_OPTYPE_DR,
ZYDIS_SEMANTIC_OPTYPE_MASK,
ZYDIS_SEMANTIC_OPTYPE_MEM,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBX,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBY,
ZYDIS_SEMANTIC_OPTYPE_MEM_VSIBZ,
ZYDIS_SEMANTIC_OPTYPE_IMM,
ZYDIS_SEMANTIC_OPTYPE_REL,
ZYDIS_SEMANTIC_OPTYPE_PTR,
ZYDIS_SEMANTIC_OPTYPE_AGEN,
ZYDIS_SEMANTIC_OPTYPE_MOFFS,
ZYDIS_SEMANTIC_OPTYPE_MIB,
/**
* Maximum value of this enum.
*/
ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE = ZYDIS_SEMANTIC_OPTYPE_MIB,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_SEMANTIC_OPTYPE_MAX_VALUE)
} ZydisSemanticOperandType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalElementType` enum.
*/
typedef enum ZydisInternalElementType_
{
ZYDIS_IELEMENT_TYPE_INVALID,
ZYDIS_IELEMENT_TYPE_VARIABLE,
ZYDIS_IELEMENT_TYPE_STRUCT,
ZYDIS_IELEMENT_TYPE_INT,
ZYDIS_IELEMENT_TYPE_UINT,
ZYDIS_IELEMENT_TYPE_INT1,
ZYDIS_IELEMENT_TYPE_INT8,
ZYDIS_IELEMENT_TYPE_INT16,
ZYDIS_IELEMENT_TYPE_INT32,
ZYDIS_IELEMENT_TYPE_INT64,
ZYDIS_IELEMENT_TYPE_UINT8,
ZYDIS_IELEMENT_TYPE_UINT16,
ZYDIS_IELEMENT_TYPE_UINT32,
ZYDIS_IELEMENT_TYPE_UINT64,
ZYDIS_IELEMENT_TYPE_UINT128,
ZYDIS_IELEMENT_TYPE_UINT256,
ZYDIS_IELEMENT_TYPE_FLOAT16,
ZYDIS_IELEMENT_TYPE_FLOAT32,
ZYDIS_IELEMENT_TYPE_FLOAT64,
ZYDIS_IELEMENT_TYPE_FLOAT80,
ZYDIS_IELEMENT_TYPE_BCD80,
ZYDIS_IELEMENT_TYPE_CC3,
ZYDIS_IELEMENT_TYPE_CC5,
/**
* Maximum value of this enum.
*/
ZYDIS_IELEMENT_TYPE_MAX_VALUE = ZYDIS_IELEMENT_TYPE_CC5,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IELEMENT_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_TYPE_MAX_VALUE)
} ZydisInternalElementType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisImplicitRegisterType` enum.
*/
typedef enum ZydisImplicitRegisterType_
{
ZYDIS_IMPLREG_TYPE_STATIC,
ZYDIS_IMPLREG_TYPE_GPR_OSZ,
ZYDIS_IMPLREG_TYPE_GPR_ASZ,
ZYDIS_IMPLREG_TYPE_GPR_SSZ,
ZYDIS_IMPLREG_TYPE_IP_ASZ,
ZYDIS_IMPLREG_TYPE_IP_SSZ,
ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
/**
* Maximum value of this enum.
*/
ZYDIS_IMPLREG_TYPE_MAX_VALUE = ZYDIS_IMPLREG_TYPE_FLAGS_SSZ,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IMPLREG_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLREG_TYPE_MAX_VALUE)
} ZydisImplicitRegisterType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisImplicitMemBase` enum.
*/
typedef enum ZydisImplicitMemBase_
{
ZYDIS_IMPLMEM_BASE_AGPR_REG,
ZYDIS_IMPLMEM_BASE_AGPR_RM,
ZYDIS_IMPLMEM_BASE_AAX,
ZYDIS_IMPLMEM_BASE_ADX,
ZYDIS_IMPLMEM_BASE_ABX,
ZYDIS_IMPLMEM_BASE_ASP,
ZYDIS_IMPLMEM_BASE_ABP,
ZYDIS_IMPLMEM_BASE_ASI,
ZYDIS_IMPLMEM_BASE_ADI,
/**
* Maximum value of this enum.
*/
ZYDIS_IMPLMEM_BASE_MAX_VALUE = ZYDIS_IMPLMEM_BASE_ADI,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IMPLMEM_BASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IMPLMEM_BASE_MAX_VALUE)
} ZydisImplicitMemBase;
/* ---------------------------------------------------------------------------------------------- */
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ACTION_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_REGISTER_REQUIRED_BITS <= 16);
ZYAN_STATIC_ASSERT(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisOperandDefinition` struct.
*/
typedef struct ZydisOperandDefinition_
{
ZyanU8 type ZYAN_BITFIELD(ZYDIS_SEMANTIC_OPTYPE_REQUIRED_BITS);
ZyanU8 visibility ZYAN_BITFIELD(ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS);
ZyanU8 actions ZYAN_BITFIELD(ZYDIS_OPERAND_ACTION_REQUIRED_BITS);
ZyanU16 size[3];
ZyanU8 element_type ZYAN_BITFIELD(ZYDIS_IELEMENT_TYPE_REQUIRED_BITS);
union
{
ZyanU8 encoding ZYAN_BITFIELD(ZYDIS_OPERAND_ENCODING_REQUIRED_BITS);
struct
{
ZyanU8 type ZYAN_BITFIELD(ZYDIS_IMPLREG_TYPE_REQUIRED_BITS);
union
{
ZyanU16 reg ZYAN_BITFIELD(ZYDIS_REGISTER_REQUIRED_BITS);
ZyanU8 id ZYAN_BITFIELD(6);
} reg;
} reg;
struct
{
ZyanU8 seg ZYAN_BITFIELD(3);
ZyanU8 base ZYAN_BITFIELD(ZYDIS_IMPLMEM_BASE_REQUIRED_BITS);
} mem;
} op;
ZyanBool is_multisource4 ZYAN_BITFIELD(1);
} ZydisOperandDefinition;
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisReadWriteAction` enum.
*/
typedef enum ZydisReadWriteAction_
{
ZYDIS_RW_ACTION_NONE,
ZYDIS_RW_ACTION_READ,
ZYDIS_RW_ACTION_WRITE,
ZYDIS_RW_ACTION_READWRITE,
/**
* Maximum value of this enum.
*/
ZYDIS_RW_ACTION_MAX_VALUE = ZYDIS_RW_ACTION_READWRITE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_RW_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_RW_ACTION_MAX_VALUE)
} ZydisReadWriteAction;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisRegisterConstraint` enum.
*/
typedef enum ZydisRegisterConstraint_
{
ZYDIS_REG_CONSTRAINTS_UNUSED,
ZYDIS_REG_CONSTRAINTS_NONE,
ZYDIS_REG_CONSTRAINTS_GPR,
ZYDIS_REG_CONSTRAINTS_SR_DEST,
ZYDIS_REG_CONSTRAINTS_SR,
ZYDIS_REG_CONSTRAINTS_CR,
ZYDIS_REG_CONSTRAINTS_DR,
ZYDIS_REG_CONSTRAINTS_MASK,
ZYDIS_REG_CONSTRAINTS_BND,
ZYDIS_REG_CONSTRAINTS_VSIB,
ZYDIS_REG_CONSTRAINTS_NO_REL,
/**
* Maximum value of this enum.
*/
ZYDIS_REG_CONSTRAINTS_MAX_VALUE = ZYDIS_REG_CONSTRAINTS_NO_REL,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REG_CONSTRAINTS_MAX_VALUE)
} ZydisRegisterConstraint;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalVectorLength` enum.
*/
typedef enum ZydisInternalVectorLength_
{
ZYDIS_IVECTOR_LENGTH_DEFAULT,
ZYDIS_IVECTOR_LENGTH_FIXED_128,
ZYDIS_IVECTOR_LENGTH_FIXED_256,
ZYDIS_IVECTOR_LENGTH_FIXED_512,
/**
* Maximum value of this enum.
*/
ZYDIS_IVECTOR_LENGTH_MAX_VALUE = ZYDIS_IVECTOR_LENGTH_FIXED_512,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IVECTOR_LENGTH_MAX_VALUE)
} ZydisInternalVectorLength;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInternalElementSize` enum.
*/
typedef enum ZydisInternalElementSize_
{
ZYDIS_IELEMENT_SIZE_INVALID,
ZYDIS_IELEMENT_SIZE_8,
ZYDIS_IELEMENT_SIZE_16,
ZYDIS_IELEMENT_SIZE_32,
ZYDIS_IELEMENT_SIZE_64,
ZYDIS_IELEMENT_SIZE_128,
/**
* Maximum value of this enum.
*/
ZYDIS_IELEMENT_SIZE_MAX_VALUE = ZYDIS_IELEMENT_SIZE_128,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_IELEMENT_SIZE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_IELEMENT_SIZE_MAX_VALUE)
} ZydisInternalElementSize;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXFunctionality` enum.
*/
typedef enum ZydisEVEXFunctionality_
{
ZYDIS_EVEX_FUNC_INVALID,
/**
* `EVEX.b` enables broadcast functionality.
*/
ZYDIS_EVEX_FUNC_BC,
/**
* `EVEX.b` enables embedded-rounding functionality.
*/
ZYDIS_EVEX_FUNC_RC,
/**
* `EVEX.b` enables sae functionality.
*/
ZYDIS_EVEX_FUNC_SAE,
/**
* Maximum value of this enum.
*/
ZYDIS_EVEX_FUNC_MAX_VALUE = ZYDIS_EVEX_FUNC_SAE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_EVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_FUNC_MAX_VALUE)
} ZydisEVEXFunctionality;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXTupleType` enum.
*/
typedef enum ZydisEVEXTupleType_
{
ZYDIS_TUPLETYPE_INVALID,
/**
* Full Vector
*/
ZYDIS_TUPLETYPE_FV,
/**
* Half Vector
*/
ZYDIS_TUPLETYPE_HV,
/**
* Full Vector Mem
*/
ZYDIS_TUPLETYPE_FVM,
/**
* Tuple1 Scalar
*/
ZYDIS_TUPLETYPE_T1S,
/**
* Tuple1 Fixed
*/
ZYDIS_TUPLETYPE_T1F,
/**
* Tuple1 4x32
*/
ZYDIS_TUPLETYPE_T1_4X,
/**
* Gather / Scatter
*/
ZYDIS_TUPLETYPE_GSCAT,
/**
* Tuple2
*/
ZYDIS_TUPLETYPE_T2,
/**
* Tuple4
*/
ZYDIS_TUPLETYPE_T4,
/**
* Tuple8
*/
ZYDIS_TUPLETYPE_T8,
/**
* Half Mem
*/
ZYDIS_TUPLETYPE_HVM,
/**
* QuarterMem
*/
ZYDIS_TUPLETYPE_QVM,
/**
* OctMem
*/
ZYDIS_TUPLETYPE_OVM,
/**
* Mem128
*/
ZYDIS_TUPLETYPE_M128,
/**
* MOVDDUP
*/
ZYDIS_TUPLETYPE_DUP,
/**
* Maximum value of this enum.
*/
ZYDIS_TUPLETYPE_MAX_VALUE = ZYDIS_TUPLETYPE_DUP,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_TUPLETYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_TUPLETYPE_MAX_VALUE)
} ZydisEVEXTupleType;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMVEXFunctionality` enum.
*/
typedef enum ZydisMVEXFunctionality_
{
/**
* The `MVEX.SSS` value is ignored.
*/
ZYDIS_MVEX_FUNC_IGNORED,
/**
* `MVEX.SSS` must be `000b`.
*/
ZYDIS_MVEX_FUNC_INVALID,
/**
* `MVEX.SSS` controls embedded-rounding functionality.
*/
ZYDIS_MVEX_FUNC_RC,
/**
* `MVEX.SSS` controls sae functionality.
*/
ZYDIS_MVEX_FUNC_SAE,
/**
* No special operation (32bit float elements).
*/
ZYDIS_MVEX_FUNC_F_32,
/**
* No special operation (32bit uint elements).
*/
ZYDIS_MVEX_FUNC_I_32,
/**
* No special operation (64bit float elements).
*/
ZYDIS_MVEX_FUNC_F_64,
/**
* No special operation (64bit uint elements).
*/
ZYDIS_MVEX_FUNC_I_64,
/**
* Sf32(reg) or Si32(reg).
*/
ZYDIS_MVEX_FUNC_SWIZZLE_32,
/**
* Sf64(reg) or Si64(reg).
*/
ZYDIS_MVEX_FUNC_SWIZZLE_64,
/**
* Sf32(mem).
*/
ZYDIS_MVEX_FUNC_SF_32,
/**
* Sf32(mem) broadcast only.
*/
ZYDIS_MVEX_FUNC_SF_32_BCST,
/**
* Sf32(mem) broadcast 4to16 only.
*/
ZYDIS_MVEX_FUNC_SF_32_BCST_4TO16,
/**
* Sf64(mem).
*/
ZYDIS_MVEX_FUNC_SF_64,
/**
* Si32(mem).
*/
ZYDIS_MVEX_FUNC_SI_32,
/**
* Si32(mem) broadcast only.
*/
ZYDIS_MVEX_FUNC_SI_32_BCST,
/**
* Si32(mem) broadcast 4to16 only.
*/
ZYDIS_MVEX_FUNC_SI_32_BCST_4TO16,
/**
* Si64(mem).
*/
ZYDIS_MVEX_FUNC_SI_64,
/**
* Uf32.
*/
ZYDIS_MVEX_FUNC_UF_32,
/**
* Uf64.
*/
ZYDIS_MVEX_FUNC_UF_64,
/**
* Ui32.
*/
ZYDIS_MVEX_FUNC_UI_32,
/**
* Ui64.
*/
ZYDIS_MVEX_FUNC_UI_64,
/**
* Df32.
*/
ZYDIS_MVEX_FUNC_DF_32,
/**
* Df64.
*/
ZYDIS_MVEX_FUNC_DF_64,
/**
* Di32.
*/
ZYDIS_MVEX_FUNC_DI_32,
/**
* Di64.
*/
ZYDIS_MVEX_FUNC_DI_64,
/**
* Maximum value of this enum.
*/
ZYDIS_MVEX_FUNC_MAX_VALUE = ZYDIS_MVEX_FUNC_DI_64,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MVEX_FUNC_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_FUNC_MAX_VALUE)
} ZydisMVEXFunctionality;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisVEXStaticBroadcast` enum.
*/
typedef enum ZydisVEXStaticBroadcast
{
ZYDIS_VEX_STATIC_BROADCAST_NONE,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_2,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_4,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_VEX_STATIC_BROADCAST_1_TO_32,
ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
/**
* Maximum value of this enum.
*/
ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_VEX_STATIC_BROADCAST_2_TO_4,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_VEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisEVEXStaticBroadcast` enum.
*/
typedef enum ZydisEVEXStaticBroadcast_
{
ZYDIS_EVEX_STATIC_BROADCAST_NONE,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_2,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_4,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_32,
ZYDIS_EVEX_STATIC_BROADCAST_1_TO_64,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_4,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_2_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_4_TO_8,
ZYDIS_EVEX_STATIC_BROADCAST_4_TO_16,
ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
/**
* Maximum value of this enum.
*/
ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_EVEX_STATIC_BROADCAST_8_TO_16,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_EVEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisEVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMVEXStaticBroadcast` enum.
*/
typedef enum ZydisMVEXStaticBroadcast_
{
ZYDIS_MVEX_STATIC_BROADCAST_NONE,
ZYDIS_MVEX_STATIC_BROADCAST_1_TO_8,
ZYDIS_MVEX_STATIC_BROADCAST_1_TO_16,
ZYDIS_MVEX_STATIC_BROADCAST_4_TO_8,
ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
/**
* Maximum value of this enum.
*/
ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE = ZYDIS_MVEX_STATIC_BROADCAST_4_TO_16,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_MVEX_STATIC_BROADCAST_MAX_VALUE)
} ZydisMVEXStaticBroadcast;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMaskPolicy` enum.
*/
typedef enum ZydisMaskPolicy_
{
ZYDIS_MASK_POLICY_INVALID,
/**
* The instruction accepts mask-registers other than the default-mask (K0), but
* does not require them.
*/
ZYDIS_MASK_POLICY_ALLOWED,
/**
* The instruction requires a mask-register other than the default-mask (K0).
*/
ZYDIS_MASK_POLICY_REQUIRED,
/**
* The instruction does not allow a mask-register other than the default-mask (K0).
*/
ZYDIS_MASK_POLICY_FORBIDDEN,
/**
* Maximum value of this enum.
*/
ZYDIS_MASK_POLICY_MAX_VALUE = ZYDIS_MASK_POLICY_FORBIDDEN,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MASK_POLICY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_POLICY_MAX_VALUE)
} ZydisMaskPolicy;
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMaskOverride` enum.
*/
typedef enum ZydisMaskOverride_
{
ZYDIS_MASK_OVERRIDE_DEFAULT,
ZYDIS_MASK_OVERRIDE_ZEROING,
ZYDIS_MASK_OVERRIDE_CONTROL,
/**
* Maximum value of this enum.
*/
ZYDIS_MASK_OVERRIDE_MAX_VALUE = ZYDIS_MASK_OVERRIDE_CONTROL,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MASK_OVERRIDE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MASK_OVERRIDE_MAX_VALUE)
} ZydisMaskOverride;
/* ---------------------------------------------------------------------------------------------- */
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_MNEMONIC_REQUIRED_BITS <= 16);
ZYAN_STATIC_ASSERT(ZYDIS_CATEGORY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_ISA_SET_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_ISA_EXT_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_BRANCH_TYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_RW_ACTION_REQUIRED_BITS <= 8);
#ifndef ZYDIS_MINIMAL_MODE
# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
ZyanU8 operand_count ZYAN_BITFIELD( 4); \
ZyanU16 operand_reference ZYAN_BITFIELD(15); \
ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
ZyanU8 flags_reference ZYAN_BITFIELD( 7); \
ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
ZyanU8 category ZYAN_BITFIELD(ZYDIS_CATEGORY_REQUIRED_BITS); \
ZyanU8 isa_set ZYAN_BITFIELD(ZYDIS_ISA_SET_REQUIRED_BITS); \
ZyanU8 isa_ext ZYAN_BITFIELD(ZYDIS_ISA_EXT_REQUIRED_BITS); \
ZyanU8 branch_type ZYAN_BITFIELD(ZYDIS_BRANCH_TYPE_REQUIRED_BITS); \
ZyanU8 exception_class ZYAN_BITFIELD(ZYDIS_EXCEPTION_CLASS_REQUIRED_BITS); \
ZyanU8 constr_REG ZYAN_BITFIELD(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS); \
ZyanU8 constr_RM ZYAN_BITFIELD(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS); \
ZyanU8 cpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
ZyanU8 fpu_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS); \
ZyanU8 xmm_state ZYAN_BITFIELD(ZYDIS_RW_ACTION_REQUIRED_BITS)
#else
# define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZyanU16 mnemonic ZYAN_BITFIELD(ZYDIS_MNEMONIC_REQUIRED_BITS); \
ZyanU8 operand_size_map ZYAN_BITFIELD( 3); \
ZyanU8 address_size_map ZYAN_BITFIELD( 2); \
ZyanBool requires_protected_mode ZYAN_BITFIELD( 1); \
ZyanU8 constr_REG ZYAN_BITFIELD(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS); \
ZyanU8 constr_RM ZYAN_BITFIELD(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS)
#endif
#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR \
ZYDIS_INSTRUCTION_DEFINITION_BASE; \
ZyanU8 constr_NDSNDD ZYAN_BITFIELD(ZYDIS_REG_CONSTRAINTS_REQUIRED_BITS)
#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL \
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR; \
ZyanBool is_gather ZYAN_BITFIELD( 1)
/**
* Defines the `ZydisInstructionDefinition` struct.
*/
typedef struct ZydisInstructionDefinition_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
} ZydisInstructionDefinition;
/**
* Defines the `ZydisInstructionDefinitionLEGACY` struct.
*/
typedef struct ZydisInstructionDefinitionLEGACY_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool is_privileged ZYAN_BITFIELD( 1);
#endif
ZyanBool accepts_LOCK ZYAN_BITFIELD( 1);
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool accepts_REP ZYAN_BITFIELD( 1);
ZyanBool accepts_REPEREPZ ZYAN_BITFIELD( 1);
ZyanBool accepts_REPNEREPNZ ZYAN_BITFIELD( 1);
ZyanBool accepts_BOUND ZYAN_BITFIELD( 1);
ZyanBool accepts_XACQUIRE ZYAN_BITFIELD( 1);
ZyanBool accepts_XRELEASE ZYAN_BITFIELD( 1);
ZyanBool accepts_hle_without_lock ZYAN_BITFIELD( 1);
ZyanBool accepts_branch_hints ZYAN_BITFIELD( 1);
ZyanBool accepts_segment ZYAN_BITFIELD( 1);
#endif
} ZydisInstructionDefinitionLEGACY;
/**
* Defines the `ZydisInstructionDefinition3DNOW` struct.
*/
typedef struct ZydisInstructionDefinition3DNOW_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE;
} ZydisInstructionDefinition3DNOW;
/**
* Defines the `ZydisInstructionDefinitionXOP` struct.
*/
typedef struct ZydisInstructionDefinitionXOP_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR;
} ZydisInstructionDefinitionXOP;
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionVEX` struct.
*/
typedef struct ZydisInstructionDefinitionVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_VEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionVEX;
#ifndef ZYDIS_DISABLE_AVX512
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_TUPLETYPE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EVEX_FUNC_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionEVEX` struct.
*/
typedef struct ZydisInstructionDefinitionEVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 vector_length ZYAN_BITFIELD(ZYDIS_IVECTOR_LENGTH_REQUIRED_BITS);
ZyanU8 tuple_type ZYAN_BITFIELD(ZYDIS_TUPLETYPE_REQUIRED_BITS);
ZyanU8 element_size ZYAN_BITFIELD(ZYDIS_IELEMENT_SIZE_REQUIRED_BITS);
ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_EVEX_FUNC_REQUIRED_BITS);
#endif
ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
ZyanBool accepts_zero_mask ZYAN_BITFIELD( 1);
#ifndef ZYDIS_MINIMAL_MODE
ZyanU8 mask_override ZYAN_BITFIELD(ZYDIS_MASK_OVERRIDE_REQUIRED_BITS);
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_EVEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionEVEX;
#endif
#ifndef ZYDIS_DISABLE_KNC
// MSVC does not correctly execute the `pragma pack(1)` compiler-directive, if we use the correct
// enum types
ZYAN_STATIC_ASSERT(ZYDIS_MVEX_FUNC_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MASK_POLICY_REQUIRED_BITS <= 8);
ZYAN_STATIC_ASSERT(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS <= 8);
/**
* Defines the `ZydisInstructionDefinitionMVEX` struct.
*/
typedef struct ZydisInstructionDefinitionMVEX_
{
ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR_INTEL;
ZyanU8 functionality ZYAN_BITFIELD(ZYDIS_MVEX_FUNC_REQUIRED_BITS);
ZyanU8 mask_policy ZYAN_BITFIELD(ZYDIS_MASK_POLICY_REQUIRED_BITS);
#ifndef ZYDIS_MINIMAL_MODE
ZyanBool has_element_granularity ZYAN_BITFIELD( 1);
ZyanU8 broadcast ZYAN_BITFIELD(ZYDIS_MVEX_STATIC_BROADCAST_REQUIRED_BITS);
#endif
} ZydisInstructionDefinitionMVEX;
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
typedef struct ZydisAccessedFlags_
{
ZydisCPUFlagAction action[ZYDIS_CPUFLAG_MAX_VALUE + 1];
ZyanU32 cpu_flags_read ZYAN_BITFIELD(22);
ZyanU32 cpu_flags_written ZYAN_BITFIELD(22);
ZyanU8 fpu_flags_read ZYAN_BITFIELD( 4);
ZyanU8 fpu_flags_written ZYAN_BITFIELD( 4);
} ZydisAccessedFlags;
/* ---------------------------------------------------------------------------------------------- */
#pragma pack(pop)
#ifdef ZYAN_MSVC
# pragma warning(pop)
#endif
/* ============================================================================================== */
/* Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Instruction definition */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the instruction-definition with the given `encoding` and `id`.
*
* @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(ZydisInstructionEncoding encoding,
ZyanU16 id, const ZydisInstructionDefinition** definition);
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the the operand-definitions for the given instruction-`definition`.
*
* @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 ZyanU8 ZydisGetOperandDefinitions(const ZydisInstructionDefinition* definition,
const ZydisOperandDefinition** operand);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Element info */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the actual type and size of an internal element-type.
*
* @param element The internal element type.
* @param type The actual element type.
* @param size The element size.
*/
ZYDIS_NO_EXPORT void ZydisGetElementInfo(ZydisInternalElementType element, ZydisElementType* type,
ZydisElementSize* size);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
#ifndef ZYDIS_MINIMAL_MODE
/**
* Returns the the operand-definitions for the given instruction-`definition`.
*
* @param definition A pointer to the instruction-definition.
* @param flags A pointer to the variable that receives the `ZydisAccessedFlags` struct.
*
* @return `ZYAN_TRUE`, if the instruction accesses any flags, or `ZYAN_FALSE`, if not.
*/
ZYDIS_NO_EXPORT ZyanBool ZydisGetAccessedFlags(const ZydisInstructionDefinition* definition,
const ZydisAccessedFlags** flags);
#endif
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_INTERNAL_SHAREDDATA_H */

View file

@ -0,0 +1,464 @@
/***************************************************************************************************
Zyan Disassembler Library (Zydis)
Original Author : Florian Bernd, Joel Hoener
* 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
* Provides some internal, more performant, but unsafe helper functions for the `ZyanString`
* data-type.
*
* Most of these functions are very similar to the ones in `Zycore/String.h`, but inlined and
* without optional overhead like parameter-validation checks, etc ...
*
* The `ZyanString` data-type is able to dynamically allocate memory on the heap, but as `Zydis` is
* designed to be a non-'malloc'ing library, all functions in this file assume that the instances
* they are operating on are created with a user-defined static-buffer.
*/
#ifndef ZYDIS_INTERNAL_STRING_H
#define ZYDIS_INTERNAL_STRING_H
#include <Zycore/LibC.h>
#include <Zycore/String.h>
#include <Zycore/Types.h>
#include <Zycore/Format.h>
#include <Zydis/ShortString.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Letter Case */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisLetterCase` enum.
*/
typedef enum ZydisLetterCase_
{
/**
* Uses the given text "as is".
*/
ZYDIS_LETTER_CASE_DEFAULT,
/**
* Converts the given text to lowercase letters.
*/
ZYDIS_LETTER_CASE_LOWER,
/**
* Converts the given text to uppercase letters.
*/
ZYDIS_LETTER_CASE_UPPER,
/**
* Maximum value of this enum.
*/
ZYDIS_LETTER_CASE_MAX_VALUE = ZYDIS_LETTER_CASE_UPPER,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_LETTER_CASE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_LETTER_CASE_MAX_VALUE)
} ZydisLetterCase;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Internal macros */
/* ---------------------------------------------------------------------------------------------- */
/**
* Checks for a terminating '\0' character at the end of the string data.
*/
#define ZYDIS_STRING_ASSERT_NULLTERMINATION(string) \
ZYAN_ASSERT(*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) == '\0');
/**
* Writes a terminating '\0' character at the end of the string data.
*/
#define ZYDIS_STRING_NULLTERMINATE(string) \
*(char*)((ZyanU8*)(string)->vector.data + (string)->vector.size - 1) = '\0';
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Internal Functions */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Appending */
/* ---------------------------------------------------------------------------------------------- */
/**
* Appends the content of the source string to the end of the destination string.
*
* @param destination The destination string.
* @param source The source string.
*
* @return A zyan status code.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppend(ZyanString* destination, const ZyanStringView* source)
{
ZYAN_ASSERT(destination && source);
ZYAN_ASSERT(!destination->vector.allocator);
ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
source->string.vector.data, source->string.vector.size - 1);
destination->vector.size += source->string.vector.size - 1;
ZYDIS_STRING_NULLTERMINATE(destination);
return ZYAN_STATUS_SUCCESS;
}
/**
* Appends the content of the source string to the end of the destination
* string, converting the characters to the specified letter-case.
*
* @param destination The destination string.
* @param source The source string.
* @param letter_case The desired letter-case.
*
* @return A zyan status code.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppendCase(ZyanString* destination, const ZyanStringView* source,
ZydisLetterCase letter_case)
{
ZYAN_ASSERT(destination && source);
ZYAN_ASSERT(!destination->vector.allocator);
ZYAN_ASSERT(destination->vector.size && source->string.vector.size);
if (destination->vector.size + source->string.vector.size - 1 > destination->vector.capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1,
source->string.vector.data, source->string.vector.size - 1);
switch (letter_case)
{
case ZYDIS_LETTER_CASE_DEFAULT:
break;
case ZYDIS_LETTER_CASE_LOWER:
{
const ZyanUSize index = destination->vector.size - 1;
const ZyanUSize count = source->string.vector.size - 1;
char* s = (char*)destination->vector.data + index;
for (ZyanUSize i = index; i < index + count; ++i)
{
const char c = *s;
if ((c >= 'A') && (c <= 'Z'))
{
*s = c | 32;
}
++s;
}
break;
}
case ZYDIS_LETTER_CASE_UPPER:
{
const ZyanUSize index = destination->vector.size - 1;
const ZyanUSize count = source->string.vector.size - 1;
char* s = (char*)destination->vector.data + index;
for (ZyanUSize i = index; i < index + count; ++i)
{
const char c = *s;
if ((c >= 'a') && (c <= 'z'))
{
*s = c & ~32;
}
++s;
}
break;
}
default:
ZYAN_UNREACHABLE;
}
destination->vector.size += source->string.vector.size - 1;
ZYDIS_STRING_NULLTERMINATE(destination);
return ZYAN_STATUS_SUCCESS;
}
/**
* Appends the content of the source short-string to the end of the destination string.
*
* @param destination The destination string.
* @param source The source string.
*
* @return A zyan status code.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppendShort(ZyanString* destination,
const ZydisShortString* source)
{
ZYAN_ASSERT(destination && source);
ZYAN_ASSERT(!destination->vector.allocator);
ZYAN_ASSERT(destination->vector.size && source->size);
if (destination->vector.size + source->size > destination->vector.capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
(ZyanUSize)source->size + 1);
destination->vector.size += source->size;
ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
return ZYAN_STATUS_SUCCESS;
}
/**
* Appends the content of the source short-string to the end of the destination string,
* converting the characters to the specified letter-case.
*
* @param destination The destination string.
* @param source The source string.
* @param letter_case The desired letter-case.
*
* @return A zyan status code.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppendShortCase(ZyanString* destination,
const ZydisShortString* source, ZydisLetterCase letter_case)
{
ZYAN_ASSERT(destination && source);
ZYAN_ASSERT(!destination->vector.allocator);
ZYAN_ASSERT(destination->vector.size && source->size);
if (destination->vector.size + source->size > destination->vector.capacity)
{
return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE;
}
ZYAN_MEMCPY((char*)destination->vector.data + destination->vector.size - 1, source->data,
(ZyanUSize)source->size + 1);
switch (letter_case)
{
case ZYDIS_LETTER_CASE_DEFAULT:
break;
case ZYDIS_LETTER_CASE_LOWER:
{
const ZyanUSize index = destination->vector.size - 1;
const ZyanUSize count = source->size;
char* s = (char*)destination->vector.data + index;
for (ZyanUSize i = index; i < index + count; ++i)
{
const char c = *s;
if ((c >= 'A') && (c <= 'Z'))
{
*s = c | 32;
}
++s;
}
break;
}
case ZYDIS_LETTER_CASE_UPPER:
{
const ZyanUSize index = destination->vector.size - 1;
const ZyanUSize count = source->size;
char* s = (char*)destination->vector.data + index;
for (ZyanUSize i = index; i < index + count; ++i)
{
const char c = *s;
if ((c >= 'a') && (c <= 'z'))
{
*s = c & ~32;
}
++s;
}
break;
}
default:
ZYAN_UNREACHABLE;
}
destination->vector.size += source->size;
ZYDIS_STRING_ASSERT_NULLTERMINATION(destination);
return ZYAN_STATUS_SUCCESS;
}
/* ---------------------------------------------------------------------------------------------- */
/* Formatting */
/* ---------------------------------------------------------------------------------------------- */
/**
* Formats the given unsigned ordinal `value` to its decimal text-representation and
* appends it to the `string`.
*
* @param string A pointer to the `ZyanString` instance.
* @param value The value.
* @param padding_length Padds the converted value with leading zeros, if the number of chars is
* less than the `padding_length`.
* @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed.
* @param suffix The string to use as suffix or `ZYAN_NULL`, if not needed.
*
* @return A zyan status code.
*
* This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
* `ZyanString` instance.
*/
ZyanStatus ZydisStringAppendDecU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
const ZyanStringView* prefix, const ZyanStringView* suffix);
/**
* Formats the given signed ordinal `value` to its decimal text-representation and
* appends it to the `string`.
*
* @param string A pointer to the `ZyanString` instance.
* @param value The value.
* @param padding_length Padds the converted value with leading zeros, if the number of chars is
* less than the `padding_length`.
* @param force_sign Set `ZYAN_TRUE`, to force printing of the `+` sign for positive numbers.
* @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed.
* @param suffix The string to use as suffix or `ZYAN_NULL`, if not needed.
*
* @return A zyan status code.
*
* This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
* `ZyanString` instance.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppendDecS(ZyanString* string, ZyanI64 value,
ZyanU8 padding_length, ZyanBool force_sign, const ZyanStringView* prefix,
const ZyanStringView* suffix)
{
static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
if (value < 0)
{
ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
if (prefix)
{
ZYAN_CHECK(ZydisStringAppend(string, prefix));
}
return ZydisStringAppendDecU(string, ZyanAbsI64(value), padding_length,
(const ZyanStringView*)ZYAN_NULL, suffix);
}
if (force_sign)
{
ZYAN_ASSERT(value >= 0);
ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
}
return ZydisStringAppendDecU(string, value, padding_length, prefix, suffix);
}
/**
* Formats the given unsigned ordinal `value` to its hexadecimal text-representation and
* appends it to the `string`.
*
* @param string A pointer to the `ZyanString` instance.
* @param value The value.
* @param padding_length Padds the converted value with leading zeros, if the number of chars is
* less than the `padding_length`.
* @param uppercase Set `ZYAN_TRUE` to use uppercase letters ('A'-'F') instead of lowercase
* ones ('a'-'f').
* @param prefix The string to use as prefix or `ZYAN_NULL`, if not needed.
* @param suffix The string to use as suffix or `ZYAN_NULL`, if not needed.
*
* @return A zyan status code.
*
* This function will fail, if the `ZYAN_STRING_IS_IMMUTABLE` flag is set for the specified
* `ZyanString` instance.
*/
ZyanStatus ZydisStringAppendHexU(ZyanString* string, ZyanU64 value, ZyanU8 padding_length,
ZyanBool uppercase, const ZyanStringView* prefix, const ZyanStringView* suffix);
/**
* Formats the given signed ordinal `value` to its hexadecimal text-representation and
* appends it to the `string`.
*
* @param string A pointer to the string.
* @param value The value.
* @param padding_length Padds the converted value with leading zeros, if the number of chars is
* less than the `padding_length` (the sign char is ignored).
* @param uppercase Set `ZYAN_TRUE` to print the hexadecimal value in uppercase letters
* instead of lowercase ones.
* @param force_sign Set to `ZYAN_TRUE`, to force printing of the `+` sign for positive
* numbers.
* @param prefix The string to use as prefix or `NULL`, if not needed.
* @param suffix The string to use as suffix or `NULL`, if not needed.
*
* @return `ZYAN_STATUS_SUCCESS`, if the function succeeded, or
* `ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE`, if the size of the buffer was not
* sufficient to append the given `value`.
*
* The string-buffer pointer is increased by the number of chars written, if the call was
* successful.
*/
ZYAN_INLINE ZyanStatus ZydisStringAppendHexS(ZyanString* string, ZyanI64 value,
ZyanU8 padding_length, ZyanBool uppercase, ZyanBool force_sign, const ZyanStringView* prefix,
const ZyanStringView* suffix)
{
static const ZydisShortString str_add = ZYDIS_MAKE_SHORTSTRING("+");
static const ZydisShortString str_sub = ZYDIS_MAKE_SHORTSTRING("-");
if (value < 0)
{
ZYAN_CHECK(ZydisStringAppendShort(string, &str_sub));
if (prefix)
{
ZYAN_CHECK(ZydisStringAppend(string, prefix));
}
return ZydisStringAppendHexU(string, ZyanAbsI64(value), padding_length, uppercase,
(const ZyanStringView*)ZYAN_NULL, suffix);
}
if (force_sign)
{
ZYAN_ASSERT(value >= 0);
ZYAN_CHECK(ZydisStringAppendShort(string, &str_add));
}
return ZydisStringAppendHexU(string, value, padding_length, uppercase, prefix, suffix);
}
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif // ZYDIS_INTERNAL_STRING_H

View file

@ -0,0 +1,88 @@
/***************************************************************************************************
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
*/
#ifndef ZYDIS_METAINFO_H
#define ZYDIS_METAINFO_H
#include <ZydisExportConfig.h>
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#include <Zydis/Generated/EnumInstructionCategory.h>
#include <Zydis/Generated/EnumISASet.h>
#include <Zydis/Generated/EnumISAExt.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* Returns the specified instruction category string.
*
* @param category The instruction category.
*
* @return The instruction category string or `ZYAN_NULL`, if an invalid category was passed.
*/
ZYDIS_EXPORT const char* ZydisCategoryGetString(ZydisInstructionCategory category);
/**
* Returns the specified isa-set string.
*
* @param isa_set The isa-set.
*
* @return The isa-set string or `ZYAN_NULL`, if an invalid isa-set was passed.
*/
ZYDIS_EXPORT const char* ZydisISASetGetString(ZydisISASet isa_set);
/**
* Returns the specified isa-extension string.
*
* @param isa_ext The isa-extension.
*
* @return The isa-extension string or `ZYAN_NULL`, if an invalid isa-extension was passed.
*/
ZYDIS_EXPORT const char* ZydisISAExtGetString(ZydisISAExt isa_ext);
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_METAINFO_H */

View file

@ -0,0 +1,88 @@
/***************************************************************************************************
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
* Mnemonic constant definitions and helper functions.
*/
#ifndef ZYDIS_MNEMONIC_H
#define ZYDIS_MNEMONIC_H
#include <Zycore/Types.h>
#include <Zydis/ShortString.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#include <Zydis/Generated/EnumMnemonic.h>
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup mnemonic Mnemonic
* Functions for retrieving mnemonic names.
* @{
*/
/**
* Returns the specified instruction mnemonic string.
*
* @param mnemonic The mnemonic.
*
* @return The instruction mnemonic string or `ZYAN_NULL`, if an invalid mnemonic was passed.
*/
ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic);
/**
* Returns the specified instruction mnemonic as `ZydisShortString`.
*
* @param mnemonic The mnemonic.
*
* @return The instruction mnemonic string or `ZYAN_NULL`, if an invalid mnemonic was passed.
*
* The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case.
*/
ZYDIS_EXPORT const ZydisShortString* ZydisMnemonicGetStringWrapped(ZydisMnemonic mnemonic);
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_MNEMONIC_H */

293
externals/zydis/include/Zydis/Register.h vendored Normal file
View file

@ -0,0 +1,293 @@
/***************************************************************************************************
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
* Utility functions and constants for registers.
*/
#ifndef ZYDIS_REGISTER_H
#define ZYDIS_REGISTER_H
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#include <Zydis/SharedTypes.h>
#include <Zydis/ShortString.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Registers */
/* ---------------------------------------------------------------------------------------------- */
#include <Zydis/Generated/EnumRegister.h>
/* ---------------------------------------------------------------------------------------------- */
/* Register classes */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisRegisterClass` enum.
*
* Please note that this enum does not contain a matching entry for all values of the
* `ZydisRegister` enum, but only for those registers where it makes sense to logically group them
* for decoding/encoding purposes.
*
* These are mainly the registers that can be identified by an id within their corresponding
* register-class. The `IP` and `FLAGS` values are exceptions to this rule.
*/
typedef enum ZydisRegisterClass_
{
ZYDIS_REGCLASS_INVALID,
/**
* 8-bit general-purpose registers.
*/
ZYDIS_REGCLASS_GPR8,
/**
* 16-bit general-purpose registers.
*/
ZYDIS_REGCLASS_GPR16,
/**
* 32-bit general-purpose registers.
*/
ZYDIS_REGCLASS_GPR32,
/**
* 64-bit general-purpose registers.
*/
ZYDIS_REGCLASS_GPR64,
/**
* Floating point legacy registers.
*/
ZYDIS_REGCLASS_X87,
/**
* Floating point multimedia registers.
*/
ZYDIS_REGCLASS_MMX,
/**
* 128-bit vector registers.
*/
ZYDIS_REGCLASS_XMM,
/**
* 256-bit vector registers.
*/
ZYDIS_REGCLASS_YMM,
/**
* 512-bit vector registers.
*/
ZYDIS_REGCLASS_ZMM,
/**
* Matrix registers.
*/
ZYDIS_REGCLASS_TMM,
/*
* Flags registers.
*/
ZYDIS_REGCLASS_FLAGS,
/**
* Instruction-pointer registers.
*/
ZYDIS_REGCLASS_IP,
/**
* Segment registers.
*/
ZYDIS_REGCLASS_SEGMENT,
/**
* Test registers.
*/
ZYDIS_REGCLASS_TEST,
/**
* Control registers.
*/
ZYDIS_REGCLASS_CONTROL,
/**
* Debug registers.
*/
ZYDIS_REGCLASS_DEBUG,
/**
* Mask registers.
*/
ZYDIS_REGCLASS_MASK,
/**
* Bound registers.
*/
ZYDIS_REGCLASS_BOUND,
/**
* Maximum value of this enum.
*/
ZYDIS_REGCLASS_MAX_VALUE = ZYDIS_REGCLASS_BOUND,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_REGCLASS_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGCLASS_MAX_VALUE)
} ZydisRegisterClass;
/* ---------------------------------------------------------------------------------------------- */
/* Register width */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisRegisterWidth` data-type.
*/
typedef ZyanU16 ZydisRegisterWidth;
/* ---------------------------------------------------------------------------------------------- */
/* Register context */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisRegisterContext` struct.
*/
typedef struct ZydisRegisterContext_
{
/**
* The values stored in the register context.
*/
ZyanU64 values[ZYDIS_REGISTER_MAX_VALUE + 1];
} ZydisRegisterContext;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup register Register
* Functions allowing retrieval of information about registers.
* @{
*/
/* ---------------------------------------------------------------------------------------------- */
/* Register */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the register specified by the `register_class` and `id` tuple.
*
* @param register_class The register class.
* @param id The register id.
*
* @return The register specified by the `register_class` and `id` tuple or `ZYDIS_REGISTER_NONE`,
* if an invalid parameter was passed.
*/
ZYDIS_EXPORT ZydisRegister ZydisRegisterEncode(ZydisRegisterClass register_class, ZyanU8 id);
/**
* Returns the id of the specified register.
*
* @param reg The register.
*
* @return The id of the specified register, or -1 if an invalid parameter was passed.
*/
ZYDIS_EXPORT ZyanI8 ZydisRegisterGetId(ZydisRegister reg);
/**
* Returns the register-class of the specified register.
*
* @param reg The register.
*
* @return The register-class of the specified register.
*/
ZYDIS_EXPORT ZydisRegisterClass ZydisRegisterGetClass(ZydisRegister reg);
/**
* Returns the width of the specified register.
*
* @param mode The active machine mode.
* @param reg The register.
*
* @return The width of the specified register, or `ZYDIS_REGISTER_NONE` if the register is
* invalid for the active machine-mode.
*/
ZYDIS_EXPORT ZydisRegisterWidth ZydisRegisterGetWidth(ZydisMachineMode mode, ZydisRegister reg);
/**
* Returns the largest enclosing register of the given register.
*
* @param mode The active machine mode.
* @param reg The register.
*
* @return The largest enclosing register of the given register, or `ZYDIS_REGISTER_NONE` if the
* register is invalid for the active machine-mode or does not have an enclosing-register.
*/
ZYDIS_EXPORT ZydisRegister ZydisRegisterGetLargestEnclosing(ZydisMachineMode mode,
ZydisRegister reg);
/**
* Returns the specified register string.
*
* @param reg The register.
*
* @return The register string or `ZYAN_NULL`, if an invalid register was passed.
*/
ZYDIS_EXPORT const char* ZydisRegisterGetString(ZydisRegister reg);
/**
* Returns the specified register string as `ZydisShortString`.
*
* @param reg The register.
*
* @return The register string or `ZYAN_NULL`, if an invalid register was passed.
*
* The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case.
*/
ZYDIS_EXPORT const ZydisShortString* ZydisRegisterGetStringWrapped(ZydisRegister reg);
/* ---------------------------------------------------------------------------------------------- */
/* Register class */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns the width of the specified register-class.
*
* @param mode The active machine mode.
* @param register_class The register class.
*
* @return The width of the specified register.
*/
ZYDIS_EXPORT ZydisRegisterWidth ZydisRegisterClassGetWidth(ZydisMachineMode mode,
ZydisRegisterClass register_class);
/* ---------------------------------------------------------------------------------------------- */
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_REGISTER_H */

View file

@ -0,0 +1,480 @@
/***************************************************************************************************
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
* Defines decoder/encoder-shared macros and types.
*/
#ifndef ZYDIS_SHAREDTYPES_H
#define ZYDIS_SHAREDTYPES_H
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_MAX_INSTRUCTION_LENGTH 15
#define ZYDIS_MAX_OPERAND_COUNT 10
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Machine mode */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisMachineMode` enum.
*/
typedef enum ZydisMachineMode_
{
/**
* 64 bit mode.
*/
ZYDIS_MACHINE_MODE_LONG_64,
/**
* 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_32,
/**
* 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LONG_COMPAT_16,
/**
* 32 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_32,
/**
* 16 bit protected mode.
*/
ZYDIS_MACHINE_MODE_LEGACY_16,
/**
* 16 bit real mode.
*/
ZYDIS_MACHINE_MODE_REAL_16,
/**
* Maximum value of this enum.
*/
ZYDIS_MACHINE_MODE_MAX_VALUE = ZYDIS_MACHINE_MODE_REAL_16,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_MACHINE_MODE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_MACHINE_MODE_MAX_VALUE)
} ZydisMachineMode;
/* ---------------------------------------------------------------------------------------------- */
/* Address width */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisAddressWidth` enum.
*/
typedef enum ZydisAddressWidth_
{
ZYDIS_ADDRESS_WIDTH_16,
ZYDIS_ADDRESS_WIDTH_32,
ZYDIS_ADDRESS_WIDTH_64,
/**
* Maximum value of this enum.
*/
ZYDIS_ADDRESS_WIDTH_MAX_VALUE = ZYDIS_ADDRESS_WIDTH_64,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_ADDRESS_WIDTH_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ADDRESS_WIDTH_MAX_VALUE)
} ZydisAddressWidth;
/* ---------------------------------------------------------------------------------------------- */
/* Element type */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisElementType` enum.
*/
typedef enum ZydisElementType_
{
ZYDIS_ELEMENT_TYPE_INVALID,
/**
* A struct type.
*/
ZYDIS_ELEMENT_TYPE_STRUCT,
/**
* Unsigned integer value.
*/
ZYDIS_ELEMENT_TYPE_UINT,
/**
* Signed integer value.
*/
ZYDIS_ELEMENT_TYPE_INT,
/**
* 16-bit floating point value (`half`).
*/
ZYDIS_ELEMENT_TYPE_FLOAT16,
/**
* 32-bit floating point value (`single`).
*/
ZYDIS_ELEMENT_TYPE_FLOAT32,
/**
* 64-bit floating point value (`double`).
*/
ZYDIS_ELEMENT_TYPE_FLOAT64,
/**
* 80-bit floating point value (`extended`).
*/
ZYDIS_ELEMENT_TYPE_FLOAT80,
/**
* Binary coded decimal value.
*/
ZYDIS_ELEMENT_TYPE_LONGBCD,
/**
* A condition code (e.g. used by `CMPPD`, `VCMPPD`, ...).
*/
ZYDIS_ELEMENT_TYPE_CC,
/**
* Maximum value of this enum.
*/
ZYDIS_ELEMENT_TYPE_MAX_VALUE = ZYDIS_ELEMENT_TYPE_CC,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_ELEMENT_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ELEMENT_TYPE_MAX_VALUE)
} ZydisElementType;
/* ---------------------------------------------------------------------------------------------- */
/* Element size */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisElementSize` datatype.
*/
typedef ZyanU16 ZydisElementSize;
/* ---------------------------------------------------------------------------------------------- */
/* Operand type */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisOperandType` enum.
*/
typedef enum ZydisOperandType_
{
/**
* The operand is not used.
*/
ZYDIS_OPERAND_TYPE_UNUSED,
/**
* The operand is a register operand.
*/
ZYDIS_OPERAND_TYPE_REGISTER,
/**
* The operand is a memory operand.
*/
ZYDIS_OPERAND_TYPE_MEMORY,
/**
* The operand is a pointer operand with a segment:offset lvalue.
*/
ZYDIS_OPERAND_TYPE_POINTER,
/**
* The operand is an immediate operand.
*/
ZYDIS_OPERAND_TYPE_IMMEDIATE,
/**
* Maximum value of this enum.
*/
ZYDIS_OPERAND_TYPE_MAX_VALUE = ZYDIS_OPERAND_TYPE_IMMEDIATE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_OPERAND_TYPE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_OPERAND_TYPE_MAX_VALUE)
} ZydisOperandType;
/* ---------------------------------------------------------------------------------------------- */
/* Operand encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisOperandEncoding` enum.
*/
typedef enum ZydisOperandEncoding_
{
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,
/**
* Maximum value of this enum.
*/
ZYDIS_OPERAND_ENCODING_MAX_VALUE = ZYDIS_OPERAND_ENCODING_JIMM16_32_32,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_OPERAND_ENCODING_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_OPERAND_ENCODING_MAX_VALUE)
} ZydisOperandEncoding;
/* ---------------------------------------------------------------------------------------------- */
/* Operand visibility */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisOperandVisibility` enum.
*/
typedef enum ZydisOperandVisibility_
{
ZYDIS_OPERAND_VISIBILITY_INVALID,
/**
* The operand is explicitly encoded in the instruction.
*/
ZYDIS_OPERAND_VISIBILITY_EXPLICIT,
/**
* The operand is part of the opcode, but listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_IMPLICIT,
/**
* The operand is part of the opcode, and not typically listed as an operand.
*/
ZYDIS_OPERAND_VISIBILITY_HIDDEN,
/**
* Maximum value of this enum.
*/
ZYDIS_OPERAND_VISIBILITY_MAX_VALUE = ZYDIS_OPERAND_VISIBILITY_HIDDEN,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_OPERAND_VISIBILITY_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_OPERAND_VISIBILITY_MAX_VALUE)
} ZydisOperandVisibility;
/* ---------------------------------------------------------------------------------------------- */
/* Operand action */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisOperandAction` enum.
*/
typedef enum ZydisOperandAction_
{
/* ------------------------------------------------------------------------------------------ */
/* Elemental actions */
/* ------------------------------------------------------------------------------------------ */
/**
* The operand is read by the instruction.
*/
ZYDIS_OPERAND_ACTION_READ = 0x01,
/**
* The operand is written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_WRITE = 0x02,
/**
* The operand is conditionally read by the instruction.
*/
ZYDIS_OPERAND_ACTION_CONDREAD = 0x04,
/**
* The operand is conditionally written by the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_CONDWRITE = 0x08,
/* ------------------------------------------------------------------------------------------ */
/* Combined actions */
/* ------------------------------------------------------------------------------------------ */
/**
* The operand is read (must read) and written by the instruction (must write).
*/
ZYDIS_OPERAND_ACTION_READWRITE = ZYDIS_OPERAND_ACTION_READ | ZYDIS_OPERAND_ACTION_WRITE,
/**
* The operand is conditionally read (may read) and conditionally written by
* the instruction (may write).
*/
ZYDIS_OPERAND_ACTION_CONDREAD_CONDWRITE =
ZYDIS_OPERAND_ACTION_CONDREAD | ZYDIS_OPERAND_ACTION_CONDWRITE,
/**
* The operand is read (must read) and conditionally written by the
* instruction (may write).
*/
ZYDIS_OPERAND_ACTION_READ_CONDWRITE =
ZYDIS_OPERAND_ACTION_READ | ZYDIS_OPERAND_ACTION_CONDWRITE,
/**
* The operand is written (must write) and conditionally read by the
* instruction (may read).
*/
ZYDIS_OPERAND_ACTION_CONDREAD_WRITE =
ZYDIS_OPERAND_ACTION_CONDREAD | ZYDIS_OPERAND_ACTION_WRITE,
/**
* Mask combining all reading access flags.
*/
ZYDIS_OPERAND_ACTION_MASK_READ = ZYDIS_OPERAND_ACTION_READ | ZYDIS_OPERAND_ACTION_CONDREAD,
/**
* Mask combining all writing access flags.
*/
ZYDIS_OPERAND_ACTION_MASK_WRITE = ZYDIS_OPERAND_ACTION_WRITE | ZYDIS_OPERAND_ACTION_CONDWRITE,
/* ------------------------------------------------------------------------------------------ */
/**
* The minimum number of bits required to represent all values of this bitset.
*/
ZYDIS_OPERAND_ACTION_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_OPERAND_ACTION_CONDWRITE)
} ZydisOperandAction;
/**
* Defines the `ZydisOperandActions` data-type.
*/
typedef ZyanU8 ZydisOperandActions;
/* ---------------------------------------------------------------------------------------------- */
/* Instruction encoding */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisInstructionEncoding` enum.
*/
typedef enum ZydisInstructionEncoding_
{
/**
* The instruction uses the legacy encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_LEGACY,
/**
* The instruction uses the AMD 3DNow-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_3DNOW,
/**
* The instruction uses the AMD XOP-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_XOP,
/**
* The instruction uses the VEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_VEX,
/**
* The instruction uses the EVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_EVEX,
/**
* The instruction uses the MVEX-encoding.
*/
ZYDIS_INSTRUCTION_ENCODING_MVEX,
/**
* Maximum value of this enum.
*/
ZYDIS_INSTRUCTION_ENCODING_MAX_VALUE = ZYDIS_INSTRUCTION_ENCODING_MVEX,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_INSTRUCTION_ENCODING_REQUIRED_BITS =
ZYAN_BITS_TO_REPRESENT(ZYDIS_INSTRUCTION_ENCODING_MAX_VALUE)
} ZydisInstructionEncoding;
/* ---------------------------------------------------------------------------------------------- */
/* Opcode map */
/* ---------------------------------------------------------------------------------------------- */
/**
* Defines the `ZydisOpcodeMap` enum.
*/
typedef enum ZydisOpcodeMap_
{
ZYDIS_OPCODE_MAP_DEFAULT,
ZYDIS_OPCODE_MAP_0F,
ZYDIS_OPCODE_MAP_0F38,
ZYDIS_OPCODE_MAP_0F3A,
ZYDIS_OPCODE_MAP_0F0F,
ZYDIS_OPCODE_MAP_XOP8,
ZYDIS_OPCODE_MAP_XOP9,
ZYDIS_OPCODE_MAP_XOPA,
/**
* Maximum value of this enum.
*/
ZYDIS_OPCODE_MAP_MAX_VALUE = ZYDIS_OPCODE_MAP_XOPA,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_OPCODE_MAP_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_OPCODE_MAP_MAX_VALUE)
} ZydisOpcodeMap;
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_SHAREDTYPES_H */

View file

@ -0,0 +1,90 @@
/***************************************************************************************************
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
* Defines the immutable and storage-efficient `ZydisShortString` struct, which
* is used to store strings in the generated tables.
*/
#ifndef ZYDIS_SHORTSTRING_H
#define ZYDIS_SHORTSTRING_H
#include <ZydisExportConfig.h>
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
#pragma pack(push, 1)
/**
* Defines the `ZydisShortString` struct.
*
* This compact struct is mainly used for internal string-tables to save up some bytes.
*
* All fields in this struct should be considered as "private". Any changes may lead to unexpected
* behavior.
*/
typedef struct ZydisShortString_
{
/**
* The buffer that contains the actual (null-terminated) string.
*/
const char* data;
/**
* The length (number of characters) of the string (without 0-termination).
*/
ZyanU8 size;
} ZydisShortString;
#pragma pack(pop)
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/**
* Declares a `ZydisShortString` from a static C-style string.
*
* @param string The C-string constant.
*/
#define ZYDIS_MAKE_SHORTSTRING(string) \
{ string, sizeof(string) - 1 }
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_SHORTSTRING_H */

159
externals/zydis/include/Zydis/Status.h vendored Normal file
View file

@ -0,0 +1,159 @@
/***************************************************************************************************
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
* Status code definitions and check macros.
*/
#ifndef ZYDIS_STATUS_H
#define ZYDIS_STATUS_H
#include <Zycore/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Status codes */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Module IDs */
/* ---------------------------------------------------------------------------------------------- */
/**
* The zydis module id.
*/
#define ZYAN_MODULE_ZYDIS 0x002u
/* ---------------------------------------------------------------------------------------------- */
/* Status codes */
/* ---------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------- */
/* Decoder */
/* ---------------------------------------------------------------------------------------------- */
/**
* An attempt was made to read data from an input data-source that has no more
* data available.
*/
#define ZYDIS_STATUS_NO_MORE_DATA \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x00u)
/**
* An general error occured while decoding the current instruction. The
* instruction might be undefined.
*/
#define ZYDIS_STATUS_DECODING_ERROR \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x01u)
/**
* The instruction exceeded the maximum length of 15 bytes.
*/
#define ZYDIS_STATUS_INSTRUCTION_TOO_LONG \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x02u)
/**
* The instruction encoded an invalid register.
*/
#define ZYDIS_STATUS_BAD_REGISTER \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x03u)
/**
* A lock-prefix (F0) was found while decoding an instruction that does not
* support locking.
*/
#define ZYDIS_STATUS_ILLEGAL_LOCK \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x04u)
/**
* A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX
* instruction.
*/
#define ZYDIS_STATUS_ILLEGAL_LEGACY_PFX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x05u)
/**
* A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction.
*/
#define ZYDIS_STATUS_ILLEGAL_REX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x06u)
/**
* An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix.
*/
#define ZYDIS_STATUS_INVALID_MAP \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x07u)
/**
* An error occured while decoding the EVEX-prefix.
*/
#define ZYDIS_STATUS_MALFORMED_EVEX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x08u)
/**
* An error occured while decoding the MVEX-prefix.
*/
#define ZYDIS_STATUS_MALFORMED_MVEX \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x09u)
/**
* An invalid write-mask was specified for an EVEX/MVEX instruction.
*/
#define ZYDIS_STATUS_INVALID_MASK \
ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x0Au)
/* ---------------------------------------------------------------------------------------------- */
/* Formatter */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returning this status code in some specified formatter callbacks will cause
* the formatter to omit the corresponding token.
*
* Valid callbacks:
* - `ZYDIS_FORMATTER_FUNC_PRE_OPERAND`
* - `ZYDIS_FORMATTER_FUNC_POST_OPERAND`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_REG`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_MEM`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_PTR`
* - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_IMM`
*/
#define ZYDIS_STATUS_SKIP_TOKEN \
ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYDIS, 0x0Bu)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_STATUS_H */

275
externals/zydis/include/Zydis/Utils.h vendored Normal file
View file

@ -0,0 +1,275 @@
/***************************************************************************************************
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
* Other utility functions.
*/
#ifndef ZYDIS_UTILS_H
#define ZYDIS_UTILS_H
#include <Zycore/Defines.h>
#include <Zydis/DecoderTypes.h>
#include <Zydis/Status.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT 9
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZydisInstructionSegment` struct.
*/
typedef enum ZydisInstructionSegment_
{
ZYDIS_INSTR_SEGMENT_NONE,
/**
* The legacy prefixes (including ignored `REX` prefixes).
*/
ZYDIS_INSTR_SEGMENT_PREFIXES,
/**
* The effective `REX` prefix byte.
*/
ZYDIS_INSTR_SEGMENT_REX,
/**
* The `XOP` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_XOP,
/**
* The `VEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_VEX,
/**
* The `EVEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_EVEX,
/**
* The `MVEX` prefix bytes.
*/
ZYDIS_INSTR_SEGMENT_MVEX,
/**
* The opcode bytes.
*/
ZYDIS_INSTR_SEGMENT_OPCODE,
/**
* The `ModRM` byte.
*/
ZYDIS_INSTR_SEGMENT_MODRM,
/**
* The `SIB` byte.
*/
ZYDIS_INSTR_SEGMENT_SIB,
/**
* The displacement bytes.
*/
ZYDIS_INSTR_SEGMENT_DISPLACEMENT,
/**
* The immediate bytes.
*/
ZYDIS_INSTR_SEGMENT_IMMEDIATE,
/**
* Maximum value of this enum.
*/
ZYDIS_INSTR_SEGMENT_MAX_VALUE = ZYDIS_INSTR_SEGMENT_IMMEDIATE,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_INSTR_SEGMENT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_INSTR_SEGMENT_MAX_VALUE)
} ZydisInstructionSegment;
/**
* Defines the `ZydisInstructionSegments` struct.
*/
typedef struct ZydisInstructionSegments_
{
/**
* The number of logical instruction segments.
*/
ZyanU8 count;
struct
{
/**
* The type of the segment.
*/
ZydisInstructionSegment type;
/**
* The offset of the segment relative to the start of the instruction (in bytes).
*/
ZyanU8 offset;
/**
* The size of the segment, in bytes.
*/
ZyanU8 size;
} segments[ZYDIS_MAX_INSTRUCTION_SEGMENT_COUNT];
} ZydisInstructionSegments;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup utils Utils
* Miscellaneous utility functions. Address translation and other helpers.
* @{
*/
/* ---------------------------------------------------------------------------------------------- */
/* Address calculation */
/* ---------------------------------------------------------------------------------------------- */
// TODO: Provide a function that works in minimal-mode and does not require a operand parameter
/**
* Calculates the absolute address value for the given instruction operand.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param operand A pointer to the `ZydisDecodedOperand` struct.
* @param runtime_address The runtime address of the instruction.
* @param result_address A pointer to the memory that receives the absolute address.
*
* @return A zyan status code.
*
* You should use this function in the following cases:
* - `IMM` operands with relative address (e.g. `JMP`, `CALL`, ...)
* - `MEM` operands with `RIP`/`EIP`-relative address (e.g. `MOV RAX, [RIP+0x12345678]`)
* - `MEM` operands with absolute address (e.g. `MOV RAX, [0x12345678]`)
* - The displacement needs to get truncated and zero extended
*/
ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address, ZyanU64* result_address);
/**
* Calculates the absolute address value for the given instruction operand.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param operand A pointer to the `ZydisDecodedOperand` struct.
* @param runtime_address The runtime address of the instruction.
* @param register_context A pointer to the `ZydisRegisterContext` struct.
* @param result_address A pointer to the memory that receives the absolute target-address.
*
* @return A zyan status code.
*
* This function behaves like `ZydisCalcAbsoluteAddress` but takes an additional register-context
* argument to allow calculation of addresses depending on runtime register values.
*
* Note that `IP/EIP/RIP` from the register-context will be ignored in favor of the passed
* runtime-address.
*/
ZYDIS_EXPORT ZyanStatus ZydisCalcAbsoluteAddressEx(const ZydisDecodedInstruction* instruction,
const ZydisDecodedOperand* operand, ZyanU64 runtime_address,
const ZydisRegisterContext* register_context, ZyanU64* result_address);
/* ---------------------------------------------------------------------------------------------- */
/* Accessed CPU flags */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns a mask of accessed CPU-flags matching the given `action`.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param action The CPU-flag action.
* @param flags Receives the flag mask.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction,
ZydisCPUFlagAction action, ZydisCPUFlags* flags);
/**
* Returns a mask of accessed CPU-flags that are read (tested) by the current instruction.
*
* DEPRECATED. This function will be removed in the next major release. Please refer to the
* `cpu_flags_read` or `fpu_flags_read` fields of the `ZydisDecodedInstruction` instead.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param flags Receives the flag mask.
*
* @return A zyan status code.
*/
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsRead(
const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
/**
* Returns a mask of accessed CPU-flags that are written (modified, undefined) by the current
* instruction.
*
* DEPRECATED. This function will be removed in the next major release. Please refer to the
* `cpu_flags_written` or `fpu_flags_written` fields of the `ZydisDecodedInstruction` instead.
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param flags Receives the flag mask.
*
* @return A zyan status code.
*/
ZYDIS_DEPRECATED_EXPORT ZyanStatus ZydisGetAccessedFlagsWritten(
const ZydisDecodedInstruction* instruction, ZydisCPUFlags* flags);
/* ---------------------------------------------------------------------------------------------- */
/* Instruction segments */
/* ---------------------------------------------------------------------------------------------- */
/**
* Returns offsets and sizes of all logical instruction segments (e.g. `OPCODE`,
* `MODRM`, ...).
*
* @param instruction A pointer to the `ZydisDecodedInstruction` struct.
* @param segments Receives the instruction segments information.
*
* @return A zyan status code.
*/
ZYDIS_EXPORT ZyanStatus ZydisGetInstructionSegments(const ZydisDecodedInstruction* instruction,
ZydisInstructionSegments* segments);
/* ---------------------------------------------------------------------------------------------- */
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_UTILS_H */

169
externals/zydis/include/Zydis/Zydis.h vendored Normal file
View file

@ -0,0 +1,169 @@
/***************************************************************************************************
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
* Master include file, including everything else.
*/
#ifndef ZYDIS_H
#define ZYDIS_H
#include <Zycore/Defines.h>
#include <Zycore/Types.h>
#ifndef ZYDIS_DISABLE_DECODER
# include <Zydis/Decoder.h>
# include <Zydis/DecoderTypes.h>
#endif
#ifndef ZYDIS_DISABLE_FORMATTER
# include <Zydis/Formatter.h>
#endif
#include <Zydis/MetaInfo.h>
#include <Zydis/Mnemonic.h>
#include <Zydis/Register.h>
#include <Zydis/SharedTypes.h>
#include <Zydis/Status.h>
#include <Zydis/Utils.h>
#ifdef __cplusplus
extern "C" {
#endif
/* ============================================================================================== */
/* Macros */
/* ============================================================================================== */
/* ---------------------------------------------------------------------------------------------- */
/* Constants */
/* ---------------------------------------------------------------------------------------------- */
/**
* A macro that defines the zydis version.
*/
#define ZYDIS_VERSION (ZyanU64)0x0003000100000000
/* ---------------------------------------------------------------------------------------------- */
/* Helper macros */
/* ---------------------------------------------------------------------------------------------- */
/**
* Extracts the major-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_MAJOR(version) (ZyanU16)(((version) & 0xFFFF000000000000) >> 48)
/**
* Extracts the minor-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_MINOR(version) (ZyanU16)(((version) & 0x0000FFFF00000000) >> 32)
/**
* Extracts the patch-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_PATCH(version) (ZyanU16)(((version) & 0x00000000FFFF0000) >> 16)
/**
* Extracts the build-part of the zydis version.
*
* @param version The zydis version value
*/
#define ZYDIS_VERSION_BUILD(version) (ZyanU16)((version) & 0x000000000000FFFF)
/* ---------------------------------------------------------------------------------------------- */
/* ============================================================================================== */
/* Enums and types */
/* ============================================================================================== */
/**
* Defines the `ZydisFeature` enum.
*/
typedef enum ZydisFeature_
{
ZYDIS_FEATURE_DECODER,
ZYDIS_FEATURE_FORMATTER,
ZYDIS_FEATURE_AVX512,
ZYDIS_FEATURE_KNC,
/**
* Maximum value of this enum.
*/
ZYDIS_FEATURE_MAX_VALUE = ZYDIS_FEATURE_KNC,
/**
* The minimum number of bits required to represent all values of this enum.
*/
ZYDIS_FEATURE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_FEATURE_MAX_VALUE)
} ZydisFeature;
/* ============================================================================================== */
/* Exported functions */
/* ============================================================================================== */
/**
* @addtogroup version Version
* Functions for checking the library version and build options.
* @{
*/
/**
* Returns the zydis version.
*
* @return The zydis version.
*
* Use the macros provided in this file to extract the major, minor, patch and build part from the
* returned version value.
*/
ZYDIS_EXPORT ZyanU64 ZydisGetVersion(void);
/**
* Checks, if the specified feature is enabled in the current zydis library instance.
*
* @param feature The feature.
*
* @return `ZYAN_STATUS_TRUE` if the feature is enabled, `ZYAN_STATUS_FALSE` if not. Another
* zyan status code, if an error occured.
*/
ZYDIS_EXPORT ZyanStatus ZydisIsFeatureEnabled(ZydisFeature feature);
/**
* @}
*/
/* ============================================================================================== */
#ifdef __cplusplus
}
#endif
#endif /* ZYDIS_H */