summaryrefslogtreecommitdiff
path: root/lang/c/pseudoobjc.h
diff options
context:
space:
mode:
authorMark Rowe <mrowe@bdash.net.nz>2025-05-07 18:22:50 -0700
committerkat <kat@vector35.com>2025-05-29 09:42:11 -0400
commit4ea37e18bfed8de162dfb816971417a0679b602f (patch)
tree899c8f86701c7a8e2359c84d73e9c2ba2759c540 /lang/c/pseudoobjc.h
parentc55c604031e0d04a44c39832f5887e2d9aa7314e (diff)
Implement a Pseudo Objective-C language representation
This is implemented in the Pseudo C plug-in as it shares 99% of the logic. The Objective-C support is implemented in a subclass of `PseudoCFunction`. The handling of instruction types that the Objective-C representation needs to customize is extracted into virtual functions that the Objective-C subclass overrides. This currently supports: * Rewriting `objc_msgSend` / `objc_msgSendSuper2` with constant selectors to `[receiver message]` notation. * Rewriting calls to `objc_alloc` / `objc_alloc_init` / `objc_new` to the equivalent message send notation. * Rewriting `objc_retain` / `objc_release` and friends to the equivalent message send notation. * Displaying Objective-C class references as their class names rather than `_OBJC_CLASS_$_` symbol names. * Displaying Objective-C string literals as `@"..."`. This works best when used in conjunction with https://github.com/bdash/bn-objc-extras as the reference counting runtime calls add so much clutter.
Diffstat (limited to 'lang/c/pseudoobjc.h')
-rw-r--r--lang/c/pseudoobjc.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/lang/c/pseudoobjc.h b/lang/c/pseudoobjc.h
new file mode 100644
index 00000000..4b87c7d7
--- /dev/null
+++ b/lang/c/pseudoobjc.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include "pseudoc.h"
+
+#include "binaryninjaapi.h"
+
+class PseudoObjCFunction : public PseudoCFunction
+{
+public:
+ PseudoObjCFunction(BinaryNinja::LanguageRepresentationFunctionType* type, BinaryNinja::Architecture* arch,
+ BinaryNinja::Function* owner, BinaryNinja::HighLevelILFunction* highLevelILFunction);
+
+protected:
+ void GetExpr_CALL_OR_TAILCALL(const BinaryNinja::HighLevelILInstruction& instr,
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
+ BNOperatorPrecedence precedence, bool statement) override;
+ void GetExpr_CONST_PTR(const BinaryNinja::HighLevelILInstruction& instr,
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
+ BNOperatorPrecedence precedence, bool statement) override;
+ void GetExpr_IMPORT(const BinaryNinja::HighLevelILInstruction& instr,
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
+ BNOperatorPrecedence precedence, bool statement) override;
+
+private:
+ bool GetExpr_ObjCMsgSend(const BinaryNinja::HighLevelILInstruction& expr,
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
+ const std::vector<BinaryNinja::HighLevelILInstruction>& parameterExprs);
+ bool GetExpr_GenericObjCRuntimeCall(uint64_t address, const BinaryNinja::HighLevelILInstruction& expr,
+ BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings,
+ const std::vector<BinaryNinja::HighLevelILInstruction>& parameterExprs, const std::vector<std::string_view>& selectorTokens);
+ bool GetExpr_OBJC_CLASS(const BinaryNinja::Symbol& symbol, uint64_t constant,
+ const BinaryNinja::HighLevelILInstruction& expr, BinaryNinja::HighLevelILTokenEmitter& tokens,
+ BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement);
+ bool GetExpr_NSConstantString(BinaryNinja::Ref<BinaryNinja::Type> type, uint64_t constant,
+ const BinaryNinja::HighLevelILInstruction& expr, BinaryNinja::HighLevelILTokenEmitter& tokens,
+ BinaryNinja::DisassemblySettings* settings, BNOperatorPrecedence precedence, bool statement);
+};
+
+class PseudoObjCFunctionType : public PseudoCFunctionType {
+public:
+ PseudoObjCFunctionType();
+ BinaryNinja::Ref<BinaryNinja::LanguageRepresentationFunction> Create(BinaryNinja::Architecture* arch,
+ BinaryNinja::Function* owner, BinaryNinja::HighLevelILFunction* highLevelILFunction) override;
+};