Minor changes to the internal formatter logic

- `ZYDIS_FORMATTER_HOOK_PRINT_MEMSIZE` is now directly invoked by `ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM`
This commit is contained in:
flobernd 2018-02-26 13:13:11 +01:00
parent 1483f854f2
commit 0e60679470
No known key found for this signature in database
GPG Key ID: 9C3AE0ED4A969F10
2 changed files with 6 additions and 15 deletions

View File

@ -308,7 +308,7 @@ enum ZydisFormatterHookTypes
*/ */
ZYDIS_FORMATTER_HOOK_PRE_INSTRUCTION, 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, ZYDIS_FORMATTER_HOOK_POST_INSTRUCTION,
/** /**
@ -316,7 +316,7 @@ enum ZydisFormatterHookTypes
*/ */
ZYDIS_FORMATTER_HOOK_PRE_OPERAND, 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, ZYDIS_FORMATTER_HOOK_POST_OPERAND,
@ -336,7 +336,8 @@ enum ZydisFormatterHookTypes
* @brief This function is invoked to format a memory operand. * @brief This function is invoked to format a memory operand.
* *
* Replacing this function might indirectly disable some specific calls to the * 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, ZYDIS_FORMATTER_HOOK_FORMAT_OPERAND_MEM,
/** /**

View File

@ -120,15 +120,8 @@ static ZydisStatus ZydisFormatInstrIntel(const ZydisFormatter* formatter, ZydisS
break; break;
case ZYDIS_OPERAND_TYPE_MEMORY: 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, status = formatter->funcFormatOperandMem(formatter, string, instruction,
&instruction->operands[i], userData); &instruction->operands[i], userData);
if ((status == ZYDIS_STATUS_SUCCESS) && (strLenTemp == string->length))
{
string->length = strLenPreOperand;
}
break; break;
} }
case ZYDIS_OPERAND_TYPE_POINTER: case ZYDIS_OPERAND_TYPE_POINTER:
@ -242,6 +235,8 @@ static ZydisStatus ZydisFormatOperandMemIntel(const ZydisFormatter* formatter, Z
return ZYDIS_STATUS_INVALID_PARAMETER; return ZYDIS_STATUS_INVALID_PARAMETER;
} }
ZYDIS_CHECK(formatter->funcPrintMemSize(formatter, string, instruction, operand, userData));
switch (operand->mem.segment) switch (operand->mem.segment)
{ {
case ZYDIS_REGISTER_ES: case ZYDIS_REGISTER_ES:
@ -1252,11 +1247,6 @@ ZydisStatus ZydisFormatterFormatOperandEx(const ZydisFormatter* formatter,
userData); userData);
break; break;
case ZYDIS_OPERAND_TYPE_MEMORY: 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, status = formatter->funcFormatOperandMem(formatter, &string, instruction, operand,
userData); userData);
break; break;