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 --- highlevelilinstruction.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'highlevelilinstruction.cpp') diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 3c838c1a..3626dd54 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -3262,3 +3262,55 @@ ExprId HighLevelILFunction::FloatCompareUnordered(size_t size, ExprId a, ExprId { return AddExprWithLocation(HLIL_FCMP_UO, loc, size, a, b); } + + +fmt::format_context::iterator fmt::formatter::format(const HighLevelILInstruction& obj, format_context& ctx) const +{ + if (!obj.function) + return fmt::format_to(ctx.out(), ""); + + vector tokens; + Ref settings = new DisassemblySettings(); + vector lines = obj.function->GetExprText(obj, settings); + if (!lines.empty()) + { + 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()); + } + } + + bool first = true; + for (auto& line: lines) + { + if (!first) + { + fmt::format_to(ctx.out(), " ; "); + } + first = false; + + for (auto& token: line.tokens) + { + fmt::format_to(ctx.out(), "{}", token.text); + } + } + } + else + { + fmt::format_to(ctx.out(), "???"); + } + return ctx.out(); +} -- cgit v1.3.1