summaryrefslogtreecommitdiff
path: root/plugins/workflow_swift/src/demangler/mod.rs
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2026-02-18 22:03:29 -0800
committerMark Rowe <mark@vector35.com>2026-03-23 16:08:45 -0700
commit1fb9828d1e12f242fa6a53aa43603ae5e556b69d (patch)
tree40fd4fa7ca487ca8cce5a8eca8e18d5e4a15da83 /plugins/workflow_swift/src/demangler/mod.rs
parent7aa5bd46fc2343458dff6a24ec2c67169fcac34c (diff)
[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.
Diffstat (limited to 'plugins/workflow_swift/src/demangler/mod.rs')
-rw-r--r--plugins/workflow_swift/src/demangler/mod.rs36
1 files changed, 29 insertions, 7 deletions
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<Ref<BinaryView>>,
+ view: Option<Ref<BinaryView>>,
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
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))
+ }
}
}