From c62a7862a86c7a05732985a7759b66b0035fb356 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Mon, 23 Mar 2026 10:37:39 -0700 Subject: [MachO] Apply the correct calling convention for objc_retain_xN / objc_release_xN The type library for the Objective-C runtime does not apply the custom calling conventions these functions use. Detect these functions when creating symbols for imported functions and apply the custom calling convention to them. Fixes https://github.com/Vector35/binaryninja-api/issues/8031. --- view/macho/machoview.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/view/macho/machoview.cpp b/view/macho/machoview.cpp index b1a5bdd9..d4ccf563 100644 --- a/view/macho/machoview.cpp +++ b/view/macho/machoview.cpp @@ -2712,6 +2712,17 @@ Ref MachoView::DefineMachoSymbol( } } + if ((type == ExternalSymbol || type == ImportAddressSymbol) + && (name.find("_objc_retain_x") != std::string::npos || name.find("_objc_release_x") != std::string::npos)) + { + auto x = name.rfind('x'); + auto num = name.substr(x + 1); + + auto cc = GetDefaultArchitecture()->GetCallingConventionByName("apple-arm64-objc-fast-arc-" + num); + if (auto idType = GetTypeByName({"id"}); cc && idType) + typeRef = Type::FunctionType(idType, cc, {{"obj", idType}}); + } + return std::pair, Ref>( new Symbol(type, shortName, fullName, rawName, addr, binding, nameSpace), typeRef); }; -- cgit v1.3.1