summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2026-03-23 10:37:39 -0700
committerMark Rowe <mark@vector35.com>2026-03-23 16:05:06 -0700
commitc62a7862a86c7a05732985a7759b66b0035fb356 (patch)
tree2bf8e1ef057a931f70409230d00f9695ffbfc473
parent896f4b96b3f8e6f62e5fdd03803fdfc399db9c5d (diff)
[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.
-rw-r--r--view/macho/machoview.cpp11
1 files changed, 11 insertions, 0 deletions
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<Symbol> 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<Symbol>, Ref<Type>>(
new Symbol(type, shortName, fullName, rawName, addr, binding, nameSpace), typeRef);
};