From f682ca69b356755fe6c06bcdd8f4fab73f7d2c78 Mon Sep 17 00:00:00 2001 From: Rubens Brandao Date: Wed, 22 Nov 2023 18:57:28 -0300 Subject: Rust API : Add HLIL Bindings --- rust/src/llil/function.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'rust/src/llil/function.rs') diff --git a/rust/src/llil/function.rs b/rust/src/llil/function.rs index 46d3e6d1..f0aba63a 100644 --- a/rust/src/llil/function.rs +++ b/rust/src/llil/function.rs @@ -13,6 +13,7 @@ // limitations under the License. use binaryninjacore_sys::BNFreeLowLevelILFunction; +use binaryninjacore_sys::BNGetLowLevelILOwnerFunction; use binaryninjacore_sys::BNLowLevelILFunction; use binaryninjacore_sys::BNNewLowLevelILFunctionReference; @@ -65,14 +66,14 @@ unsafe impl Sync for Fu impl Eq for Function {} impl PartialEq for Function { fn eq(&self, rhs: &Self) -> bool { - self.handle == rhs.handle + self.get_function().eq(&rhs.get_function()) } } use std::hash::{Hash, Hasher}; impl Hash for Function { fn hash(&self, state: &mut H) { - self.handle.hash(state); + self.get_function().hash(state) } } @@ -82,7 +83,10 @@ where M: FunctionMutability, F: FunctionForm, { - pub(crate) unsafe fn from_raw(borrower: A::Handle, handle: *mut BNLowLevelILFunction) -> Self { + pub(crate) unsafe fn from_raw( + borrower: A::Handle, + handle: *mut BNLowLevelILFunction, + ) -> Ref { debug_assert!(!handle.is_null()); Self { @@ -92,6 +96,7 @@ where _mutability: PhantomData, _form: PhantomData, } + .to_owned() } pub(crate) fn arch(&self) -> &A { @@ -139,6 +144,13 @@ where BNGetLowLevelILInstructionCount(self.handle) } } + + pub fn get_function(&self) -> Ref { + unsafe { + let func = BNGetLowLevelILOwnerFunction(self.handle); + crate::function::Function::from_raw(func) + } + } } // LLIL basic blocks are not available until the function object -- cgit v1.3.1