Allowed custom operand-sizes for register operands

This commit is contained in:
flobernd 2017-06-20 03:16:17 +02:00
parent 4487d1b252
commit 17358016d9
3 changed files with 19 additions and 14 deletions

View File

@ -522,6 +522,10 @@ enum ZydisOpcodeMaps
*/
typedef uint64_t ZydisInstructionAttributes;
// TODO: Update values
// TODO: Add IsAtomic
/**
* @brief The instruction has the ModRM byte.
*/
@ -553,8 +557,7 @@ typedef uint64_t ZydisInstructionAttributes;
/**
* @brief The instruction is privileged.
*
* Priviliged instructions are any instructions that require a current ring
* level below 3 or even SMM.
* Priviliged instructions are any instructions that require a current ring level below 3.
*/
#define ZYDIS_ATTRIB_IS_PRIVILEGED 0x0000000000000080
/**
@ -606,14 +609,6 @@ typedef uint64_t ZydisInstructionAttributes;
* @brief The instruction accepts segment prefixes (0x2E, 0x36, 0x3E, 0x26, 0x64, 0x65).
*/
#define ZYDIS_ATTRIB_ACCEPTS_SEGMENT 0x0000000000020000
/**
* @brief The instruction accepts the operand-size prefix (0x66).
*/
#define ZYDIS_ATTRIB_ACCEPTS_OPERANDSIZE 0x0000000000040000 // TODO: Remove
/**
* @brief The instruction accepts the address-size prefix (0x67).
*/
#define ZYDIS_ATTRIB_ACCEPTS_ADDRESSSIZE 0x0000000000080000 // TODO: Remove
/**
* @brief The instruction has the lock prefix (0xF0).
*/

View File

@ -933,8 +933,14 @@ static void ZydisSetOperandSizeAndElementInfo(ZydisDecoderContext* context,
{
case ZYDIS_OPERAND_TYPE_REGISTER:
{
operand->size = (context->decoder->machineMode == 64) ?
ZydisRegisterGetWidth64(operand->reg) : ZydisRegisterGetWidth(operand->reg);
if (definition->size[context->eoszIndex])
{
operand->size = definition->size[context->eoszIndex] * 8;
} else
{
operand->size = (context->decoder->machineMode == 64) ?
ZydisRegisterGetWidth64(operand->reg) : ZydisRegisterGetWidth(operand->reg);
}
operand->elementType = ZYDIS_ELEMENT_TYPE_INT;
operand->elementSize = operand->size;
break;
@ -2055,6 +2061,10 @@ static void ZydisSetPrefixRelatedAttributes(ZydisDecoderContext* context,
}
} else
{
if (def->acceptsSegment)
{
info->attributes |= ZYDIS_ATTRIB_ACCEPTS_SEGMENT;
}
if (context->lastSegmentPrefix && def->acceptsSegment)
{
switch (context->lastSegmentPrefix)

View File

@ -500,11 +500,11 @@ static ZydisStatus ZydisFormatterPrintOperandSizeIntel(ZydisInstructionFormatter
uint32_t typecast = 0;
if (formatter->flags & ZYDIS_FMTFLAG_FORCE_OPERANDSIZE)
{
if (info->operands[operand->id].type == ZYDIS_OPERAND_TYPE_MEMORY)
if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly))
{
typecast = info->operands[operand->id].size;
}
} else if (info->operands[operand->id].type == ZYDIS_OPERAND_TYPE_MEMORY)
} else if ((operand->type == ZYDIS_OPERAND_TYPE_MEMORY) && (!operand->mem.isAddressGenOnly))
{
switch (operand->id)
{