Skip to content

Commit aa9c28e

Browse files
committed
Add data_variable_at_address and fixed the type propagation issue in riscv
1 parent 89060ca commit aa9c28e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

arch/riscv/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,9 +2865,17 @@ impl FunctionRecognizer for RiscVELFPLTRecognizer {
28652865

28662866
let func_sym =
28672867
Symbol::imported_function_from_import_address_symbol(sym.as_ref(), func.start());
2868+
28682869
bv.define_auto_symbol(func_sym.as_ref());
2869-
func.apply_imported_types(func_sym.as_ref(), None);
2870-
true
2870+
for ext_sym in &bv.symbols_by_name(func_sym.raw_name()) {
2871+
if ext_sym.sym_type() == SymbolType::External {
2872+
if let Some(var) = bv.data_variable_at_address(ext_sym.address()) {
2873+
func.apply_imported_types(func_sym.as_ref(), Some(var.t()));
2874+
return true;
2875+
}
2876+
}
2877+
}
2878+
false
28712879
}
28722880
}
28732881

rust/src/binaryview.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,17 @@ pub trait BinaryViewExt: BinaryViewBase {
564564
}
565565
}
566566

567+
fn data_variable_at_address(&self, addr: u64) -> Option<Ref<DataVariable>> {
568+
let dv = BNDataVariable::default();
569+
unsafe {
570+
if BNGetDataVariableAtAddress(self.as_ref().handle, addr, std::mem::transmute(&dv)) {
571+
Some(DataVariable(dv).to_owned())
572+
} else {
573+
None
574+
}
575+
}
576+
}
577+
567578
fn define_auto_data_var<'a, T: Into<Conf<&'a Type>>>(&self, addr: u64, ty: T) {
568579
unsafe {
569580
BNDefineDataVariable(self.as_ref().handle, addr, &mut ty.into().into());

0 commit comments

Comments
 (0)