From 4ea37e18bfed8de162dfb816971417a0679b602f Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 7 May 2025 18:22:50 -0700 Subject: 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. --- lang/c/pseudoc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lang/c/pseudoc.h') diff --git a/lang/c/pseudoc.h b/lang/c/pseudoc.h index a3b03a88..66178432 100644 --- a/lang/c/pseudoc.h +++ b/lang/c/pseudoc.h @@ -52,6 +52,16 @@ protected: void EndLines( const BinaryNinja::HighLevelILInstruction& instr, BinaryNinja::HighLevelILTokenEmitter& tokens) override; + virtual void GetExpr_CALL_OR_TAILCALL(const BinaryNinja::HighLevelILInstruction& instr, + BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings, + BNOperatorPrecedence precedence, bool statement); + virtual void GetExpr_CONST_PTR(const BinaryNinja::HighLevelILInstruction& instr, + BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings, + BNOperatorPrecedence precedence, bool statement); + virtual void GetExpr_IMPORT(const BinaryNinja::HighLevelILInstruction& instr, + BinaryNinja::HighLevelILTokenEmitter& tokens, BinaryNinja::DisassemblySettings* settings, + BNOperatorPrecedence precedence, bool statement); + public: PseudoCFunction(BinaryNinja::LanguageRepresentationFunctionType* type, BinaryNinja::Architecture* arch, BinaryNinja::Function* owner, BinaryNinja::HighLevelILFunction* highLevelILFunction); @@ -66,4 +76,7 @@ public: PseudoCFunctionType(); BinaryNinja::Ref Create(BinaryNinja::Architecture* arch, BinaryNinja::Function* owner, BinaryNinja::HighLevelILFunction* highLevelILFunction) override; + +protected: + PseudoCFunctionType(const std::string& name); }; -- cgit v1.3.1