update
This commit is contained in:
@@ -21,12 +21,17 @@ use crate::{
|
||||
architecture::CoreArchitecture,
|
||||
basicblock::{BasicBlock, BlockContext},
|
||||
binaryview::{BinaryView, BinaryViewExt},
|
||||
llil, mlil,
|
||||
hlil, llil, mlil,
|
||||
platform::Platform,
|
||||
symbol::Symbol,
|
||||
types::{Conf, NamedTypedVariable, Type},
|
||||
};
|
||||
pub use binaryninjacore_sys::BNAnalysisSkipReason as AnalysisSkipReason;
|
||||
pub use binaryninjacore_sys::BNFunctionAnalysisSkipOverride as FunctionAnalysisSkipOverride;
|
||||
pub use binaryninjacore_sys::BNFunctionUpdateType as FunctionUpdateType;
|
||||
|
||||
|
||||
use std::hash::Hash;
|
||||
use std::{fmt, mem};
|
||||
|
||||
pub struct Location {
|
||||
@@ -108,7 +113,7 @@ impl BlockContext for NativeBlock {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
#[derive(Eq)]
|
||||
pub struct Function {
|
||||
pub(crate) handle: *mut BNFunction,
|
||||
}
|
||||
@@ -178,6 +183,16 @@ impl Function {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_can_return_auto<T: Into<Conf<bool>>>(&self, can_return: T) {
|
||||
let mut bool_with_confidence = can_return.into().into();
|
||||
unsafe { BNSetAutoFunctionCanReturn(self.handle, &mut bool_with_confidence) }
|
||||
}
|
||||
|
||||
pub fn set_can_return_user<T: Into<Conf<bool>>>(&self, can_return: T) {
|
||||
let mut bool_with_confidence = can_return.into().into();
|
||||
unsafe { BNSetAutoFunctionCanReturn(self.handle, &mut bool_with_confidence) }
|
||||
}
|
||||
|
||||
pub fn comment_at(&self, addr: u64) -> BnString {
|
||||
unsafe { BnString::from_raw(BNGetCommentForAddress(self.handle, addr)) }
|
||||
}
|
||||
@@ -225,6 +240,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 +260,7 @@ impl Function {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(Ref::new(mlil::MediumLevelILFunction::from_raw(mlil)))
|
||||
Ok(mlil::MediumLevelILFunction::ref_from_raw(mlil))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +272,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 +284,7 @@ impl Function {
|
||||
return Err(());
|
||||
}
|
||||
|
||||
Ok(Ref::new(llil::LiftedFunction::from_raw(self.arch(), llil)))
|
||||
Ok(llil::LiftedFunction::from_raw(self.arch(), llil))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,6 +328,40 @@ impl Function {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analysis_skipped(&self) -> bool {
|
||||
unsafe { BNIsFunctionAnalysisSkipped(self.handle) }
|
||||
}
|
||||
|
||||
pub fn set_analysis_skipped(&self, skip: bool) {
|
||||
if skip {
|
||||
unsafe {
|
||||
BNSetFunctionAnalysisSkipOverride(
|
||||
self.handle,
|
||||
BNFunctionAnalysisSkipOverride::AlwaysSkipFunctionAnalysis,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
BNSetFunctionAnalysisSkipOverride(
|
||||
self.handle,
|
||||
BNFunctionAnalysisSkipOverride::NeverSkipFunctionAnalysis,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn analysis_skip_reason(&self) -> AnalysisSkipReason {
|
||||
unsafe { BNGetAnalysisSkipReason(self.handle) }
|
||||
}
|
||||
|
||||
pub fn analysis_skip_override(&self) -> FunctionAnalysisSkipOverride {
|
||||
unsafe { BNGetFunctionAnalysisSkipOverride(self.handle) }
|
||||
}
|
||||
|
||||
pub fn set_analysis_skip_override(&self, override_: FunctionAnalysisSkipOverride) {
|
||||
unsafe { BNSetFunctionAnalysisSkipOverride(self.handle, override_) }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Function {
|
||||
@@ -354,6 +415,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user