Fixed and refactored some enums

- Fixed `ZydisRegister` enum and string-table
- Renamed `ZYDIS_XXX_MAX_BITS` in `ZYDIS_XXX_MIN_BITS`
This commit is contained in:
flobernd 2017-12-03 18:36:43 +01:00 committed by Joel Höner
parent 043b1f5a5a
commit 451d7fb1a8
7 changed files with 53 additions and 65 deletions

View File

@ -148,8 +148,7 @@ enum ZydisISAExts
ZYDIS_ISA_EXT_XSAVE,
ZYDIS_ISA_EXT_XSAVEC,
ZYDIS_ISA_EXT_XSAVEOPT,
ZYDIS_ISA_EXT_XSAVES
ZYDIS_ISA_EXT_XSAVES,
ZYDIS_ISA_EXT_MAX_VALUE = ZYDIS_ISA_EXT_XSAVES,
ZYDIS_ISA_EXT_MIN_BITS = 0x0008
};
#define ZYDIS_ISA_EXT_MAX_VALUE ZYDIS_ISA_EXT_XSAVES
#define ZYDIS_ISA_EXT_MAX_BITS 0x0008

View File

@ -71,8 +71,7 @@ enum ZydisISASets
ZYDIS_ISA_SET_XSAVE,
ZYDIS_ISA_SET_XSAVEC,
ZYDIS_ISA_SET_XSAVEOPT,
ZYDIS_ISA_SET_XSAVES
ZYDIS_ISA_SET_XSAVES,
ZYDIS_ISA_SET_MAX_VALUE = ZYDIS_ISA_SET_XSAVES,
ZYDIS_ISA_SET_MIN_BITS = 0x0006
};
#define ZYDIS_ISA_SET_MAX_VALUE ZYDIS_ISA_SET_XSAVES
#define ZYDIS_ISA_SET_MAX_BITS 0x0006

View File

@ -98,8 +98,7 @@ enum ZydisInstructionCategories
ZYDIS_CATEGORY_X87_ALU,
ZYDIS_CATEGORY_XOP,
ZYDIS_CATEGORY_XSAVE,
ZYDIS_CATEGORY_XSAVEOPT
ZYDIS_CATEGORY_XSAVEOPT,
ZYDIS_CATEGORY_MAX_VALUE = ZYDIS_CATEGORY_XSAVEOPT,
ZYDIS_CATEGORY_MIN_BITS = 0x0007
};
#define ZYDIS_CATEGORY_MAX_VALUE ZYDIS_CATEGORY_XSAVEOPT
#define ZYDIS_CATEGORY_MAX_BITS 0x0007

View File

@ -1582,8 +1582,7 @@ enum ZydisMnemonics
ZYDIS_MNEMONIC_XSAVES,
ZYDIS_MNEMONIC_XSAVES64,
ZYDIS_MNEMONIC_XSETBV,
ZYDIS_MNEMONIC_XTEST
ZYDIS_MNEMONIC_XTEST,
ZYDIS_MNEMONIC_MAX_VALUE = ZYDIS_MNEMONIC_XTEST,
ZYDIS_MNEMONIC_MIN_BITS = 0x000B
};
#define ZYDIS_MNEMONIC_MAX_VALUE ZYDIS_MNEMONIC_XTEST
#define ZYDIS_MNEMONIC_MAX_BITS 0x000B

View File

@ -147,7 +147,7 @@ typedef struct ZydisOperandDefinition_
ZydisU8 type ZYDIS_BITFIELD(3);
union
{
ZydisRegister reg;
ZydisRegister reg ZYDIS_BITFIELD(ZYDIS_REGISTER_MIN_BITS);
ZydisU8 id ZYDIS_BITFIELD(6);
} reg;
} reg;
@ -543,16 +543,16 @@ enum ZydisMaskPolicies
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZydisMnemonic mnemonic ZYDIS_BITFIELD(ZYDIS_MNEMONIC_MAX_BITS); \
ZydisMnemonic mnemonic ZYDIS_BITFIELD(ZYDIS_MNEMONIC_MIN_BITS); \
ZydisU8 operandCount ZYDIS_BITFIELD( 4); \
ZydisU16 operandReference ZYDIS_BITFIELD(15); \
ZydisU8 operandSizeMap ZYDIS_BITFIELD( 3); \
ZydisU8 flagsReference ZYDIS_BITFIELD( 7); \
ZydisBool requiresProtectedMode ZYDIS_BITFIELD( 1); \
ZydisBool acceptsAddressSizeOverride ZYDIS_BITFIELD( 1); \
ZydisInstructionCategory category ZYDIS_BITFIELD(ZYDIS_CATEGORY_MAX_BITS); \
ZydisISASet isaSet ZYDIS_BITFIELD(ZYDIS_ISA_SET_MAX_BITS); \
ZydisISAExt isaExt ZYDIS_BITFIELD(ZYDIS_ISA_EXT_MAX_BITS); \
ZydisInstructionCategory category ZYDIS_BITFIELD(ZYDIS_CATEGORY_MIN_BITS); \
ZydisISASet isaSet ZYDIS_BITFIELD(ZYDIS_ISA_SET_MIN_BITS); \
ZydisISAExt isaExt ZYDIS_BITFIELD(ZYDIS_ISA_EXT_MIN_BITS); \
ZydisExceptionClass exceptionClass ZYDIS_BITFIELD( 6)
#define ZYDIS_INSTRUCTION_DEFINITION_BASE_VECTOR \

View File

@ -59,6 +59,7 @@ typedef ZydisU8 ZydisRegister;
enum ZydisRegisters
{
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,
@ -86,24 +87,6 @@ enum ZydisRegisters
// 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 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,
// 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 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,
@ -113,12 +96,28 @@ enum ZydisRegisters
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,
// Flags registers
ZYDIS_REGISTER_RFLAGS, ZYDIS_REGISTER_EFLAGS, ZYDIS_REGISTER_FLAGS,
// Instruction-pointer registers
ZYDIS_REGISTER_RIP, ZYDIS_REGISTER_EIP, ZYDIS_REGISTER_IP,
// Special registers
ZYDIS_REGISTER_MXCSR, ZYDIS_REGISTER_PKRU, ZYDIS_REGISTER_XCR0,
ZYDIS_REGISTER_FLAGS, ZYDIS_REGISTER_EFLAGS, ZYDIS_REGISTER_RFLAGS,
// IP 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,
@ -143,15 +142,17 @@ enum ZydisRegisters
// Bound registers
ZYDIS_REGISTER_BND0, ZYDIS_REGISTER_BND1, ZYDIS_REGISTER_BND2, ZYDIS_REGISTER_BND3,
ZYDIS_REGISTER_BNDCFG, ZYDIS_REGISTER_BNDSTATUS,
// Misc registers
ZYDIS_REGISTER_MXCSR, ZYDIS_REGISTER_PKRU, ZYDIS_REGISTER_XCR0,
/**
* @brief Maximum value of this enum.
*/
ZYDIS_REGISTER_MAX_VALUE = ZYDIS_REGISTER_BNDSTATUS,
ZYDIS_REGISTER_MAX_VALUE = ZYDIS_REGISTER_XCR0,
/**
* @brief Maximum amount of bits occupied by an integer from this enum.
* @brief Minimum amount of bits required to store a value of this enum.
*/
ZYDIS_REGISTER_MAX_BITS = 8
ZYDIS_REGISTER_MIN_BITS = 0x0008
};
/* ---------------------------------------------------------------------------------------------- */

View File

@ -71,16 +71,6 @@ static const ZydisStaticString registerStrings[] =
ZYDIS_MAKE_STATIC_STRING("r10"), ZYDIS_MAKE_STATIC_STRING("r11"),
ZYDIS_MAKE_STATIC_STRING("r12"), ZYDIS_MAKE_STATIC_STRING("r13"),
ZYDIS_MAKE_STATIC_STRING("r14"), ZYDIS_MAKE_STATIC_STRING("r15"),
// Address-size scaling general purpose pseudo-registers
ZYDIS_MAKE_STATIC_STRING("aszax"), ZYDIS_MAKE_STATIC_STRING("aszcx"),
ZYDIS_MAKE_STATIC_STRING("aszdx"), ZYDIS_MAKE_STATIC_STRING("aszbx"),
ZYDIS_MAKE_STATIC_STRING("aszsp"), ZYDIS_MAKE_STATIC_STRING("aszbp"),
ZYDIS_MAKE_STATIC_STRING("aszsi"), ZYDIS_MAKE_STATIC_STRING("aszdi"),
// Stack-size scaling general purpose pseudo-registers
ZYDIS_MAKE_STATIC_STRING("sszax"), ZYDIS_MAKE_STATIC_STRING("sszcx"),
ZYDIS_MAKE_STATIC_STRING("sszdx"), ZYDIS_MAKE_STATIC_STRING("sszbx"),
ZYDIS_MAKE_STATIC_STRING("sszsp"), ZYDIS_MAKE_STATIC_STRING("sszbp"),
ZYDIS_MAKE_STATIC_STRING("sszsi"), ZYDIS_MAKE_STATIC_STRING("sszdi"),
// Floating point legacy registers
ZYDIS_MAKE_STATIC_STRING("st0"), ZYDIS_MAKE_STATIC_STRING("st1"),
ZYDIS_MAKE_STATIC_STRING("st2"), ZYDIS_MAKE_STATIC_STRING("st3"),
@ -149,9 +139,12 @@ static const ZydisStaticString registerStrings[] =
ZYDIS_MAKE_STATIC_STRING("ip"), ZYDIS_MAKE_STATIC_STRING("eip"),
ZYDIS_MAKE_STATIC_STRING("rip"),
// Segment registers
ZYDIS_MAKE_STATIC_STRING("es"), ZYDIS_MAKE_STATIC_STRING("ss"),
ZYDIS_MAKE_STATIC_STRING("cs"), ZYDIS_MAKE_STATIC_STRING("ds"),
ZYDIS_MAKE_STATIC_STRING("es"), ZYDIS_MAKE_STATIC_STRING("cs"),
ZYDIS_MAKE_STATIC_STRING("ss"), ZYDIS_MAKE_STATIC_STRING("ds"),
ZYDIS_MAKE_STATIC_STRING("fs"), ZYDIS_MAKE_STATIC_STRING("gs"),
// Table registers
ZYDIS_MAKE_STATIC_STRING("gdtr"), ZYDIS_MAKE_STATIC_STRING("ldtr"),
ZYDIS_MAKE_STATIC_STRING("idtr"), ZYDIS_MAKE_STATIC_STRING("tr"),
// Test registers
ZYDIS_MAKE_STATIC_STRING("tr0"), ZYDIS_MAKE_STATIC_STRING("tr1"),
ZYDIS_MAKE_STATIC_STRING("tr2"), ZYDIS_MAKE_STATIC_STRING("tr3"),
@ -183,12 +176,10 @@ static const ZydisStaticString registerStrings[] =
// Bound registers
ZYDIS_MAKE_STATIC_STRING("bnd0"), ZYDIS_MAKE_STATIC_STRING("bnd1"),
ZYDIS_MAKE_STATIC_STRING("bnd2"), ZYDIS_MAKE_STATIC_STRING("bnd3"),
ZYDIS_MAKE_STATIC_STRING("bndcfg"), ZYDIS_MAKE_STATIC_STRING("bndstatus"),
// Misc registers
ZYDIS_MAKE_STATIC_STRING("mxcsr"), ZYDIS_MAKE_STATIC_STRING("pkru"),
ZYDIS_MAKE_STATIC_STRING("xcr0"), ZYDIS_MAKE_STATIC_STRING("gdtr"),
ZYDIS_MAKE_STATIC_STRING("ldtr"), ZYDIS_MAKE_STATIC_STRING("idtr"),
ZYDIS_MAKE_STATIC_STRING("tr"), ZYDIS_MAKE_STATIC_STRING("bndcfg"),
ZYDIS_MAKE_STATIC_STRING("bndstatus")
ZYDIS_MAKE_STATIC_STRING("xcr0")
};
/* ============================================================================================== */
@ -342,7 +333,7 @@ ZydisRegisterWidth ZydisRegisterGetWidth64(ZydisRegister reg)
const char* ZydisRegisterGetString(ZydisRegister reg)
{
if (reg > (sizeof(registerStrings) / sizeof(registerStrings[0])) - 1)
if (reg >= ZYDIS_ARRAY_SIZE(registerStrings))
{
return ZYDIS_NULL;
}
@ -351,7 +342,7 @@ const char* ZydisRegisterGetString(ZydisRegister reg)
const ZydisStaticString* ZydisRegisterGetStaticString(ZydisRegister reg)
{
if (reg > (sizeof(registerStrings) / sizeof(registerStrings[0])) - 1)
if (reg >= ZYDIS_ARRAY_SIZE(registerStrings))
{
return ZYDIS_NULL;
}