From 1b7619ed534614eec3ea6d822644ccd9019499cf Mon Sep 17 00:00:00 2001 From: G0lge Date: Sat, 2 Mar 2024 21:35:10 +0300 Subject: [PATCH] replacing `has_displacement` with `size` --- examples/Disassemble.c | 1 + include/Zydis/DecoderTypes.h | 9 +++------ src/Decoder.c | 2 -- src/Encoder.c | 2 +- src/FormatterATT.c | 4 ++-- src/FormatterIntel.c | 4 ++-- src/Utils.c | 2 +- 7 files changed, 10 insertions(+), 14 deletions(-) diff --git a/examples/Disassemble.c b/examples/Disassemble.c index ad0a31af..b701a252 100644 --- a/examples/Disassemble.c +++ b/examples/Disassemble.c @@ -76,6 +76,7 @@ int main(void) offset += instruction.length; runtime_address += instruction.length; + } return 0; diff --git a/include/Zydis/DecoderTypes.h b/include/Zydis/DecoderTypes.h index 78072b02..a12c4807 100644 --- a/include/Zydis/DecoderTypes.h +++ b/include/Zydis/DecoderTypes.h @@ -149,19 +149,16 @@ typedef struct ZydisDecodedOperandMem_ */ struct ZydisDecodedOperandMemDisp_ { - /** - * Signals, if the displacement value is used. - */ - ZyanBool has_displacement; + /** * The displacement value */ ZyanI64 value; /** - * size of the displacement value + * The size of the displacement value */ - ZyanU16 size; + ZyanU8 size; } disp; } ZydisDecodedOperandMem; diff --git a/src/Decoder.c b/src/Decoder.c index 04900500..50b7d1ec 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -1433,7 +1433,6 @@ static ZyanStatus ZydisDecodeOperandMemory(const ZydisDecoderContext* context, if (displacement_size) { ZYAN_ASSERT(instruction->raw.disp.size == displacement_size); - operand->mem.disp.has_displacement = ZYAN_TRUE; operand->mem.disp.value = instruction->raw.disp.value; operand->mem.disp.size = displacement_size; } @@ -1830,7 +1829,6 @@ static ZyanStatus ZydisDecodeOperands(const ZydisDecoder* decoder, const ZydisDe ZYAN_ASSERT(instruction->raw.disp.size); operands[i].type = ZYDIS_OPERAND_TYPE_MEMORY; operands[i].mem.type = ZYDIS_MEMOP_TYPE_MEM; - operands[i].mem.disp.has_displacement = ZYAN_TRUE; operands[i].mem.disp.size = instruction->raw.disp.size; operands[i].mem.disp.value = instruction->raw.disp.value; break; diff --git a/src/Encoder.c b/src/Encoder.c index 49f7e303..1b92fe2e 100644 --- a/src/Encoder.c +++ b/src/Encoder.c @@ -4705,7 +4705,7 @@ ZYDIS_EXPORT ZyanStatus ZydisEncoderDecodedInstructionToEncoderRequest( enc_op->mem.base = dec_op->mem.base; enc_op->mem.index = dec_op->mem.index; enc_op->mem.scale = dec_op->mem.type != ZYDIS_MEMOP_TYPE_MIB ? dec_op->mem.scale : 0; - if (dec_op->mem.disp.has_displacement) + if (dec_op->mem.disp.size) { enc_op->mem.displacement = dec_op->mem.disp.value; } diff --git a/src/FormatterATT.c b/src/FormatterATT.c index bb183bdc..462ba449 100644 --- a/src/FormatterATT.c +++ b/src/FormatterATT.c @@ -208,7 +208,7 @@ ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter, const ZyanBool absolute = !formatter->force_relative_riprel && (context->runtime_address != ZYDIS_RUNTIME_ADDRESS_NONE); - if (absolute && context->operand->mem.disp.has_displacement && + if (absolute && context->operand->mem.disp.size && (context->operand->mem.index == ZYDIS_REGISTER_NONE) && ((context->operand->mem.base == ZYDIS_REGISTER_NONE) || (context->operand->mem.base == ZYDIS_REGISTER_EIP ) || @@ -226,7 +226,7 @@ ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter, if (neither_reg_nor_idx) { ZYAN_CHECK(formatter->func_print_address_abs(formatter, buffer, context)); - } else if (context->operand->mem.disp.has_displacement && context->operand->mem.disp.value) + } else if (context->operand->mem.disp.size && context->operand->mem.disp.value) { ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context)); } diff --git a/src/FormatterIntel.c b/src/FormatterIntel.c index 5e01e858..77144e82 100644 --- a/src/FormatterIntel.c +++ b/src/FormatterIntel.c @@ -212,7 +212,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter, const ZyanBool absolute = !formatter->force_relative_riprel && (context->runtime_address != ZYDIS_RUNTIME_ADDRESS_NONE); - if (absolute && context->operand->mem.disp.has_displacement && + if (absolute && context->operand->mem.disp.size && (context->operand->mem.index == ZYDIS_REGISTER_NONE) && ((context->operand->mem.base == ZYDIS_REGISTER_NONE) || (context->operand->mem.base == ZYDIS_REGISTER_EIP ) || @@ -253,7 +253,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter, if (neither_reg_nor_idx) { ZYAN_CHECK(formatter->func_print_address_abs(formatter, buffer, context)); - } else if (context->operand->mem.disp.has_displacement && context->operand->mem.disp.value) + } else if (context->operand->mem.disp.size && context->operand->mem.disp.value) { ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context)); } diff --git a/src/Utils.c b/src/Utils.c index 6fd86a98..c3a5b0f9 100644 --- a/src/Utils.c +++ b/src/Utils.c @@ -49,7 +49,7 @@ ZyanStatus ZydisCalcAbsoluteAddress(const ZydisDecodedInstruction* instruction, switch (operand->type) { case ZYDIS_OPERAND_TYPE_MEMORY: - if (!operand->mem.disp.has_displacement) + if (!operand->mem.disp.size) { return ZYAN_STATUS_INVALID_ARGUMENT; }