From 7064468986827633023933435608630110377820 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 10 Jun 2024 19:00:58 -0400 Subject: Add fmt formatters for IL instructions --- mediumlevelilinstruction.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'mediumlevelilinstruction.cpp') diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 0306a404..754729c0 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -3125,3 +3125,49 @@ ExprId MediumLevelILFunction::FloatCompareUnordered(size_t size, ExprId a, ExprI { return AddExprWithLocation(MLIL_FCMP_UO, loc, size, a, b); } + + +fmt::format_context::iterator fmt::formatter::format(const MediumLevelILInstruction& obj, format_context& ctx) const +{ + if (!obj.function) + return fmt::format_to(ctx.out(), ""); + + vector tokens; +#ifdef BINARYNINJACORE_LIBRARY + bool success = obj.function->GetExprText(obj.function->GetFunction(), obj.function->GetArchitecture(), obj, tokens, new DisassemblySettings()); +#else + bool success = obj.function->GetExprText(obj.function->GetArchitecture(), obj.exprIndex, tokens); +#endif + if (success) + { + string text; + if (presentation == '?') + { + fmt::format_to(ctx.out(), "{} ", obj.operation); + fmt::format_to(ctx.out(), "@ {:#x} ", obj.address); + if (obj.exprIndex != BN_INVALID_EXPR && (obj.exprIndex & 0xffff000000000000) == 0) + { + fmt::format_to(ctx.out(), "[expr {}] ", obj.exprIndex); + } + if (obj.instructionIndex != BN_INVALID_EXPR && (obj.instructionIndex & 0xffff000000000000) == 0) + { + fmt::format_to(ctx.out(), "[instr {}] ", obj.instructionIndex); + } + Ref type = obj.GetType(); + if (type) + { + fmt::format_to(ctx.out(), "[type: {}] ", type->GetString()); + } + } + + for (auto& token: tokens) + { + fmt::format_to(ctx.out(), token.text); + } + } + else + { + fmt::format_to(ctx.out(), "???"); + } + return ctx.out(); +} -- cgit v1.3.1