diff options
| -rw-r--r-- | arch/riscv/src/lib.rs | 12 | ||||
| -rw-r--r-- | rust/src/binaryview.rs | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/arch/riscv/src/lib.rs b/arch/riscv/src/lib.rs index e619df2a..725177ca 100644 --- a/arch/riscv/src/lib.rs +++ b/arch/riscv/src/lib.rs @@ -2865,9 +2865,17 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer { let func_sym = Symbol::imported_function_from_import_address_symbol(sym.as_ref(), func.start()); + bv.define_auto_symbol(func_sym.as_ref()); - func.apply_imported_types(func_sym.as_ref(), None); - true + for ext_sym in &bv.symbols_by_name(func_sym.raw_name()) { + if ext_sym.sym_type() == SymbolType::External { + if let Some(var) = bv.data_variable_at_address(ext_sym.address()) { + func.apply_imported_types(func_sym.as_ref(), Some(var.t())); + return true; + } + } + } + false } } diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 8d7a2db4..bf14580c 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -564,6 +564,17 @@ pub trait BinaryViewExt: BinaryViewBase { } } + fn data_variable_at_address(&self, addr: u64) -> Option<Ref<DataVariable>> { + let dv = BNDataVariable::default(); + unsafe { + if BNGetDataVariableAtAddress(self.as_ref().handle, addr, std::mem::transmute(&dv)) { + Some(DataVariable(dv).to_owned()) + } else { + None + } + } + } + fn define_auto_data_var<'a, T: Into<Conf<&'a Type>>>(&self, addr: u64, ty: T) { unsafe { BNDefineDataVariable(self.as_ref().handle, addr, &mut ty.into().into()); |
