summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2022-08-31 23:01:49 -0400
committerGlenn Smith <glenn@vector35.com>2022-09-29 21:02:24 -0400
commit460656be13999759eb1eeb5bd9a868b34c0aea22 (patch)
tree8147e1028b4e6ca42dc4dc5c03f1453c13a8b1fc /rust/src
parente5af153f0b7964bf65ff9af07012d9a51ab0cd1c (diff)
Expose CallingConvention::GetVariablesForParameters
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/callingconvention.rs62
-rw-r--r--rust/src/symbol.rs2
-rw-r--r--rust/src/types.rs2
3 files changed, 64 insertions, 2 deletions
diff --git a/rust/src/callingconvention.rs b/rust/src/callingconvention.rs
index 79fe7201..a8deadef 100644
--- a/rust/src/callingconvention.rs
+++ b/rust/src/callingconvention.rs
@@ -445,6 +445,66 @@ impl<A: Architecture> CallingConvention<A> {
pub fn name(&self) -> BnString {
unsafe { BnString::from_raw(BNGetCallingConventionName(self.handle)) }
}
+
+ pub fn variables_for_parameters<S: Clone + BnStrCompatible>(
+ &self,
+ params: &Vec<FunctionParameter<S>>,
+ int_arg_registers: Option<Vec<A::Register>>,
+ ) -> Vec<Variable> {
+ let mut bn_params: Vec<BNFunctionParameter> = vec![];
+
+ for parameter in params.iter() {
+ let raw_name = parameter.name.clone().into_bytes_with_nul();
+ let location = match &parameter.location {
+ Some(location) => location.into_raw(),
+ None => unsafe { mem::zeroed() },
+ };
+ bn_params.push(BNFunctionParameter {
+ name: raw_name.as_ref().as_ptr() as *mut _,
+ type_: parameter.t.contents.handle,
+ typeConfidence: parameter.t.confidence,
+ defaultLocation: parameter.location.is_none(),
+ location,
+ });
+ }
+
+ let mut count: usize = 0;
+ let vars: *mut BNVariable = if let Some(int_args) = int_arg_registers {
+ let mut int_regs = vec![];
+ for r in int_args {
+ int_regs.push(r.id());
+ }
+
+ unsafe {
+ BNGetVariablesForParameters(
+ self.handle,
+ bn_params.as_ptr(),
+ bn_params.len(),
+ int_regs.as_ptr(),
+ int_regs.len(),
+ &mut count,
+ )
+ }
+ } else {
+ unsafe {
+ BNGetVariablesForParametersDefaultIntArgs(
+ self.handle,
+ bn_params.as_ptr(),
+ bn_params.len(),
+ &mut count,
+ )
+ }
+ };
+
+ let vars_slice = unsafe { slice::from_raw_parts(vars, count) };
+ let mut result = vec![];
+ for var in vars_slice {
+ result.push(unsafe { Variable::from_raw(*var) });
+ }
+
+ unsafe { BNFreeVariableList(vars) };
+ result
+ }
}
impl<A: Architecture> Eq for CallingConvention<A> {}
@@ -454,7 +514,9 @@ impl<A: Architecture> PartialEq for CallingConvention<A> {
}
}
+use crate::types::{FunctionParameter, Variable};
use std::hash::{Hash, Hasher};
+
impl<A: Architecture> Hash for CallingConvention<A> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.handle.hash(state);
diff --git a/rust/src/symbol.rs b/rust/src/symbol.rs
index 2d5df068..2578bee2 100644
--- a/rust/src/symbol.rs
+++ b/rust/src/symbol.rs
@@ -280,7 +280,7 @@ unsafe impl<'a> CoreArrayWrapper<'a> for Symbol {
impl PartialEq for Symbol {
fn eq(&self, other: &Self) -> bool {
- *self == *other
+ self.handle == other.handle
}
}
diff --git a/rust/src/types.rs b/rust/src/types.rs
index 790faca5..4f9d8bff 100644
--- a/rust/src/types.rs
+++ b/rust/src/types.rs
@@ -1315,7 +1315,7 @@ impl FunctionParameter<BnString> {
//////////////
// Variable
-#[derive(Clone, Copy, Debug)]
+#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub struct Variable {
pub t: BNVariableSourceType,
pub index: u32,