Skip to content

Commit 9a9d7d9

Browse files
committed
Rust APIs needed for guided analysis mode
Required for implementing guided analysis mode in custom implementations of analyze_basic_blocks
1 parent 63e37df commit 9a9d7d9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

rust/src/architecture.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,6 +1949,8 @@ pub struct BasicBlockAnalysisContext {
19491949
pub indirect_branches: Vec<IndirectBranchInfo>,
19501950
pub indirect_no_return_calls: HashSet<ArchAndAddr>,
19511951
pub analysis_skip_override: BNFunctionAnalysisSkipOverride,
1952+
pub guided_analysis_mode: bool,
1953+
pub trigger_guided_on_invalid_instruction: bool,
19521954
pub translate_tail_calls: bool,
19531955
pub disallow_branch_to_string: bool,
19541956
pub max_function_size: u64,
@@ -2036,6 +2038,8 @@ impl BasicBlockAnalysisContext {
20362038
indirect_branches,
20372039
indirect_no_return_calls,
20382040
analysis_skip_override: ctx_ref.analysisSkipOverride,
2041+
guided_analysis_mode: ctx_ref.guidedAnalysisMode,
2042+
trigger_guided_on_invalid_instruction: ctx_ref.triggerGuidedOnInvalidInstruction,
20392043
translate_tail_calls: ctx_ref.translateTailCalls,
20402044
disallow_branch_to_string: ctx_ref.disallowBranchToString,
20412045
max_function_size: ctx_ref.maxFunctionSize,

rust/src/basic_block.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ impl<C: BlockContext> BasicBlock<C> {
205205
}
206206
}
207207

208+
pub fn has_invalid_instructions(&self) -> bool {
209+
unsafe { BNBasicBlockHasInvalidInstructions(self.handle) }
210+
}
211+
208212
pub fn raw_length(&self) -> u64 {
209213
unsafe { BNGetBasicBlockLength(self.handle) }
210214
}

rust/src/function.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use crate::variable::{
4949
StackVariableReference, Variable,
5050
};
5151
use crate::workflow::Workflow;
52+
use std::collections::HashSet;
5253
use std::ffi::CStr;
5354
use std::fmt::{Debug, Formatter};
5455
use std::ptr::NonNull;
@@ -2586,6 +2587,21 @@ impl Function {
25862587
let key = key.to_cstr();
25872588
unsafe { BNFunctionRemoveMetadata(self.handle, key.as_ptr()) };
25882589
}
2590+
2591+
pub fn guided_source_blocks(&self) -> HashSet<ArchAndAddr> {
2592+
let mut count = 0;
2593+
let raw = unsafe { BNGetGuidedSourceBlocks(self.handle, &mut count) };
2594+
if raw.is_null() || count == 0 {
2595+
return HashSet::new();
2596+
}
2597+
2598+
(0..count)
2599+
.map(|i| {
2600+
let raw = unsafe { std::ptr::read(raw.add(i)) };
2601+
ArchAndAddr::from(raw)
2602+
})
2603+
.collect::<HashSet<_>>()
2604+
}
25892605
}
25902606

25912607
impl Debug for Function {

0 commit comments

Comments
 (0)