Minor refactorings

- Adjusted datatype of some enums
- Renamed some things
  - `ZydisDecodedInstruction.flags` -> `ZydisDecodedInstruction.accessedFlags`
  - `ZydisDecodedInstruction.meta.roundingMode` -> `ZydisDecodedInstruction.meta.rounding.mode`
  - `ZydisDecodedInstruction.meta.swizzleMode` -> `ZydisDecodedInstruction.meta.swizzle.mode`
  - `ZydisDecodedInstruction.meta.conversionMode` -> `ZydisDecodedInstruction.meta.conversion.mode`
  - `ZydisGetCPUFlagsByAction` -> `ZydisGetAccessedFlagsByAction`
This commit is contained in:
flobernd 2017-09-10 21:43:52 +02:00
parent 5d6c58ad1c
commit 01b8267d47
14 changed files with 91 additions and 73 deletions

View File

@ -480,7 +480,7 @@ enum ZydisCPUFlagActions
/**
* @brief Defines the @c ZydisExceptionClass datatype.
*/
typedef uint16_t ZydisExceptionClass;
typedef uint8_t ZydisExceptionClass;
/**
* @brief Values that represent exception-classes.
@ -583,7 +583,7 @@ enum ZydisMaskModes
/**
* @brief Defines the @c ZydisBroadcastMode datatype.
*/
typedef uint16_t ZydisBroadcastMode;
typedef uint8_t ZydisBroadcastMode;
/**
* @brief Values that represent AVX broadcast-modes.
@ -645,7 +645,7 @@ enum ZydisRoundingModes
/**
* @brief Defines the @c ZydisSwizzleMode datatype.
*/
typedef uint16_t ZydisSwizzleMode;
typedef uint8_t ZydisSwizzleMode;
/**
* @brief Values that represent swizzle-modes.
@ -670,7 +670,7 @@ enum ZydisSwizzleModes
/**
* @brief Defines the @c ZydisConversionMode datatype.
*/
typedef uint16_t ZydisConversionMode;
typedef uint8_t ZydisConversionMode;
/**
* @brief Values that represent conversion-modes.
@ -766,11 +766,11 @@ typedef struct ZydisDecodedInstruction_
/**
* @brief The CPU-flag action.
*
* You can call `ZydisGetCPUFlagsByAction` to get a mask with all flags matching a specific
* action.
* You can call `ZydisGetAccessedFlagsByAction` to get a mask with all flags matching a
* specific action.
*/
ZydisCPUFlagAction action;
} flags[ZYDIS_CPUFLAG_ENUM_COUNT];
} accessedFlags[ZYDIS_CPUFLAG_ENUM_COUNT];
/**
* @brief Extended info for AVX instructions.
*/
@ -799,7 +799,7 @@ typedef struct ZydisDecodedInstruction_
ZydisBool isControlMask;
} mask;
/**
* @brief Contains info about the AVX broadcast-factor.
* @brief Contains info about the AVX broadcast.
*/
struct
{
@ -816,17 +816,35 @@ typedef struct ZydisDecodedInstruction_
ZydisBroadcastMode mode;
} broadcast;
/**
* @brief The AVX rounding-mode.
* @brief Contains info about the AVX rounding.
*/
ZydisRoundingMode roundingMode;
struct
{
/**
* @brief The AVX rounding-mode.
*/
ZydisRoundingMode mode;
} rounding;
/**
* @brief The AVX register-swizzle mode (MVEX only).
* @brief Contains info about the AVX register-swizzle (MVEX only).
*/
ZydisSwizzleMode swizzleMode;
struct
{
/**
* @brief The AVX register-swizzle mode (MVEX only).
*/
ZydisSwizzleMode mode;
} swizzle;
/**
* @brief The AVX data-conversion mode (MVEX only).
* @brief Contains info about the AVX data-conversion (MVEX only).
*/
ZydisConversionMode conversionMode;
struct
{
/**
* @brief The AVX data-conversion mode (MVEX only).
*/
ZydisConversionMode mode;
} conversion;
/**
* @brief Signals, if the sae functionality is enabled for the instruction.
*/

View File

@ -1,3 +1,5 @@
typedef uint8_t ZydisISAExt;
enum ZydisISAExts
{
ZYDIS_ISA_EXT_INVALID,

View File

@ -1,3 +1,5 @@
typedef uint8_t ZydisISASet;
enum ZydisISASets
{
ZYDIS_ISA_SET_INVALID,

View File

@ -1,4 +1,6 @@
enum ZydisCategories
typedef uint8_t ZydisInstructionCategory;
enum ZydisInstructionCategories
{
ZYDIS_CATEGORY_INVALID,
ZYDIS_CATEGORY_AES,

View File

@ -1,3 +1,5 @@
typedef uint16_t ZydisMnemonic;
enum ZydisMnemonics
{
ZYDIS_MNEMONIC_INVALID,

View File

@ -46,22 +46,16 @@ extern "C" {
/**
* @brief Defines the @c ZydisInstructionCategory datatype.
*/
typedef uint16_t ZydisInstructionCategory;
#include <Zydis/Generated/EnumCategory.h>
#include <Zydis/Generated/EnumInstructionCategory.h>
/**
* @brief Defines the @c ZydisISASet datatype.
*/
typedef uint16_t ZydisISASet;
#include <Zydis/Generated/EnumISASet.h>
/**
* @brief Defines the @c ZydisISAExt datatype.
*/
typedef uint16_t ZydisISAExt;
#include <Zydis/Generated/EnumISAExt.h>
/* ============================================================================================== */

View File

@ -46,8 +46,6 @@ extern "C" {
/**
* @brief Defines the @c ZydisMnemonic datatype.
*/
typedef uint16_t ZydisMnemonic;
#include <Zydis/Generated/EnumMnemonic.h>
/* ============================================================================================== */

View File

@ -62,7 +62,7 @@ ZYDIS_EXPORT ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(
/* ============================================================================================== */
/**
* @brief Returns a mask of CPU-flags matching the given `action`.
* @brief Returns a mask of accessed CPU-flags matching the given `action`.
*
* @param instruction A pointer to the @c ZydisDecodedInstruction struct.
* @param action The CPU-flag action.
@ -70,7 +70,7 @@ ZYDIS_EXPORT ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(
*
* @return A zydis status code
*/
ZYDIS_EXPORT ZydisStatus ZydisGetCPUFlagsByAction(const ZydisDecodedInstruction* instruction,
ZYDIS_EXPORT ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction,
ZydisCPUFlagAction action, ZydisCPUFlagMask* flags);
/* ============================================================================================== */

View File

@ -1153,7 +1153,7 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context,
ZYDIS_ASSERT(definition->elementType == ZYDIS_IELEMENT_TYPE_VARIABLE);
ZYDIS_ASSERT(instruction->avx.vectorLength == 512);
switch (instruction->avx.conversionMode)
switch (instruction->avx.conversion.mode)
{
case ZYDIS_CONVERSION_MODE_INVALID:
operand->size = 512;
@ -2205,7 +2205,7 @@ static void ZydisSetAccessedFlags(ZydisDecodedInstruction* instruction,
ZYDIS_ASSERT(ZYDIS_ARRAY_SIZE(instruction->flags) == ZYDIS_ARRAY_SIZE(flags->action));
memcpy(&instruction->flags, &flags->action, ZYDIS_ARRAY_SIZE(flags->action));
memcpy(&instruction->accessedFlags, &flags->action, ZYDIS_ARRAY_SIZE(flags->action));
}
/**
@ -2681,7 +2681,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
// Noting to do here
break;
case ZYDIS_EVEX_FUNC_RC:
instruction->avx.roundingMode = ZYDIS_ROUNDING_MODE_RN + context->cache.LL;
instruction->avx.rounding.mode = ZYDIS_ROUNDING_MODE_RN + context->cache.LL;
// Intentional fallthrough
case ZYDIS_EVEX_FUNC_SAE:
instruction->avx.hasSAE = ZYDIS_TRUE;
@ -2838,7 +2838,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
// Nothing to do here
break;
case ZYDIS_MVEX_FUNC_RC:
instruction->avx.roundingMode = ZYDIS_ROUNDING_MODE_RN + instruction->raw.mvex.SSS;
instruction->avx.rounding.mode = ZYDIS_ROUNDING_MODE_RN + instruction->raw.mvex.SSS;
break;
case ZYDIS_MVEX_FUNC_SAE:
if (instruction->raw.mvex.SSS >= 4)
@ -2848,7 +2848,7 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
break;
case ZYDIS_MVEX_FUNC_SWIZZLE_32:
case ZYDIS_MVEX_FUNC_SWIZZLE_64:
instruction->avx.swizzleMode = ZYDIS_SWIZZLE_MODE_DCBA + instruction->raw.mvex.SSS;
instruction->avx.swizzle.mode = ZYDIS_SWIZZLE_MODE_DCBA + instruction->raw.mvex.SSS;
break;
case ZYDIS_MVEX_FUNC_SF_32:
case ZYDIS_MVEX_FUNC_SF_32_BCST:
@ -2864,19 +2864,19 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16;
break;
case 3:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_FLOAT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_FLOAT16;
break;
case 4:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8;
break;
case 5:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8;
break;
case 6:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16;
break;
case 7:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16;
break;
default:
ZYDIS_UNREACHABLE;
@ -2896,16 +2896,16 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
instruction->avx.broadcast.mode = ZYDIS_BROADCAST_MODE_4_TO_16;
break;
case 4:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8;
break;
case 5:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8;
break;
case 6:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16;
break;
case 7:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16;
break;
default:
ZYDIS_UNREACHABLE;
@ -2934,19 +2934,19 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
case 0:
break;
case 3:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_FLOAT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_FLOAT16;
break;
case 4:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8;
break;
case 5:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8;
break;
case 6:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16;
break;
case 7:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16;
break;
default:
ZYDIS_UNREACHABLE;
@ -2962,16 +2962,16 @@ static void ZydisSetAVXInformation(ZydisDecoderContext* context,
case 0:
break;
case 4:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT8;
break;
case 5:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT8;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT8;
break;
case 6:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_UINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_UINT16;
break;
case 7:
instruction->avx.conversionMode = ZYDIS_CONVERSION_MODE_SINT16;
instruction->avx.conversion.mode = ZYDIS_CONVERSION_MODE_SINT16;
break;
default:
ZYDIS_UNREACHABLE;

View File

@ -728,7 +728,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisFormatter* forma
case ZYDIS_DECORATOR_TYPE_ROUNDING_CONTROL:
if (instruction->avx.hasSAE)
{
switch (instruction->avx.roundingMode)
switch (instruction->avx.rounding.mode)
{
case ZYDIS_ROUNDING_MODE_INVALID:
break;
@ -753,7 +753,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisFormatter* forma
}
} else
{
switch (instruction->avx.roundingMode)
switch (instruction->avx.rounding.mode)
{
case ZYDIS_ROUNDING_MODE_INVALID:
break;
@ -779,14 +779,14 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisFormatter* forma
}
break;
case ZYDIS_DECORATOR_TYPE_SAE:
if (instruction->avx.hasSAE && !instruction->avx.roundingMode)
if (instruction->avx.hasSAE && !instruction->avx.rounding.mode)
{
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer,
ZYDIS_STRBUF_APPEND_MODE_DEFAULT, " {sae}"));
}
break;
case ZYDIS_DECORATOR_TYPE_SWIZZLE:
switch (instruction->avx.swizzleMode)
switch (instruction->avx.swizzle.mode)
{
case ZYDIS_SWIZZLE_MODE_INVALID:
case ZYDIS_SWIZZLE_MODE_DCBA:
@ -825,7 +825,7 @@ static ZydisStatus ZydisFormatterPrintDecoratorIntel(const ZydisFormatter* forma
}
break;
case ZYDIS_DECORATOR_TYPE_CONVERSION:
switch (instruction->avx.conversionMode)
switch (instruction->avx.conversion.mode)
{
case ZYDIS_CONVERSION_MODE_INVALID:
break;

View File

@ -1,4 +1,4 @@
static const char* zydisCategoryStrings[] =
static const char* zydisInstructionCategoryStrings[] =
{
"INVALID",
"AES",

View File

@ -30,7 +30,7 @@
/* Enum strings */
/* ============================================================================================== */
#include <Generated/EnumCategoryStrings.inc>
#include <Generated/EnumInstructionCategoryStrings.inc>
#include <Generated/EnumISASetStrings.inc>
#include <Generated/EnumISAExtStrings.inc>
@ -40,11 +40,11 @@
const char* ZydisCategoryGetString(ZydisInstructionCategory category)
{
if (category > ZYDIS_ARRAY_SIZE(zydisCategoryStrings) - 1)
if (category > ZYDIS_ARRAY_SIZE(zydisInstructionCategoryStrings) - 1)
{
return NULL;
}
return zydisCategoryStrings[category];
return zydisInstructionCategoryStrings[category];
}
const char* ZydisISASetGetString(ZydisISASet isaSet)

View File

@ -97,7 +97,7 @@ ZydisStatus ZydisUtilsCalcAbsoluteTargetAddress(const ZydisDecodedInstruction* i
/* Exported functions */
/* ---------------------------------------------------------------------------------------------- */
ZydisStatus ZydisGetCPUFlagsByAction(const ZydisDecodedInstruction* instruction,
ZydisStatus ZydisGetAccessedFlagsByAction(const ZydisDecodedInstruction* instruction,
ZydisCPUFlagAction action, ZydisCPUFlagMask* flags)
{
if (!instruction)
@ -105,9 +105,9 @@ ZydisStatus ZydisGetCPUFlagsByAction(const ZydisDecodedInstruction* instruction,
return ZYDIS_STATUS_INVALID_PARAMETER;
}
*flags = 0;
for (uint8_t i = 0; i < ZYDIS_ARRAY_SIZE(instruction->flags); ++i)
for (uint8_t i = 0; i < ZYDIS_ARRAY_SIZE(instruction->accessedFlags); ++i)
{
if (instruction->flags[i].action == action)
if (instruction->accessedFlags[i].action == action)
{
*flags |= (1 << i);
}

View File

@ -251,30 +251,30 @@ void printFlags(ZydisDecodedInstruction* instruction)
fputs("=======================================\n", stdout);
printf(" ACTIONS: ");
uint8_t c = 0;
for (ZydisCPUFlag i = 0; i < ZYDIS_ARRAY_SIZE(instruction->flags); ++i)
for (ZydisCPUFlag i = 0; i < ZYDIS_ARRAY_SIZE(instruction->accessedFlags); ++i)
{
if (instruction->flags[i].action != ZYDIS_CPUFLAG_ACTION_NONE)
if (instruction->accessedFlags[i].action != ZYDIS_CPUFLAG_ACTION_NONE)
{
if (c && (c % 8 == 0))
{
printf("\n ");
}
++c;
printf("[%-4s: %s] ", flagNames[i], flagActions[instruction->flags[i].action]);
printf("[%-4s: %s] ", flagNames[i], flagActions[instruction->accessedFlags[i].action]);
}
}
puts(c ? "" : "none");
ZydisCPUFlagMask flags, temp;
ZydisGetCPUFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_TESTED, &flags);
ZydisGetAccessedFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_TESTED, &flags);
printf(" READ: 0x%08" PRIX32 "\n", flags);
ZydisGetCPUFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_MODIFIED, &flags);
ZydisGetCPUFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_SET_0, &temp);
ZydisGetAccessedFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_MODIFIED, &flags);
ZydisGetAccessedFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_SET_0, &temp);
flags |= temp;
ZydisGetCPUFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_SET_1, &temp);
ZydisGetAccessedFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_SET_1, &temp);
flags |= temp;
printf(" WRITTEN: 0x%08" PRIX32 "\n", flags);
ZydisGetCPUFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_UNDEFINED, &flags);
ZydisGetAccessedFlagsByAction(instruction, ZYDIS_CPUFLAG_ACTION_UNDEFINED, &flags);
printf(" UNDEFINED: 0x%08" PRIX32 "\n", flags);
}
@ -346,19 +346,19 @@ void printAVXInfo(ZydisDecodedInstruction* instruction)
switch (instruction->encoding)
{
case ZYDIS_INSTRUCTION_ENCODING_EVEX:
printf("\n ROUNDING: %s", roundingModeStrings[instruction->avx.roundingMode]);
printf("\n ROUNDING: %s", roundingModeStrings[instruction->avx.rounding.mode]);
printf("\n SAE: %s", instruction->avx.hasSAE ? "Y" : "N");
printf("\n MASK: %s [%5s]%s", ZydisRegisterGetString(instruction->avx.mask.reg),
maskModeStrings[instruction->avx.mask.mode],
instruction->avx.mask.isControlMask ? " (control-mask)" : "");
break;
case ZYDIS_INSTRUCTION_ENCODING_MVEX:
printf("\n ROUNDING: %s", roundingModeStrings[instruction->avx.roundingMode]);
printf("\n ROUNDING: %s", roundingModeStrings[instruction->avx.rounding.mode]);
printf("\n SAE: %s", instruction->avx.hasSAE ? "Y" : "N");
printf("\n MASK: %s [MERGE]", ZydisRegisterGetString(instruction->avx.mask.reg));
printf("\n EH: %s", instruction->avx.hasEvictionHint ? "Y" : "N");
printf("\n SWIZZLE: %s", swizzleModeStrings[instruction->avx.swizzleMode]);
printf("\n CONVERT: %s", conversionModeStrings[instruction->avx.conversionMode]);
printf("\n SWIZZLE: %s", swizzleModeStrings[instruction->avx.swizzle.mode]);
printf("\n CONVERT: %s", conversionModeStrings[instruction->avx.conversion.mode]);
break;
default:
break;