From 0e60679470b0649f059eeda574f3b5d262696f3b Mon Sep 17 00:00:00 2001 From: flobernd Date: Mon, 26 Feb 2018 13:13:11 +0100 Subject: [PATCH] Minor changes to the internal formatter logic - `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE` is now directly invoked by `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM` --- include/Zydis/Formatter.h | 7 ++++--- src/Formatter.c | 14 ++------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/include/Zydis/Formatter.h b/include/Zydis/Formatter.h index 474a257..0d1ed12 100644 --- a/include/Zydis/Formatter.h +++ b/include/Zydis/Formatter.h @@ -308,7 +308,7 @@ enum ZydisFormatterHookTypes */ ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION, /** - * @brief This function is invoked before the formatter formatted an instruction. + * @brief This function is invoked after the formatter formatted an instruction. */ ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION, /** @@ -316,7 +316,7 @@ enum ZydisFormatterHookTypes */ ZYDIS_FORMATTER_HOOK_PRE_OPERAND, /** - * @brief This function is invoked before the formatter formatted an operand. + * @brief This function is invoked after the formatter formatted an operand. */ ZYDIS_FORMATTER_HOOK_POST_OPERAND, @@ -336,7 +336,8 @@ enum ZydisFormatterHookTypes * @brief This function is invoked to format a memory operand. * * Replacing this function might indirectly disable some specific calls to the - * `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and `ZYDIS_FORMATTER_HOOK_PRINT_DISP` functions. + * `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE`, `ZYDIS_FORMATTER_HOOK_PRINT_ADDRESS` and + * `ZYDIS_FORMATTER_HOOK_PRINT_DISP` functions. */ ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM, /** diff --git a/src/Formatter.c b/src/Formatter.c index 572ea6c..90955bc 100644 --- a/src/Formatter.c +++ b/src/Formatter.c @@ -120,15 +120,8 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS break; case ZYDIS_OPERAND_TYPE_MEMORY: { - ZYDIS_CHECK(formatter->funcPrintMemSize(formatter, string, instruction, - &instruction->operands[i], userData)); - const ZydisUSize strLenTemp = string->length; status = formatter->funcFormatOperandMem(formatter, string, instruction, &instruction->operands[i], userData); - if ((status == ZYDIS_STATUS_SUCCESS) && (strLenTemp == string->length)) - { - string->length = strLenPreOperand; - } break; } case ZYDIS_OPERAND_TYPE_POINTER: @@ -242,6 +235,8 @@ static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, Z return ZYDIS_STATUS_INVALID_PARAMETER; } + ZYDIS_CHECK(formatter->funcPrintMemSize(formatter, string, instruction, operand, userData)); + switch (operand->mem.segment) { case ZYDIS_REGISTER_ES: @@ -1252,11 +1247,6 @@ ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter, userData); break; case ZYDIS_OPERAND_TYPE_MEMORY: - status = formatter->funcPrintMemSize(formatter, &string, instruction, operand, userData); - if (!ZYDIS_SUCCESS(status)) - { - goto FinalizeString; - } status = formatter->funcFormatOperandMem(formatter, &string, instruction, operand, userData); break;