From 1fb9828d1e12f242fa6a53aa43603ae5e556b69d Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Wed, 18 Feb 2026 22:03:29 -0800 Subject: [Swift] Add support for applying parameter and return types during demangling This is disabled by default due to a current limitation where core is not able to represent parameters that are small structs being passed across multiple registers. `analysis.swift.extractTypesFromMangledNames` can be enabled to test this. --- plugins/workflow_swift/src/demangler/mod.rs | 36 +++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'plugins/workflow_swift/src/demangler/mod.rs') diff --git a/plugins/workflow_swift/src/demangler/mod.rs b/plugins/workflow_swift/src/demangler/mod.rs index e1f22893..657c62c3 100644 --- a/plugins/workflow_swift/src/demangler/mod.rs +++ b/plugins/workflow_swift/src/demangler/mod.rs @@ -1,9 +1,22 @@ +mod function_type; +mod name; +mod type_reconstruction; + use binaryninja::architecture::CoreArchitecture; use binaryninja::binary_view::BinaryView; use binaryninja::demangle::CustomDemangler; use binaryninja::rc::Ref; +use binaryninja::settings::{QueryOptions, Settings}; use binaryninja::types::{QualifiedName, Type}; +fn should_extract_types(view: Option<&BinaryView>) -> bool { + let mut opts = match view { + Some(v) => QueryOptions::new_with_view(v), + None => QueryOptions::new(), + }; + Settings::new().get_bool_with_opts(crate::SETTING_EXTRACT_TYPES, &mut opts) +} + pub struct SwiftDemangler; impl CustomDemangler for SwiftDemangler { @@ -19,16 +32,25 @@ impl CustomDemangler for SwiftDemangler { fn demangle( &self, - _arch: &CoreArchitecture, + arch: &CoreArchitecture, name: &str, - _view: Option>, + view: Option>, ) -> Option<(QualifiedName, Option>)> { let ctx = swift_demangler::Context::new(); let symbol = swift_demangler::Symbol::parse(&ctx, name)?; - // Use the canonical demangled form from the parsed node tree. - // This matches what `xcrun swift-demangle` produces. - // TODO: Use the structured Symbol API to also reconstruct BN Types. - let demangled = symbol.display(); - Some((QualifiedName::from(demangled), None)) + + if should_extract_types(view.as_deref()) { + let ty = function_type::build_function_type(&symbol, arch); + let qname = if ty.is_some() { + name::build_short_name(&symbol) + } else { + None + } + .unwrap_or_else(|| QualifiedName::from(symbol.display())); + Some((qname, ty)) + } else { + let qname = QualifiedName::from(symbol.display()); + Some((qname, None)) + } } } -- cgit v1.3.1