Skip to content

Commit

Permalink
add HighLevelILFunction::ssa_variables method
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 27, 2024
1 parent 2bbf699 commit 72c9380
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rust/src/hlil/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@ impl HighLevelILFunction {
assert!(!variables.is_null());
unsafe { Array::new(variables, count, ()) }
}

/// This gets just the HLIL SSA variables - you may be interested in the union
/// of [crate::function::Function::parameter_variables] and
/// [crate::mlil::function::MediumLevelILFunction::aliased_variables] as well for all the
/// variables used in the function
pub fn ssa_variables(&self) -> Array<Array<SSAVariable>> {
let mut count = 0;
let variables = unsafe { BNGetHighLevelILVariables(self.handle, &mut count) };
assert!(!variables.is_null());
unsafe { Array::new(variables, count, self.to_owned()) }
}
}

impl ToOwned for HighLevelILFunction {
Expand Down
36 changes: 36 additions & 0 deletions rust/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
callingconvention::CallingConvention,
filemetadata::FileMetadata,
function::Function,
hlil::HighLevelILFunction,
rc::*,
string::{raw_to_string, BnStrCompatible, BnString},
symbol::Symbol,
Expand Down Expand Up @@ -1444,6 +1445,41 @@ impl SSAVariable {
}
}

impl CoreArrayProvider for SSAVariable {
type Raw = usize;
type Context = Variable;
type Wrapped<'a> = Self;
}

unsafe impl CoreArrayProviderInner for SSAVariable {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeILInstructionList(raw)
}

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
SSAVariable::new(*context, *raw)
}
}

impl CoreArrayProvider for Array<SSAVariable> {
type Raw = BNVariable;
type Context = Ref<HighLevelILFunction>;
type Wrapped<'a> = Self;
}

unsafe impl CoreArrayProviderInner for Array<SSAVariable> {
unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) {
BNFreeVariableList(raw)
}

unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
let mut count = 0;
let versions =
unsafe { BNGetHighLevelILVariableSSAVersions(context.handle, raw, &mut count) };
Array::new(versions, count, Variable::from_raw(*raw))
}
}

///////////////
// NamedVariable

Expand Down

0 comments on commit 72c9380

Please sign in to comment.