summaryrefslogtreecommitdiff
path: root/mediumlevelilinstruction.cpp
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-06-10 19:00:58 -0400
committerGlenn Smith <glenn@vector35.com>2024-06-10 19:00:58 -0400
commit7064468986827633023933435608630110377820 (patch)
tree0043113cf273007ba8883807d71d248d7d90b9c1 /mediumlevelilinstruction.cpp
parent9879389091766176705999562870003860338879 (diff)
Add fmt formatters for IL instructions
Diffstat (limited to 'mediumlevelilinstruction.cpp')
-rw-r--r--mediumlevelilinstruction.cpp46
1 files changed, 46 insertions, 0 deletions
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<MediumLevelILInstruction>::format(const MediumLevelILInstruction& 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, 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> 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();
+}