diff --git a/include/Zydis/Formatter.h b/include/Zydis/Formatter.h index 904890d..adc153b 100644 --- a/include/Zydis/Formatter.h +++ b/include/Zydis/Formatter.h @@ -70,16 +70,16 @@ typedef uint32_t ZydisFormatterFlags; /** * @brief Formats the instruction in uppercase instead of lowercase. */ -#define ZYDIS_FMTFLAG_UPPERCASE 0x00000001 +#define ZYDIS_FMTFLAG_UPPERCASE 0x00000001 // (1 << 0) /** * @brief Forces the formatter to always print the segment register of memory-operands, instead * of ommiting implicit DS/SS segments. */ -#define ZYDIS_FMTFLAG_FORCE_SEGMENTS 0x00000002 +#define ZYDIS_FMTFLAG_FORCE_SEGMENTS 0x00000002 // (1 << 1) /** * @brief Forces the formatter to always print the size of memory-operands. */ -#define ZYDIS_FMTFLAG_FORCE_OPERANDSIZE 0x00000004 +#define ZYDIS_FMTFLAG_FORCE_OPERANDSIZE 0x00000004 // (1 << 2) /* ---------------------------------------------------------------------------------------------- */ diff --git a/src/Decoder.c b/src/Decoder.c index 2de8246..550c248 100644 --- a/src/Decoder.c +++ b/src/Decoder.c @@ -2032,6 +2032,10 @@ static void ZydisSetAttributes(ZydisDecoderContext* context, ZydisDecodedInstruc } if (def->isFarBranch) { + ZYDIS_ASSERT((instruction->meta.category == ZYDIS_CATEGORY_CALL) || + (instruction->meta.category == ZYDIS_CATEGORY_COND_BR) || + (instruction->meta.category == ZYDIS_CATEGORY_UNCOND_BR) || + (instruction->meta.category == ZYDIS_CATEGORY_RET)); instruction->attributes |= ZYDIS_ATTRIB_IS_FAR_BRANCH; } if (def->acceptsLock) diff --git a/src/Formatter.c b/src/Formatter.c index 9ecd795..acc033f 100644 --- a/src/Formatter.c +++ b/src/Formatter.c @@ -97,12 +97,21 @@ static ZydisStatus ZydisFormatterPrintMnemonicIntel(const ZydisFormatter* format return ZYDIS_STATUS_INVALID_PARAMETER; } + char* bufEnd = *buffer + bufferLen; + const char* mnemonic = ZydisMnemonicGetString(instruction->mnemonic); if (!mnemonic) { mnemonic = "invalid"; } - return ZydisPrintStr(buffer, bufferLen, mnemonic, ZYDIS_LETTER_CASE); + ZYDIS_CHECK(ZydisPrintStr(buffer, bufferLen, mnemonic, ZYDIS_LETTER_CASE)); + + if (instruction->attributes & ZYDIS_ATTRIB_IS_FAR_BRANCH) + { + return ZydisPrintStr(buffer, bufEnd - *buffer, " far", ZYDIS_LETTER_CASE); + } + + return ZYDIS_STATUS_SUCCESS; } /* ---------------------------------------------------------------------------------------------- */