summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorBrandon Miller <brandon@vector35.com>2025-04-25 13:30:45 -0400
committerRyan Snyder <ryan@vector35.com>2025-06-23 13:44:12 -0400
commitb079d1a1e19151f5c39de84c2e1e6cc6a91abc74 (patch)
tree8cf27224630b690fcfdfd490ee43ec1cd56fc9b6 /rust/src
parent76215b86ff629da58aa94d4cf4093d2e67017412 (diff)
Perform BB analysis from Architecture C++ API
This commit moves AnalyzeBasicBlocks from the binary ninja core to the API and allows architecture plugins to optionally override AnalyzeBasicBlocks for a custom implementation Supply ABB inputs in BNBasicBlockAnalysisContext Register default analyze basic blocks callback This allows the nanomips and rust core architecture plugins to work again while using the C++ API DefaultAnalyzeBasicBlocks Use default ABB from Python plugins Fix bug in API ArchAndAddr operator overload Python APIs for basic block analysis
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/architecture.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs
index 41150840..c716bb95 100644
--- a/rust/src/architecture.rs
+++ b/rust/src/architecture.rs
@@ -30,6 +30,7 @@ use crate::{
string::*,
types::{NameAndType, Type},
Endianness,
+ function::Function,
};
use std::ops::Deref;
use std::{
@@ -470,6 +471,19 @@ pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> {
il: &LowLevelILMutableFunction,
) -> Option<(usize, bool)>;
+ fn analyze_basic_blocks(
+ &self,
+ function: &mut Function,
+ context: *mut BNBasicBlockAnalysisContext,
+ ) {
+ unsafe {
+ BNArchitectureDefaultAnalyzeBasicBlocks(
+ function.handle,
+ context,
+ );
+ };
+ }
+
/// Fallback flag value calculation path. This method is invoked when the core is unable to
/// recover flag use semantics, and resorts to emitting instructions that explicitly set each
/// observed flag to the value of an expression returned by this function.
@@ -1533,6 +1547,20 @@ impl Architecture for CoreArchitecture {
}
}
+ fn analyze_basic_blocks(
+ &self,
+ function: &mut Function,
+ context: *mut BNBasicBlockAnalysisContext,
+ ) {
+ unsafe {
+ BNArchitectureAnalyzeBasicBlocks(
+ self.handle,
+ function.handle,
+ context,
+ );
+ };
+ }
+
fn flag_write_llil<'a>(
&self,
_flag: Self::Flag,
@@ -2237,6 +2265,19 @@ where
}
}
+ extern "C" fn cb_analyze_basic_blocks<A>(
+ ctxt: *mut c_void,
+ function: *mut BNFunction,
+ context: *mut BNBasicBlockAnalysisContext,
+ )
+ where
+ A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync,
+ {
+ let custom_arch = unsafe { &*(ctxt as *mut A) };
+ let mut function = unsafe { Function::from_raw(function) };
+ custom_arch.analyze_basic_blocks(&mut function, context);
+ }
+
extern "C" fn cb_reg_name<A>(ctxt: *mut c_void, reg: u32) -> *mut c_char
where
A: 'static + Architecture<Handle = CustomArchitectureHandle<A>> + Send + Sync,
@@ -3155,6 +3196,7 @@ where
getInstructionText: Some(cb_get_instruction_text::<A>),
freeInstructionText: Some(cb_free_instruction_text),
getInstructionLowLevelIL: Some(cb_instruction_llil::<A>),
+ analyzeBasicBlocks: Some(cb_analyze_basic_blocks::<A>),
getRegisterName: Some(cb_reg_name::<A>),
getFlagName: Some(cb_flag_name::<A>),