diff --git a/include/Zydis/DecoderTypes.h b/include/Zydis/DecoderTypes.h index 7142abe8..30683d3c 100644 --- a/include/Zydis/DecoderTypes.h +++ b/include/Zydis/DecoderTypes.h @@ -143,7 +143,7 @@ typedef struct ZydisDecodedOperandMem_ /** * The scale factor. */ - ZyanU8 scale; + ZyanU8 scale; // TODO: This is current 0 if no SIB byte is present. Should we use 1 as the default? /** * Extended info for memory-operands with displacement. */ diff --git a/include/Zydis/Formatter.h b/include/Zydis/Formatter.h index ac92dfbf..8343677f 100644 --- a/include/Zydis/Formatter.h +++ b/include/Zydis/Formatter.h @@ -122,10 +122,19 @@ typedef enum ZydisFormatterProperty_ /** * Controls the printing of the scale-factor component for memory operands. * - * Pass `ZYAN_TRUE` as value to force the formatter to always print the scale-factor component - * of memory operands or `ZYAN_FALSE` to omit the scale factor for values of `1`. + * Pass `ZYDIS_OPTION_NEVER` to never print the scale-factor 1, `ZYDIS_OPTION_ALWAYS` to always + * print the scale-factor 1 or `ZYDIS_OPTION_AUTO` to print the scale-factor 1 only if it's + * present in the physical instruction encoding (if the instruction has a `SIB` byte). */ - ZYDIS_FORMATTER_PROP_FORCE_SCALE_ONE, + ZYDIS_FORMATTER_PROP_SCALE_ONE, + /** + * Controls the printing of the displacement component for memory operands. + * + * Pass `ZYDIS_OPTION_NEVER` to never print the displacement 0, `ZYDIS_OPTION_ALWAYS` to always + * print the displacement 0 or `ZYDIS_OPTION_AUTO` to print the displacement 0 only if it's + * present in the physical instruction encoding. + */ + ZYDIS_FORMATTER_PROP_DISP_ZERO, /** * Controls the printing of branch addresses. * @@ -169,8 +178,7 @@ typedef enum ZydisFormatterProperty_ */ ZYDIS_FORMATTER_PROP_ADDR_BASE, /** - * Controls the signedness of relative addresses. Absolute addresses are - * always unsigned. + * Controls the signedness of relative addresses. Absolute addresses are always unsigned. */ ZYDIS_FORMATTER_PROP_ADDR_SIGNEDNESS, /** diff --git a/src/FormatterATT.c b/src/FormatterATT.c index bb183bdc..1c05b277 100644 --- a/src/FormatterATT.c +++ b/src/FormatterATT.c @@ -226,8 +226,12 @@ 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.has_displacement /* && context->operand->mem.disp.value */) { + // TODO: Add formatter option to control printing of scale1/disp0 with options + // - conditional (default) = print scale1 if SIB is present in physical encoding, print disp0 if DISP is present in physical encoding + // - always + // - never ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context)); } @@ -252,7 +256,6 @@ ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter, (context->operand->mem.type != ZYDIS_MEMOP_TYPE_MIB) && ((context->operand->mem.scale > 1) || formatter->force_memory_scale)) { - ZYDIS_BUFFER_APPEND_TOKEN(buffer, ZYDIS_TOKEN_DELIMITER); ZYDIS_BUFFER_APPEND(buffer, DELIM_MEMORY); ZYDIS_BUFFER_APPEND_TOKEN(buffer, ZYDIS_TOKEN_IMMEDIATE); ZYAN_CHECK(ZydisStringAppendDecU(&buffer->string, context->operand->mem.scale, 0, diff --git a/src/FormatterIntel.c b/src/FormatterIntel.c index 0584fb24..07566c24 100644 --- a/src/FormatterIntel.c +++ b/src/FormatterIntel.c @@ -252,8 +252,12 @@ 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.has_displacement /* && context->operand->mem.disp.value */) { + // TODO: Add formatter option to control printing of scale1/disp0 with options + // - conditional (default) = print scale1 if SIB is present in physical encoding, print disp0 if DISP is present in physical encoding + // - always + // - never ZYAN_CHECK(formatter->func_print_disp(formatter, buffer, context)); } }