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/function.rs | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'rust/src/function.rs') diff --git a/rust/src/function.rs b/rust/src/function.rs index 93af0dd9..7f9ad862 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -21,12 +21,13 @@ use crate::{ architecture::CoreArchitecture, basicblock::{BasicBlock, BlockContext}, binaryview::{BinaryView, BinaryViewExt}, - llil, mlil, + hlil, llil, mlil, platform::Platform, symbol::Symbol, types::{Conf, NamedTypedVariable, Type}, }; +use std::hash::Hash; use std::{fmt, mem}; pub struct Location { @@ -108,7 +109,7 @@ impl BlockContext for NativeBlock { } } -#[derive(PartialEq, Eq, Hash)] +#[derive(Eq)] pub struct Function { pub(crate) handle: *mut BNFunction, } @@ -225,6 +226,18 @@ impl Function { } } + pub fn high_level_il(&self, full_ast: bool) -> Result, ()> { + unsafe { + let hlil = BNGetFunctionHighLevelIL(self.handle); + + if hlil.is_null() { + return Err(()); + } + + Ok(hlil::HighLevelILFunction::ref_from_raw(hlil, full_ast)) + } + } + pub fn medium_level_il(&self) -> Result, ()> { unsafe { let mlil = BNGetFunctionMediumLevelIL(self.handle); @@ -233,7 +246,7 @@ impl Function { return Err(()); } - Ok(Ref::new(mlil::MediumLevelILFunction::from_raw(mlil))) + Ok(mlil::MediumLevelILFunction::ref_from_raw(mlil)) } } @@ -245,7 +258,7 @@ impl Function { return Err(()); } - Ok(Ref::new(llil::RegularFunction::from_raw(self.arch(), llil))) + Ok(llil::RegularFunction::from_raw(self.arch(), llil)) } } @@ -257,7 +270,7 @@ impl Function { return Err(()); } - Ok(Ref::new(llil::LiftedFunction::from_raw(self.arch(), llil))) + Ok(llil::LiftedFunction::from_raw(self.arch(), llil)) } } @@ -354,6 +367,26 @@ unsafe impl<'a> CoreArrayWrapper<'a> for Function { } } +impl Hash for Function { + fn hash(&self, state: &mut H) { + let start_address = self.start(); + let architecture = self.arch(); + let platform = self.platform(); + (start_address, architecture, platform).hash(state) + } +} + +impl PartialEq for Function { + fn eq(&self, other: &Self) -> bool { + if self.handle == other.handle { + return true; + } + self.start() == other.start() + && self.arch() == other.arch() + && self.platform() == other.platform() + } +} + ///////////////// // AddressRange -- cgit v1.3.1