From 9a9d7d98c2b49c734771397a8d37aca0279dfa21 Mon Sep 17 00:00:00 2001 From: Brandon Miller Date: Thu, 25 Sep 2025 08:55:34 -0400 Subject: Rust APIs needed for guided analysis mode Required for implementing guided analysis mode in custom implementations of analyze_basic_blocks --- rust/src/architecture.rs | 4 ++++ rust/src/basic_block.rs | 4 ++++ rust/src/function.rs | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) (limited to 'rust/src') diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 87182a56..1f37a4df 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -1949,6 +1949,8 @@ pub struct BasicBlockAnalysisContext { pub indirect_branches: Vec, pub indirect_no_return_calls: HashSet, pub analysis_skip_override: BNFunctionAnalysisSkipOverride, + pub guided_analysis_mode: bool, + pub trigger_guided_on_invalid_instruction: bool, pub translate_tail_calls: bool, pub disallow_branch_to_string: bool, pub max_function_size: u64, @@ -2036,6 +2038,8 @@ impl BasicBlockAnalysisContext { indirect_branches, indirect_no_return_calls, analysis_skip_override: ctx_ref.analysisSkipOverride, + guided_analysis_mode: ctx_ref.guidedAnalysisMode, + trigger_guided_on_invalid_instruction: ctx_ref.triggerGuidedOnInvalidInstruction, translate_tail_calls: ctx_ref.translateTailCalls, disallow_branch_to_string: ctx_ref.disallowBranchToString, max_function_size: ctx_ref.maxFunctionSize, diff --git a/rust/src/basic_block.rs b/rust/src/basic_block.rs index da41e712..d415b148 100644 --- a/rust/src/basic_block.rs +++ b/rust/src/basic_block.rs @@ -205,6 +205,10 @@ impl BasicBlock { } } + pub fn has_invalid_instructions(&self) -> bool { + unsafe { BNBasicBlockHasInvalidInstructions(self.handle) } + } + pub fn raw_length(&self) -> u64 { unsafe { BNGetBasicBlockLength(self.handle) } } diff --git a/rust/src/function.rs b/rust/src/function.rs index 692eb817..1a4add05 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -49,6 +49,7 @@ use crate::variable::{ StackVariableReference, Variable, }; use crate::workflow::Workflow; +use std::collections::HashSet; use std::ffi::CStr; use std::fmt::{Debug, Formatter}; use std::ptr::NonNull; @@ -2586,6 +2587,21 @@ impl Function { let key = key.to_cstr(); unsafe { BNFunctionRemoveMetadata(self.handle, key.as_ptr()) }; } + + pub fn guided_source_blocks(&self) -> HashSet { + let mut count = 0; + let raw = unsafe { BNGetGuidedSourceBlocks(self.handle, &mut count) }; + if raw.is_null() || count == 0 { + return HashSet::new(); + } + + (0..count) + .map(|i| { + let raw = unsafe { std::ptr::read(raw.add(i)) }; + ArchAndAddr::from(raw) + }) + .collect::>() + } } impl Debug for Function { -- cgit v1.3.1