Fixed formatting of signed 8-bit immediate operands (again)

- Renamed `operandSize` to `operandWidth`
- The `operandWidth` field is now set to 8-bit, if the instruction performs a byte-operation
This commit is contained in:
flobernd 2017-09-21 22:16:37 +02:00
parent e6399bbb27
commit 9222f80b97
5 changed files with 490 additions and 463 deletions

View File

@ -729,14 +729,14 @@ typedef struct ZydisDecodedInstruction_
* @brief The instruction-opcode.
*/
uint8_t opcode;
/**
* @brief The effective operand size.
*/
uint8_t operandSize;
/**
* @brief The stack width.
*/
uint8_t stackWidth;
/**
* @brief The effective operand width.
*/
uint8_t operandWidth;
/**
* @brief The effective address width.
*/

View File

@ -1564,7 +1564,8 @@ static void ZydisDecodeOperandImplicitRegister(ZydisDecoderContext* context,
ZYDIS_REGCLASS_GPR32,
ZYDIS_REGCLASS_GPR64
};
operand->reg.value = ZydisRegisterEncode(lookup[context->eoszIndex], definition->op.reg.reg.id);
operand->reg.value =
ZydisRegisterEncode(lookup[context->eoszIndex], definition->op.reg.reg.id);
break;
}
case ZYDIS_IMPLREG_TYPE_GPR_ASZ:
@ -1723,19 +1724,25 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* context,
registerClass = ZYDIS_REGCLASS_GPR64;
break;
case ZYDIS_SEMANTIC_OPTYPE_GPR16_32_64:
ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) ||
(instruction->operandWidth == 64));
registerClass =
(instruction->operandSize == 16) ? ZYDIS_REGCLASS_GPR16 : (
(instruction->operandSize == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64);
(instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR16 : (
(instruction->operandWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR64);
break;
case ZYDIS_SEMANTIC_OPTYPE_GPR32_32_64:
ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) ||
(instruction->operandWidth == 64));
registerClass =
(instruction->operandSize == 16) ? ZYDIS_REGCLASS_GPR32 : (
(instruction->operandSize == 32) ? ZYDIS_REGCLASS_GPR32: ZYDIS_REGCLASS_GPR64);
(instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR32 : (
(instruction->operandWidth == 32) ? ZYDIS_REGCLASS_GPR32: ZYDIS_REGCLASS_GPR64);
break;
case ZYDIS_SEMANTIC_OPTYPE_GPR16_32_32:
ZYDIS_ASSERT((instruction->operandWidth == 16) || (instruction->operandWidth == 32) ||
(instruction->operandWidth == 64));
registerClass =
(instruction->operandSize == 16) ? ZYDIS_REGCLASS_GPR16 : (
(instruction->operandSize == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR32);
(instruction->operandWidth == 16) ? ZYDIS_REGCLASS_GPR16 : (
(instruction->operandWidth == 32) ? ZYDIS_REGCLASS_GPR32 : ZYDIS_REGCLASS_GPR32);
break;
case ZYDIS_SEMANTIC_OPTYPE_FPR:
registerClass = ZYDIS_REGCLASS_X87;
@ -3271,7 +3278,7 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context,
ZYDIS_ASSERT(instruction);
ZYDIS_ASSERT(definition);
static const uint8_t operandSizeMap[7][8] =
static const uint8_t operandSizeMap[8][8] =
{
// Default for most instructions
{
@ -3284,6 +3291,17 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context,
64, // 64 __ W1
64 // 64 66 W1
},
// Operand size is forced to 8-bit (this is done later to preserve the `eoszIndex`)
{
16, // 16 __ W0
32, // 16 66 W0
32, // 32 __ W0
16, // 32 66 W0
32, // 64 __ W0
16, // 64 66 W0
64, // 64 __ W1
64 // 64 66 W1
},
// Operand size override 0x66 is ignored
{
16, // 16 __ W0
@ -3373,9 +3391,9 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context,
ZYDIS_ASSERT(definition->operandSizeMap < ZYDIS_ARRAY_SIZE(operandSizeMap));
ZYDIS_ASSERT(index < ZYDIS_ARRAY_SIZE(operandSizeMap[definition->operandSizeMap]));
instruction->operandSize = operandSizeMap[definition->operandSizeMap][index];
instruction->operandWidth = operandSizeMap[definition->operandSizeMap][index];
switch (instruction->operandSize)
switch (instruction->operandWidth)
{
case 16:
context->eoszIndex = 0;
@ -3389,6 +3407,12 @@ static void ZydisSetEffectiveOperandSize(ZydisDecoderContext* context,
default:
ZYDIS_UNREACHABLE;
}
// TODO: Cleanup code and remove hardcoded condition
if (definition->operandSizeMap == 1)
{
instruction->operandWidth = 8;
}
}
/**

View File

@ -368,8 +368,11 @@ static ZydisStatus ZydisFormatterPrintImmediateIntel(const ZydisFormatter* forma
return ZYDIS_STATUS_INVALID_PARAMETER;
}
}
switch (instruction->operandSize)
switch (instruction->operandWidth)
{
case 8:
return ZydisPrintHexU(
buffer, bufferLen, (uint8_t)operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);
case 16:
return ZydisPrintHexU(
buffer, bufferLen, (uint16_t)operand->imm.value.u, 2, ZYDIS_TRUE, ZYDIS_TRUE);

File diff suppressed because it is too large Load Diff

View File

@ -444,7 +444,7 @@ void printInstruction(ZydisDecodedInstruction* instruction)
instruction->opcode);
printf(" LENGTH: %2d\n", instruction->length);
printf(" SSZ: %2d\n", instruction->stackWidth);
printf(" EOSZ: %2d\n", instruction->operandSize);
printf(" EOSZ: %2d\n", instruction->operandWidth);
printf(" EASZ: %2d\n", instruction->addressWidth);
printf(" CATEGORY: %s\n", ZydisCategoryGetString(instruction->meta.category));
printf(" ISA-SET: %s\n", ZydisISASetGetString(instruction->meta.isaSet));