mirror of https://github.com/x64dbg/zydis
Minor refactorings and bugfixes
- Added the `ZYDIS_ATTRIB_HAS_MVEX` attribute - Updated attribute macro values - Changed size of `ZydisDecodeGranularity` from 32-bit to 8-bit
This commit is contained in:
parent
5914abc0be
commit
fec4116ad6
|
@ -48,7 +48,7 @@ extern "C" {
|
|||
/**
|
||||
* @brief Defines the @c ZydisDecodeGranularity datatype.
|
||||
*/
|
||||
typedef uint32_t ZydisDecodeGranularity;
|
||||
typedef uint8_t ZydisDecodeGranularity;
|
||||
|
||||
/**
|
||||
* @brief Decoder modes defining how granular the instruction should be decoded.
|
||||
|
@ -83,7 +83,7 @@ typedef struct ZydisDecoder_
|
|||
{
|
||||
ZydisMachineMode machineMode;
|
||||
ZydisAddressWidth addressWidth;
|
||||
ZydisDecodeGranularity decodeGranularity;
|
||||
ZydisDecodeGranularity granularity;
|
||||
} ZydisDecoder;
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
|
@ -107,15 +107,15 @@ ZYDIS_EXPORT ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMod
|
|||
/**
|
||||
* @brief Initializes the given @c ZydisDecoder instance.
|
||||
*
|
||||
* @param decoder A pointer to the @c ZydisDecoder instance.
|
||||
* @param machineMode The machine mode.
|
||||
* @param addressWidth The address width.
|
||||
* @param decodeGranularity The decode granularity.
|
||||
* @param decoder A pointer to the @c ZydisDecoder instance.
|
||||
* @param machineMode The machine mode.
|
||||
* @param addressWidth The address width.
|
||||
* @param granularity The decode granularity.
|
||||
*
|
||||
* @return A zydis status code.
|
||||
*/
|
||||
ZYDIS_EXPORT ZydisStatus ZydisDecoderInitEx(ZydisDecoder* decoder, ZydisMachineMode machineMode,
|
||||
ZydisAddressWidth addressWidth, ZydisDecodeGranularity decodeGranularity);
|
||||
ZydisAddressWidth addressWidth, ZydisDecodeGranularity granularity);
|
||||
|
||||
/**
|
||||
* @brief Decodes the instruction in the given input @c buffer.
|
||||
|
|
|
@ -177,171 +177,173 @@ typedef struct ZydisDecodedOperand_
|
|||
*/
|
||||
typedef uint64_t ZydisInstructionAttributes;
|
||||
|
||||
// TODO: Update values
|
||||
|
||||
/**
|
||||
* @brief The instruction has the ModRM byte.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_MODRM 0x0000000000000001
|
||||
#define ZYDIS_ATTRIB_HAS_MODRM 0x0000000000000001 // (1 << 0)
|
||||
/**
|
||||
* @brief The instruction has the SUB byte.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SIB 0x0000000000000002
|
||||
#define ZYDIS_ATTRIB_HAS_SIB 0x0000000000000002 // (1 << 1)
|
||||
/**
|
||||
* @brief The instruction has the REX prefix.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REX 0x0000000000000004
|
||||
#define ZYDIS_ATTRIB_HAS_REX 0x0000000000000004 // (1 << 2)
|
||||
/**
|
||||
* @brief The instruction has the XOP prefix.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_XOP 0x0000000000000008
|
||||
#define ZYDIS_ATTRIB_HAS_XOP 0x0000000000000008 // (1 << 3)
|
||||
/**
|
||||
* @brief The instruction has the VEX prefix.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_VEX 0x0000000000000010
|
||||
#define ZYDIS_ATTRIB_HAS_VEX 0x0000000000000010 // (1 << 4)
|
||||
/**
|
||||
* @brief The instruction has the EVEX prefix.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_EVEX 0x0000000000000020
|
||||
#define ZYDIS_ATTRIB_HAS_EVEX 0x0000000000000020 // (1 << 5)
|
||||
/**
|
||||
* @brief The instruction has the MVEX prefix.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_MVEX 0x0000000000000040 // (1 << 6)
|
||||
/**
|
||||
* @brief The instruction has one or more operands with position-relative offsets.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_IS_RELATIVE 0x0000000000000040
|
||||
#define ZYDIS_ATTRIB_IS_RELATIVE 0x0000000000000080 // (1 << 7)
|
||||
/**
|
||||
* @brief The instruction is privileged.
|
||||
*
|
||||
* Priviliged instructions are any instructions that require a current ring level below 3.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_IS_PRIVILEGED 0x0000000000000080
|
||||
#define ZYDIS_ATTRIB_IS_PRIVILEGED 0x0000000000000100 // (1 << 8)
|
||||
/**
|
||||
* @brief The instruction accepts the lock prefix (0xF0).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_LOCK 0x0000000000000100
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_LOCK 0x0000000000000200 // (1 << 9)
|
||||
/**
|
||||
* @brief The instruction accepts the rep prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REP 0x0000000000000200
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REP 0x0000000000000400 // (1 << 10)
|
||||
/**
|
||||
* @brief The instruction accepts the repe/repz prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPE 0x0000000000000400
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPE 0x0000000000000800 // (1 << 11)
|
||||
/**
|
||||
* @brief The instruction accepts the repe/repz prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPZ 0x0000000000000400
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPZ 0x0000000000000800 // (1 << 11)
|
||||
/**
|
||||
* @brief The instruction accepts the repne/repnz prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPNE 0x0000000000000800
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPNE 0x0000000000001000 // (1 << 12)
|
||||
/**
|
||||
* @brief The instruction accepts the repne/repnz prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPNZ 0x0000000000000800
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_REPNZ 0x0000000000001000 // (1 << 12)
|
||||
/**
|
||||
* @brief The instruction accepts the bound prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_BOUND 0x0000000000001000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_BOUND 0x0000000000002000 // (1 << 13)
|
||||
/**
|
||||
* @brief The instruction accepts the xacquire prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_XACQUIRE 0x0000000000002000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_XACQUIRE 0x0000000000004000 // (1 << 14)
|
||||
/**
|
||||
* @brief The instruction accepts the xrelease prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_XRELEASE 0x0000000000004000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_XRELEASE 0x0000000000008000 // (1 << 15)
|
||||
/**
|
||||
* @brief The instruction accepts the xacquire/xrelease prefixes (0xF2, 0xF3) without the
|
||||
* lock-prefix (0x0F).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_HLE_WITHOUT_LOCK 0x0000000000008000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_HLE_WITHOUT_LOCK 0x0000000000010000 // (1 << 16)
|
||||
/**
|
||||
* @brief The instruction accepts branch hints (0x2E, 0x3E).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_BRANCH_HINTS 0x0000000000010000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_BRANCH_HINTS 0x0000000000020000 // (1 << 17)
|
||||
/**
|
||||
* @brief The instruction accepts segment prefixes (0x2E, 0x36, 0x3E, 0x26, 0x64, 0x65).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_SEGMENT 0x0000000000020000
|
||||
#define ZYDIS_ATTRIB_ACCEPTS_SEGMENT 0x0000000000040000 // (1 << 18)
|
||||
/**
|
||||
* @brief The instruction has the lock prefix (0xF0).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_LOCK 0x0000000000100000
|
||||
#define ZYDIS_ATTRIB_HAS_LOCK 0x0000000000080000 // (1 << 19)
|
||||
/**
|
||||
* @brief The instruction has the rep prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REP 0x0000000000200000
|
||||
#define ZYDIS_ATTRIB_HAS_REP 0x0000000000100000 // (1 << 20)
|
||||
/**
|
||||
* @brief The instruction has the repe/repz prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REPE 0x0000000000400000
|
||||
#define ZYDIS_ATTRIB_HAS_REPE 0x0000000000200000 // (1 << 21)
|
||||
/**
|
||||
* @brief The instruction has the repe/repz prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REPZ 0x0000000000400000
|
||||
#define ZYDIS_ATTRIB_HAS_REPZ 0x0000000000200000 // (1 << 21)
|
||||
/**
|
||||
* @brief The instruction has the repne/repnz prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REPNE 0x0000000000800000
|
||||
#define ZYDIS_ATTRIB_HAS_REPNE 0x0000000000400000 // (1 << 22)
|
||||
/**
|
||||
* @brief The instruction has the repne/repnz prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_REPNZ 0x0000000000800000
|
||||
#define ZYDIS_ATTRIB_HAS_REPNZ 0x0000000000400000 // (1 << 22)
|
||||
/**
|
||||
* @brief The instruction has the bound prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_BOUND 0x0000000001000000
|
||||
#define ZYDIS_ATTRIB_HAS_BOUND 0x0000000000800000 // (1 << 23)
|
||||
/**
|
||||
* @brief The instruction has the xacquire prefix (0xF2).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_XACQUIRE 0x0000000002000000
|
||||
#define ZYDIS_ATTRIB_HAS_XACQUIRE 0x0000000001000000 // (1 << 24)
|
||||
/**
|
||||
* @brief The instruction has the xrelease prefix (0xF3).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_XRELEASE 0x0000000004000000
|
||||
#define ZYDIS_ATTRIB_HAS_XRELEASE 0x0000000002000000 // (1 << 25)
|
||||
/**
|
||||
* @brief The instruction has the branch-not-taken hint (0x2E).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN 0x0000000008000000
|
||||
#define ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN 0x0000000004000000 // (1 << 26)
|
||||
/**
|
||||
* @brief The instruction has the branch-taken hint (0x3E).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_BRANCH_TAKEN 0x0000000010000000
|
||||
#define ZYDIS_ATTRIB_HAS_BRANCH_TAKEN 0x0000000008000000 // (1 << 27)
|
||||
/**
|
||||
* @brief The instruction has a segment modifier.
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT 0x00000007E0000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT 0x00000003F0000000
|
||||
/**
|
||||
* @brief The instruction has the CS segment modifier (0x2E).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_CS 0x0000000020000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_CS 0x0000000010000000 // (1 << 28)
|
||||
/**
|
||||
* @brief The instruction has the SS segment modifier (0x36).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_SS 0x0000000040000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_SS 0x0000000020000000 // (1 << 29)
|
||||
/**
|
||||
* @brief The instruction has the DS segment modifier (0x3E).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_DS 0x0000000080000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_DS 0x0000000040000000 // (1 << 30)
|
||||
/**
|
||||
* @brief The instruction has the ES segment modifier (0x26).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_ES 0x0000000100000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_ES 0x0000000080000000 // (1 << 31)
|
||||
/**
|
||||
* @brief The instruction has the FS segment modifier (0x64).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_FS 0x0000000200000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_FS 0x0000000100000000 // (1 << 32)
|
||||
/**
|
||||
* @brief The instruction has the GS segment modifier (0x65).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_GS 0x0000000400000000
|
||||
#define ZYDIS_ATTRIB_HAS_SEGMENT_GS 0x0000000200000000 // (1 << 33)
|
||||
/**
|
||||
* @brief The instruction has the operand-size prefix (0x66).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_OPERANDSIZE 0x0000000800000000
|
||||
#define ZYDIS_ATTRIB_HAS_OPERANDSIZE 0x0000000400000000 // (1 << 34)
|
||||
/**
|
||||
* @brief The instruction has the address-size prefix (0x67).
|
||||
*/
|
||||
#define ZYDIS_ATTRIB_HAS_ADDRESSSIZE 0x0000001000000000
|
||||
#define ZYDIS_ATTRIB_HAS_ADDRESSSIZE 0x0000000800000000 // (1 << 35)
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------- */
|
||||
/* R/E/FLAGS info */
|
||||
|
|
|
@ -592,7 +592,7 @@ static ZydisStatus ZydisDecodeMVEX(ZydisDecoderContext* context,
|
|||
ZYDIS_ASSERT(instruction);
|
||||
ZYDIS_ASSERT(data[0] == 0x62);
|
||||
|
||||
instruction->attributes |= ZYDIS_ATTRIB_HAS_EVEX;
|
||||
instruction->attributes |= ZYDIS_ATTRIB_HAS_MVEX;
|
||||
instruction->raw.mvex.isDecoded = ZYDIS_TRUE;
|
||||
instruction->raw.mvex.data[0] = 0x62;
|
||||
instruction->raw.mvex.data[1] = data[1];
|
||||
|
@ -4282,7 +4282,7 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
|
|||
instruction->meta.isaExt = definition->isaExt;
|
||||
instruction->meta.exceptionClass = definition->exceptionClass;
|
||||
|
||||
if (context->decoder->decodeGranularity == ZYDIS_DECODE_GRANULARITY_FULL)
|
||||
if (context->decoder->granularity == ZYDIS_DECODE_GRANULARITY_FULL)
|
||||
{
|
||||
ZydisSetAttributes(context, instruction, definition);
|
||||
switch (instruction->encoding)
|
||||
|
@ -4328,12 +4328,12 @@ ZydisStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machineMode
|
|||
}
|
||||
|
||||
ZydisStatus ZydisDecoderInitEx(ZydisDecoder* decoder, ZydisMachineMode machineMode,
|
||||
ZydisAddressWidth addressWidth, ZydisDecodeGranularity decodeGranularity)
|
||||
ZydisAddressWidth addressWidth, ZydisDecodeGranularity granularity)
|
||||
{
|
||||
if (!decoder || ((machineMode != 16) && (machineMode != 32) && (machineMode != 64)) ||
|
||||
((decodeGranularity != ZYDIS_DECODE_GRANULARITY_DEFAULT) &&
|
||||
(decodeGranularity != ZYDIS_DECODE_GRANULARITY_MINIMAL) &&
|
||||
(decodeGranularity != ZYDIS_DECODE_GRANULARITY_FULL)))
|
||||
((granularity != ZYDIS_DECODE_GRANULARITY_DEFAULT) &&
|
||||
(granularity != ZYDIS_DECODE_GRANULARITY_MINIMAL) &&
|
||||
(granularity != ZYDIS_DECODE_GRANULARITY_FULL)))
|
||||
{
|
||||
return ZYDIS_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
@ -4350,14 +4350,14 @@ ZydisStatus ZydisDecoderInitEx(ZydisDecoder* decoder, ZydisMachineMode machineMo
|
|||
return ZYDIS_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
if (decodeGranularity == ZYDIS_DECODE_GRANULARITY_DEFAULT)
|
||||
if (granularity == ZYDIS_DECODE_GRANULARITY_DEFAULT)
|
||||
{
|
||||
decodeGranularity = ZYDIS_DECODE_GRANULARITY_FULL;
|
||||
granularity = ZYDIS_DECODE_GRANULARITY_FULL;
|
||||
}
|
||||
|
||||
decoder->machineMode = machineMode;
|
||||
decoder->addressWidth = addressWidth;
|
||||
decoder->decodeGranularity = decodeGranularity;
|
||||
decoder->granularity = granularity;
|
||||
|
||||
return ZYDIS_STATUS_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue