summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZichuan Li <34680029+river-li@users.noreply.github.com>2024-06-12 13:19:57 -0400
committerZichuan Li <34680029+river-li@users.noreply.github.com>2024-06-19 13:06:04 -0400
commitaa9c28e91b5c2ef6ab0e2aff7e44f8a16de998f7 (patch)
tree9c2c52940f227a9b1640d09119615d0365f3d906
parent89060ca7644244b3fba94bf746db588e707e7c8d (diff)
Add data_variable_at_address and fixed the type propagation issue in riscv
-rw-r--r--arch/riscv/src/lib.rs12
-rw-r--r--rust/src/binaryview.rs11
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());