diff options
| author | Glenn Smith <glenn@vector35.com> | 2024-06-10 19:00:58 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2024-06-10 19:00:58 -0400 |
| commit | 7064468986827633023933435608630110377820 (patch) | |
| tree | 0043113cf273007ba8883807d71d248d7d90b9c1 /lowlevelilinstruction.cpp | |
| parent | 9879389091766176705999562870003860338879 (diff) | |
Add fmt formatters for IL instructions
Diffstat (limited to 'lowlevelilinstruction.cpp')
| -rw-r--r-- | lowlevelilinstruction.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index e0d5922d..17368662 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -3690,3 +3690,44 @@ ExprId LowLevelILFunction::FloatCompareUnordered(size_t size, ExprId a, ExprId b { return AddExprWithLocation(LLIL_FCMP_UO, loc, size, 0, a, b); } + + +fmt::format_context::iterator fmt::formatter<LowLevelILInstruction>::format(const LowLevelILInstruction& obj, format_context& ctx) const +{ + if (!obj.function) + return fmt::format_to(ctx.out(), "<uninit>"); + + vector<InstructionTextToken> tokens; +#ifdef BINARYNINJACORE_LIBRARY + bool success = obj.function->GetExprText(obj.function->GetFunction(), obj.function->GetArchitecture(), obj, tokens); +#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); + } + } + + for (auto& token: tokens) + { + fmt::format_to(ctx.out(), token.text); + } + } + else + { + fmt::format_to(ctx.out(), "???"); + } + return ctx.out(); +} |
