diff options
| author | Rusty Wagner <rusty.wagner@gmail.com> | 2025-12-23 13:12:02 -0700 |
|---|---|---|
| committer | Rusty Wagner <rusty.wagner@gmail.com> | 2026-05-22 16:30:56 -0400 |
| commit | 8d621c51b2797fda7b1dc22243dde611cfc04f68 (patch) | |
| tree | ba5e6a90e644d21d13e75dabcbd0cc747444443a /plugins | |
| parent | 08e34ac325743085911f96b62c81d9a1f2127806 (diff) | |
Refactor calling conventions to support correct representation of structures
Diffstat (limited to 'plugins')
| -rw-r--r-- | plugins/pdb-ng/src/symbol_parser.rs | 11 | ||||
| -rw-r--r-- | plugins/warp/src/convert.rs | 2 | ||||
| -rw-r--r-- | plugins/workflow_swift/src/demangler/function_type.rs | 43 | ||||
| -rw-r--r-- | plugins/workflow_swift/src/demangler/type_reconstruction.rs | 6 |
4 files changed, 29 insertions, 33 deletions
diff --git a/plugins/pdb-ng/src/symbol_parser.rs b/plugins/pdb-ng/src/symbol_parser.rs index a4ee4a6c..125d7c88 100644 --- a/plugins/pdb-ng/src/symbol_parser.rs +++ b/plugins/pdb-ng/src/symbol_parser.rs @@ -961,7 +961,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> { MIN_CONFIDENCE, )), p.name.clone(), - p.storage.first().map(|loc| loc.location), + p.storage.first().map(|loc| loc.location.into()), ); // Ignore thisptr because it's not technically part of the raw type signature if p.name != "this" { @@ -976,7 +976,7 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> { MIN_CONFIDENCE, )), p.name.clone(), - p.storage.first().map(|loc| loc.location), + p.storage.first().map(|loc| loc.location.into()), ); // Ignore thisptr because it's not technically part of the raw type signature if p.name != "this" { @@ -1035,7 +1035,6 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> { } } - // Now apply the default location for the params from the cc let cc = fancy_type .contents .calling_convention() @@ -1049,12 +1048,6 @@ impl<'a, S: Source<'a> + 'a> PDBParserInstance<'a, S> { }); self.log(|| format!("Default calling convention: {:?}", self.default_cc)); self.log(|| format!("Result calling convention: {:?}", cc)); - - let locations = cc.contents.variables_for_parameters(&fancy_params, None); - for (p, new_location) in fancy_params.iter_mut().zip(locations.into_iter()) { - p.location = Some(new_location); - } - self.log(|| format!("Final params: {:#x?}", fancy_params)); // Use the new locals we've parsed to make the Real Definitely True function type diff --git a/plugins/warp/src/convert.rs b/plugins/warp/src/convert.rs index bacf0024..85a06314 100644 --- a/plugins/warp/src/convert.rs +++ b/plugins/warp/src/convert.rs @@ -27,6 +27,8 @@ pub fn bn_var_to_location(bn_variable: BNVariable) -> Option<Location> { Some(Location::Register(reg_loc)) } VariableSourceType::FlagVariableSourceType => None, + VariableSourceType::CompositeReturnValueSourceType => None, + VariableSourceType::CompositeParameterSourceType => None, } } diff --git a/plugins/workflow_swift/src/demangler/function_type.rs b/plugins/workflow_swift/src/demangler/function_type.rs index 908f5940..73abe23f 100644 --- a/plugins/workflow_swift/src/demangler/function_type.rs +++ b/plugins/workflow_swift/src/demangler/function_type.rs @@ -1,8 +1,7 @@ -use binaryninja::architecture::{ArchitectureExt, CoreArchitecture, Register}; +use binaryninja::architecture::{ArchitectureExt, CoreArchitecture}; use binaryninja::confidence::Conf; use binaryninja::rc::Ref; -use binaryninja::types::{FunctionParameter, Type}; -use binaryninja::variable::{Variable, VariableSourceType}; +use binaryninja::types::{FunctionParameter, Type, ValueLocation, ValueLocationSource}; use swift_demangler::{ Accessor, AccessorKind, ConstructorKind, HasFunctionSignature, HasModule, Metadata, MetadataKind, Symbol, @@ -29,21 +28,17 @@ impl PlatformAbi { } } - fn error_location(&self) -> Option<Variable> { - self.register_variable(self.error_reg) + fn error_location(&self) -> Option<ValueLocation> { + self.register_location(self.error_reg) } - fn async_context_location(&self) -> Option<Variable> { - self.register_variable(self.async_context_reg) + fn async_context_location(&self) -> Option<ValueLocation> { + self.register_location(self.async_context_reg) } - fn register_variable(&self, name: &str) -> Option<Variable> { + fn register_location(&self, name: &str) -> Option<ValueLocation> { let reg = self.arch.register_by_name(name)?; - Some(Variable::new( - VariableSourceType::RegisterVariableSourceType, - 0, - reg.id().0 as i64, - )) + Some(ValueLocation::from_register(reg)) } } @@ -83,7 +78,7 @@ impl CallingConvention { self.leading_params.push(FunctionParameter { ty: self_ty.into(), name: "self".to_string(), - location: None, + location: ValueLocationSource::Default, }); } @@ -103,12 +98,12 @@ impl CallingConvention { self.trailing_params.push(FunctionParameter { ty: void_ptr.clone().into(), name: "selfMetadata".to_string(), - location: None, + location: ValueLocationSource::Default, }); self.trailing_params.push(FunctionParameter { ty: void_ptr.into(), name: "selfWitnessTable".to_string(), - location: None, + location: ValueLocationSource::Default, }); } @@ -144,7 +139,7 @@ impl CallingConvention { all_params.push(FunctionParameter { ty: error_ty.into(), name: "error".to_string(), - location: self.abi.as_ref().and_then(|a| a.error_location()), + location: self.abi.as_ref().and_then(|a| a.error_location()).into(), }); } @@ -153,7 +148,11 @@ impl CallingConvention { all_params.push(FunctionParameter { ty: ptr_ty.into(), name: "asyncContext".to_string(), - location: self.abi.as_ref().and_then(|a| a.async_context_location()), + location: self + .abi + .as_ref() + .and_then(|a| a.async_context_location()) + .into(), }); } @@ -245,7 +244,7 @@ pub fn build_function_type(symbol: &Symbol, arch: &CoreArchitecture) -> Option<R Some(FunctionParameter { ty: ty.into(), name, - location: None, + location: ValueLocationSource::Default, }) }) .collect(); @@ -288,7 +287,7 @@ fn build_accessor_type(accessor: &Accessor, arch: &CoreArchitecture) -> Option<R let params = vec![FunctionParameter { ty: prop_ty.into(), name: "newValue".to_string(), - location: None, + location: ValueLocationSource::Default, }]; Some(cc.build_type(&Type::void(), params)) } @@ -314,12 +313,12 @@ fn build_metadata_function_type(metadata: &Metadata, arch: &CoreArchitecture) -> FunctionParameter { ty: void_ptr.clone().into(), name: "metadata".to_string(), - location: None, + location: ValueLocationSource::Default, }, FunctionParameter { ty: void_ptr.clone().into(), name: "method".to_string(), - location: None, + location: ValueLocationSource::Default, }, ]; Some(Type::function(&void_ptr, params, false)) diff --git a/plugins/workflow_swift/src/demangler/type_reconstruction.rs b/plugins/workflow_swift/src/demangler/type_reconstruction.rs index 3a3ba3e7..33e44a72 100644 --- a/plugins/workflow_swift/src/demangler/type_reconstruction.rs +++ b/plugins/workflow_swift/src/demangler/type_reconstruction.rs @@ -1,6 +1,8 @@ use binaryninja::architecture::{Architecture, CoreArchitecture}; use binaryninja::rc::Ref; -use binaryninja::types::{NamedTypeReference, NamedTypeReferenceClass, QualifiedName, Type}; +use binaryninja::types::{ + NamedTypeReference, NamedTypeReferenceClass, QualifiedName, Type, ValueLocationSource, +}; use swift_demangler::{TypeKind, TypeRef}; pub(crate) trait TypeRefExt { @@ -57,7 +59,7 @@ impl TypeRefExt for TypeRef<'_> { Some(binaryninja::types::FunctionParameter { ty: ty.into(), name, - location: None, + location: ValueLocationSource::Default, }) }) .collect(); |
