Refactorings

This commit is contained in:
flobernd 2017-07-05 13:33:59 +02:00
parent f73539ede1
commit 34a0572948
7 changed files with 59 additions and 58 deletions

View File

@ -885,7 +885,7 @@ typedef struct ZydisDecodedInstruction_
/**
* @brief The instruction-mnemonic.
*/
ZydisInstructionMnemonic mnemonic;
ZydisMnemonic mnemonic;
/**
* @brief The length of the decoded instruction.
*/

View File

@ -39,9 +39,9 @@ extern "C" {
/* ============================================================================================== */
/**
* @brief Defines the @c ZydisInstructionMnemonic datatype.
* @brief Defines the @c ZydisMnemonic datatype.
*/
typedef uint16_t ZydisInstructionMnemonic;
typedef uint16_t ZydisMnemonic;
#include <Zydis/Generated/MnemonicDefines.h>
@ -56,7 +56,7 @@ typedef uint16_t ZydisInstructionMnemonic;
*
* @return The instruction mnemonic string or @c NULL, if an invalid mnemonic was passed.
*/
ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisInstructionMnemonic mnemonic);
ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic);
/* ============================================================================================== */

View File

@ -3143,13 +3143,13 @@ static ZydisStatus ZydisCollectOptionalPrefixes(ZydisDecoderContext* context,
* @return A zydis status code.
*/
static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
ZydisDecodedInstruction* instruction, const ZydisInstructionParts* optionalParts)
ZydisDecodedInstruction* instruction, const ZydisPhysicalInstructionInfo* info)
{
ZYDIS_ASSERT(context);
ZYDIS_ASSERT(instruction);
ZYDIS_ASSERT(optionalParts);
ZYDIS_ASSERT(info);
if (optionalParts->flags & ZYDIS_INSTRPART_FLAG_HAS_MODRM)
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_MODRM)
{
if (!instruction->raw.modrm.isDecoded)
{
@ -3159,7 +3159,7 @@ static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
}
uint8_t hasSIB = 0;
uint8_t displacementSize = 0;
if (!(optionalParts->flags & ZYDIS_INSTRPART_FLAG_FORCE_REG_FORM))
if (!(info->flags & ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM))
{
switch (instruction->addressWidth)
{
@ -3231,29 +3231,27 @@ static ZydisStatus ZydisDecodeInstructionPhysical(ZydisDecoderContext* context,
}
}
if (optionalParts->flags & ZYDIS_INSTRPART_FLAG_HAS_DISP)
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_DISP)
{
ZYDIS_CHECK(ZydisReadDisplacement(
context, instruction, optionalParts->disp.size[context->easzIndex]));
context, instruction, info->disp.size[context->easzIndex]));
}
if (optionalParts->flags & ZYDIS_INSTRPART_FLAG_HAS_IMM0)
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_IMM0)
{
if (optionalParts->imm[0].isRelative)
if (info->imm[0].isRelative)
{
instruction->attributes |= ZYDIS_ATTRIB_IS_RELATIVE;
}
ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 0,
optionalParts->imm[0].size[context->eoszIndex],
optionalParts->imm[0].isSigned, optionalParts->imm[0].isRelative));
info->imm[0].size[context->eoszIndex], info->imm[0].isSigned, info->imm[0].isRelative));
}
if (optionalParts->flags & ZYDIS_INSTRPART_FLAG_HAS_IMM1)
if (info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_IMM1)
{
ZYDIS_ASSERT(!(optionalParts->flags & ZYDIS_INSTRPART_FLAG_HAS_DISP));
ZYDIS_ASSERT(!(info->flags & ZYDIS_PHYSINSTR_FLAG_HAS_DISP));
ZYDIS_CHECK(ZydisReadImmediate(context, instruction, 1,
optionalParts->imm[1].size[context->eoszIndex],
optionalParts->imm[1].isSigned, optionalParts->imm[1].isRelative));
info->imm[1].size[context->eoszIndex], info->imm[1].isSigned, info->imm[1].isRelative));
}
return ZYDIS_STATUS_SUCCESS;
@ -4266,9 +4264,9 @@ static ZydisStatus ZydisDecodeInstruction(ZydisDecoderContext* context,
ZydisSetEffectiveOperandSize(context, instruction, definition);
ZydisSetEffectiveAddressWidth(context, instruction);
const ZydisInstructionParts* optionalParts;
ZydisGetOptionalInstructionParts(node, &optionalParts);
ZYDIS_CHECK(ZydisDecodeInstructionPhysical(context, instruction, optionalParts));
const ZydisPhysicalInstructionInfo* info;
ZydisGetPhysicalInstructionInfo(node, &info);
ZYDIS_CHECK(ZydisDecodeInstructionPhysical(context, instruction, info));
if (instruction->encoding == ZYDIS_INSTRUCTION_ENCODING_3DNOW)
{

View File

@ -1,21 +1,21 @@
static const ZydisInstructionParts instructionClassMap[] =
static const ZydisPhysicalInstructionInfo physicalEncodings[] =
{
/*00*/ { 0, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*01*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*02*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*03*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*04*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*05*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*06*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*07*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*08*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*09*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0 | ZYDIS_INSTRPART_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0A*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0 | ZYDIS_INSTRPART_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0B*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0C*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0D*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_DISP, { { 16, 32, 64 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0E*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 64 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0F*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM | ZYDIS_INSTRPART_FLAG_FORCE_REG_FORM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*10*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*11*/ { 0 | ZYDIS_INSTRPART_FLAG_HAS_MODRM | ZYDIS_INSTRPART_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } }
/*01*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*02*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*03*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*04*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*05*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*06*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*07*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*08*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*09*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 32, 32 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0A*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM1, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0B*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0C*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 8, 8, 8 }, ZYDIS_TRUE, ZYDIS_TRUE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0D*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_DISP, { { 16, 32, 64 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0E*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 32, 64 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*0F*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM, { { 0, 0, 0 } }, { { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*10*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 16, 16, 16 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } },
/*11*/ { 0 | ZYDIS_PHYSINSTR_FLAG_HAS_MODRM | ZYDIS_PHYSINSTR_FLAG_HAS_IMM0, { { 0, 0, 0 } }, { { { 32, 32, 32 }, ZYDIS_FALSE, ZYDIS_FALSE }, { { 0, 0, 0 }, ZYDIS_FALSE, ZYDIS_FALSE } } }
};

View File

@ -286,7 +286,7 @@ extern const ZydisInstructionDefinitionMVEX instructionDefinitionsMVEX[];
/* Physical instruction encodings */
/* ---------------------------------------------------------------------------------------------- */
#include <Generated/InstructionClassMap.inc>
#include <Generated/PhysicalEncodings.inc>
/* ---------------------------------------------------------------------------------------------- */
/* Instruction tree */
@ -446,13 +446,13 @@ void ZydisGetInstructionDefinition(const ZydisInstructionTreeNode* node,
}
}
void ZydisGetOptionalInstructionParts(const ZydisInstructionTreeNode* node,
const ZydisInstructionParts** info)
void ZydisGetPhysicalInstructionInfo(const ZydisInstructionTreeNode* node,
const ZydisPhysicalInstructionInfo** info)
{
ZYDIS_ASSERT(node->type & ZYDIS_NODETYPE_DEFINITION_MASK);
uint8_t class = (node->type) & 0x7F;
ZYDIS_ASSERT(class < ZYDIS_ARRAY_SIZE(instructionClassMap));
*info = &instructionClassMap[class];
ZYDIS_ASSERT(class < ZYDIS_ARRAY_SIZE(physicalEncodings));
*info = &physicalEncodings[class];
}
/* ---------------------------------------------------------------------------------------------- */

View File

@ -652,7 +652,7 @@ enum ZydisMaskPolicies
/* ---------------------------------------------------------------------------------------------- */
#define ZYDIS_INSTRUCTION_DEFINITION_BASE \
ZydisInstructionMnemonic mnemonic ZYDIS_BITFIELD(11); \
ZydisMnemonic mnemonic ZYDIS_BITFIELD(11); \
uint8_t operandCount ZYDIS_BITFIELD( 4); \
uint16_t operandReference ZYDIS_BITFIELD(15); \
uint8_t operandSizeMap ZYDIS_BITFIELD( 3)
@ -737,29 +737,29 @@ typedef struct ZydisInstructionDefinitionMVEX_
/* ---------------------------------------------------------------------------------------------- */
/**
* @brief Defines the @c ZydisInstructionPartFlags datatype.
* @brief Defines the @c ZydisPhysicalInstructionInfoFlags datatype.
*/
typedef uint8_t ZydisInstructionPartFlags;
typedef uint8_t ZydisPhysicalInstructionInfoFlags;
/**
* @brief The instruction has an optional modrm byte.
*/
#define ZYDIS_INSTRPART_FLAG_HAS_MODRM 0x01
#define ZYDIS_PHYSINSTR_FLAG_HAS_MODRM 0x01
/**
* @brief The instruction has an optional displacement value.
*/
#define ZYDIS_INSTRPART_FLAG_HAS_DISP 0x02
#define ZYDIS_PHYSINSTR_FLAG_HAS_DISP 0x02
/**
* @brief The instruction has an optional immediate value.
*/
#define ZYDIS_INSTRPART_FLAG_HAS_IMM0 0x04
#define ZYDIS_PHYSINSTR_FLAG_HAS_IMM0 0x04
/**
* @brief The instruction has a second optional immediate value.
*/
#define ZYDIS_INSTRPART_FLAG_HAS_IMM1 0x08
#define ZYDIS_PHYSINSTR_FLAG_HAS_IMM1 0x08
/**
* @brief The instruction ignores the value of `modrm.mod` and always assumes `modrm.mod == 3`
@ -767,14 +767,17 @@ typedef uint8_t ZydisInstructionPartFlags;
*
* Instructions with this flag can't have a SIB byte or a displacement value.
*/
#define ZYDIS_INSTRPART_FLAG_FORCE_REG_FORM 0x10
#define ZYDIS_PHYSINSTR_FLAG_FORCE_REG_FORM 0x10
typedef struct ZydisInstructionParts_
/**
* @brief Defines the @c ZydisPhysicalInstructionInfo struct.
*/
typedef struct ZydisPhysicalInstructionInfo_
{
/**
* @brief Contains flags with information about the physical instruction-encoding.
*/
ZydisInstructionPartFlags flags;
ZydisPhysicalInstructionInfoFlags flags;
/**
* @brief Displacement info.
*/
@ -803,7 +806,7 @@ typedef struct ZydisInstructionParts_
*/
ZydisBool isRelative;
} imm[2];
} ZydisInstructionParts;
} ZydisPhysicalInstructionInfo;
/* ============================================================================================== */
/* Functions */
@ -851,8 +854,8 @@ ZYDIS_NO_EXPORT void ZydisGetInstructionDefinition(const ZydisInstructionTreeNod
* @param node The instruction definition node.
* @param info A pointer to the @c ZydisInstructionParts struct.
*/
ZYDIS_NO_EXPORT void ZydisGetOptionalInstructionParts(const ZydisInstructionTreeNode* node,
const ZydisInstructionParts** info);
ZYDIS_NO_EXPORT void ZydisGetPhysicalInstructionInfo(const ZydisInstructionTreeNode* node,
const ZydisPhysicalInstructionInfo** info);
/* ---------------------------------------------------------------------------------------------- */
/* Operand definition */

View File

@ -36,7 +36,7 @@
/* Exported functions */
/* ============================================================================================== */
const char* ZydisMnemonicGetString(ZydisInstructionMnemonic mnemonic)
const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic)
{
if (mnemonic > ZYDIS_ARRAY_SIZE(mnemonicStrings) - 1)
{