Skip to content

Commit 187c880

Browse files
committed
Add inlined unresolved indirect branches to rust BB analysis context
1 parent ac527f7 commit 187c880

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

rust/src/architecture.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,6 @@ pub struct BasicBlockAnalysisContext {
19521952
pub translate_tail_calls: bool,
19531953
pub disallow_branch_to_string: bool,
19541954
pub max_function_size: u64,
1955-
pub halt_on_invalid_instruction: bool,
19561955
pub max_size_reached: bool,
19571956

19581957
// In/Out
@@ -1962,6 +1961,7 @@ pub struct BasicBlockAnalysisContext {
19621961
direct_code_references: HashMap<u64, ArchAndAddr>,
19631962
direct_no_return_calls: HashSet<ArchAndAddr>,
19641963
halted_disassembly_addresses: HashSet<ArchAndAddr>,
1964+
inlined_unresolved_indirect_branches: HashSet<ArchAndAddr>,
19651965
}
19661966

19671967
impl BasicBlockAnalysisContext {
@@ -2021,6 +2021,15 @@ impl BasicBlockAnalysisContext {
20212021
})
20222022
.collect::<HashSet<_>>();
20232023

2024+
let inlined_unresolved_indirect_branches = (0..ctx_ref
2025+
.inlinedUnresolvedIndirectBranchCount)
2026+
.map(|i| {
2027+
let raw =
2028+
unsafe { std::ptr::read(ctx_ref.inlinedUnresolvedIndirectBranches.add(i)) };
2029+
ArchAndAddr::from(raw)
2030+
})
2031+
.collect::<HashSet<_>>();
2032+
20242033
BasicBlockAnalysisContext {
20252034
handle,
20262035
contextual_returns_dirty: false,
@@ -2030,12 +2039,12 @@ impl BasicBlockAnalysisContext {
20302039
translate_tail_calls: ctx_ref.translateTailCalls,
20312040
disallow_branch_to_string: ctx_ref.disallowBranchToString,
20322041
max_function_size: ctx_ref.maxFunctionSize,
2033-
halt_on_invalid_instruction: ctx_ref.haltOnInvalidInstructions,
20342042
max_size_reached: ctx_ref.maxSizeReached,
20352043
contextual_returns,
20362044
direct_code_references,
20372045
direct_no_return_calls,
20382046
halted_disassembly_addresses,
2047+
inlined_unresolved_indirect_branches,
20392048
}
20402049
}
20412050

@@ -2059,6 +2068,10 @@ impl BasicBlockAnalysisContext {
20592068
self.halted_disassembly_addresses.insert(loc);
20602069
}
20612070

2071+
pub fn add_inlined_unresolved_indirect_branch(&mut self, loc: ArchAndAddr) {
2072+
self.inlined_unresolved_indirect_branches.insert(loc);
2073+
}
2074+
20622075
pub fn create_basic_block(
20632076
&self,
20642077
arch: CoreArchitecture,
@@ -2135,6 +2148,21 @@ impl BasicBlockAnalysisContext {
21352148
}
21362149
}
21372150

2151+
if !self.inlined_unresolved_indirect_branches.is_empty() {
2152+
let total = self.inlined_unresolved_indirect_branches.len();
2153+
let mut locations: Vec<BNArchitectureAndAddress> = Vec::with_capacity(total);
2154+
for loc in &self.inlined_unresolved_indirect_branches {
2155+
locations.push(loc.into_raw());
2156+
}
2157+
unsafe {
2158+
BNAnalyzeBasicBlocksContextSetInlinedUnresolvedIndirectBranches(
2159+
self.handle,
2160+
locations.as_mut_ptr(),
2161+
total,
2162+
);
2163+
}
2164+
}
2165+
21382166
if self.contextual_returns_dirty {
21392167
let total = self.contextual_returns.len();
21402168
let mut locations: Vec<BNArchitectureAndAddress> = Vec::with_capacity(total);

0 commit comments

Comments
 (0)