diff options
| author | Rubens Brandao <git@rubens.io> | 2023-11-22 18:57:28 -0300 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2024-02-02 13:32:45 -0500 |
| commit | f682ca69b356755fe6c06bcdd8f4fab73f7d2c78 (patch) | |
| tree | 3cfc324cfe8043ccc8db1161f1f90c448d097c8a /rust/src/function.rs | |
| parent | e1a6bdcd576f7caeaa6f97ff1e337a259057b333 (diff) | |
Rust API : Add HLIL Bindings
Diffstat (limited to 'rust/src/function.rs')
| -rw-r--r-- | rust/src/function.rs | 43 |
1 files changed, 38 insertions, 5 deletions
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<Ref<hlil::HighLevelILFunction>, ()> { + 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<Ref<mlil::MediumLevelILFunction>, ()> { 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<H: std::hash::Hasher>(&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 |
