From 67a3751cdc75855503146c502c513efd977b32ae Mon Sep 17 00:00:00 2001 From: mappzor <34216645+mappzor@users.noreply.github.com> Date: Thu, 11 Jan 2024 21:30:11 +0100 Subject: [PATCH 1/2] Print sizes for `agen` memory operands (forced mode) --- src/FormatterBase.c | 5 +++++ src/FormatterIntel.c | 1 + 2 files changed, 6 insertions(+) diff --git a/src/FormatterBase.c b/src/FormatterBase.c index 6aad525d..d797a469 100644 --- a/src/FormatterBase.c +++ b/src/FormatterBase.c @@ -86,12 +86,17 @@ ZyanU32 ZydisFormatterHelperGetExplicitSize(const ZydisFormatter* formatter, ZYAN_ASSERT(operand->type == ZYDIS_OPERAND_TYPE_MEMORY); ZYAN_ASSERT((operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) || + (operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) || (operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB)); if (formatter->force_memory_size) { return operand->size; } + else if (operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) + { + return 0; + } if (!context->operands) { diff --git a/src/FormatterIntel.c b/src/FormatterIntel.c index 0584fb24..d754ce32 100644 --- a/src/FormatterIntel.c +++ b/src/FormatterIntel.c @@ -201,6 +201,7 @@ ZyanStatus ZydisFormatterIntelFormatOperandMEM(const ZydisFormatter* formatter, ZYAN_ASSERT(context); if ((context->operand->mem.type == ZYDIS_MEMOP_TYPE_MEM) || + (context->operand->mem.type == ZYDIS_MEMOP_TYPE_AGEN) || (context->operand->mem.type == ZYDIS_MEMOP_TYPE_VSIB)) { ZYAN_CHECK(formatter->func_print_typecast(formatter, buffer, context)); From d1caa7634edb03718f447246c6e8c2d91a2c4e27 Mon Sep 17 00:00:00 2001 From: mappzor <34216645+mappzor@users.noreply.github.com> Date: Thu, 11 Jan 2024 21:33:16 +0100 Subject: [PATCH 2/2] Pad addresses to address width --- include/Zydis/Formatter.h | 8 ++++---- src/FormatterBase.c | 4 ++-- src/FormatterIntel.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/Zydis/Formatter.h b/include/Zydis/Formatter.h index b2f8d025..e503d5fa 100644 --- a/include/Zydis/Formatter.h +++ b/include/Zydis/Formatter.h @@ -176,16 +176,16 @@ typedef enum ZydisFormatterProperty_ /** * Controls the padding of absolute address values. * - * Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all - * addresses to the current stack width (hexadecimal only), or any other integer value for + * Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all + * addresses to the current address width (hexadecimal only), or any other integer value for * custom padding. */ ZYDIS_FORMATTER_PROP_ADDR_PADDING_ABSOLUTE, /** * Controls the padding of relative address values. * - * Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to padd all - * addresses to the current stack width (hexadecimal only), or any other integer value for + * Pass `ZYDIS_PADDING_DISABLED` to disable padding, `ZYDIS_PADDING_AUTO` to pad all + * addresses to the current address width (hexadecimal only), or any other integer value for * custom padding. */ ZYDIS_FORMATTER_PROP_ADDR_PADDING_RELATIVE, diff --git a/src/FormatterBase.c b/src/FormatterBase.c index d797a469..495b31c2 100644 --- a/src/FormatterBase.c +++ b/src/FormatterBase.c @@ -235,7 +235,7 @@ ZyanStatus ZydisFormatterBasePrintAddressABS(const ZydisFormatter* formatter, if ((formatter->addr_padding_absolute == ZYDIS_PADDING_AUTO) && (formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX)) { - switch (context->instruction->stack_width) + switch (context->instruction->address_width) { case 16: padding = 4; @@ -275,7 +275,7 @@ ZyanStatus ZydisFormatterBasePrintAddressREL(const ZydisFormatter* formatter, if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) && (formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX)) { - switch (context->instruction->stack_width) + switch (context->instruction->address_width) { case 16: padding = 4; diff --git a/src/FormatterIntel.c b/src/FormatterIntel.c index d754ce32..5e01e858 100644 --- a/src/FormatterIntel.c +++ b/src/FormatterIntel.c @@ -426,7 +426,7 @@ ZyanStatus ZydisFormatterIntelPrintAddressMASM(const ZydisFormatter* formatter, if ((formatter->addr_padding_relative == ZYDIS_PADDING_AUTO) && (formatter->addr_base == ZYDIS_NUMERIC_BASE_HEX)) { - switch (context->instruction->stack_width) + switch (context->instruction->address_width) { case 16: padding = 4;