Skip to content

Commit 4ed524d

Browse files
committed
Add inline remapping for function lifter
1 parent fa6ceb7 commit 4ed524d

2 files changed

Lines changed: 57 additions & 3 deletions

File tree

rust/src/architecture.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ pub struct FunctionLifterContext {
600600
pub blocks: Vec<Ref<BasicBlock<NativeBlock>>>,
601601
pub no_return_calls: HashSet<Location>,
602602
pub contextual_returns: HashMap<Location, bool>,
603-
//pub inline_remapping: HashMap<ArchAndAddr, ArchAndAddr>>,
604-
//pub user_indirect_branches: HashMap<ArchAndAddr, HashSet<ArchAndAddr>>>,
605-
//pub auto_indirect_branches: HashMap<ArchAndAddr, HashSet<ArchAndAddr>>>,
603+
pub inlined_remapping: HashMap<Location, Location>,
604+
pub user_indirect_branches: HashMap<Location, HashSet<Location>>,
605+
pub auto_indirect_branches: HashMap<Location, HashSet<Location>>,
606606
//pub inlined_calls: HashSet<u64>,
607607
}
608608

@@ -651,6 +651,43 @@ impl FunctionLifterContext {
651651
.zip(raw_contextual_return_vals.iter().copied())
652652
.collect();
653653

654+
let inlined_remapping: HashMap<Location, Location> = {
655+
let raw_inline_remap_locs: &[BNArchitectureAndAddress] = std::slice::from_raw_parts(
656+
flc_ref.inlinedRemappingKeys,
657+
flc_ref.inlinedRemappingEntryCount,
658+
);
659+
660+
let raw_inline_remap_dests: &[BNArchitectureAndAddress] = std::slice::from_raw_parts(
661+
flc_ref.inlinedRemappingValues,
662+
flc_ref.inlinedRemappingEntryCount,
663+
);
664+
665+
raw_inline_remap_locs
666+
.iter()
667+
.map(Location::from)
668+
.zip(raw_inline_remap_dests.iter().map(Location::from))
669+
.collect()
670+
};
671+
672+
let mut user_indirect_branches: HashMap<Location, HashSet<Location>> = HashMap::new();
673+
let mut auto_indirect_branches: HashMap<Location, HashSet<Location>> = HashMap::new();
674+
for i in 0..flc_ref.indirectBranchesCount {
675+
let entry = unsafe { *flc_ref.indirectBranches.add(i) };
676+
let src = Location::new(Some(CoreArchitecture::from_raw(entry.sourceArch)), entry.sourceAddr);
677+
let dest = Location::new(Some(CoreArchitecture::from_raw(entry.destArch)), entry.destAddr);
678+
if entry.autoDefined {
679+
auto_indirect_branches
680+
.entry(src)
681+
.or_insert_with(HashSet::new)
682+
.insert(dest);
683+
} else {
684+
user_indirect_branches
685+
.entry(src)
686+
.or_insert_with(HashSet::new)
687+
.insert(dest);
688+
}
689+
}
690+
654691
FunctionLifterContext {
655692
handle,
656693
function: BNNewLowLevelILFunctionReference(function),
@@ -659,6 +696,9 @@ impl FunctionLifterContext {
659696
blocks,
660697
no_return_calls,
661698
contextual_returns,
699+
inlined_remapping,
700+
user_indirect_branches,
701+
auto_indirect_branches,
662702
}
663703
}
664704

rust/src/low_level_il/function.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ where
209209
Some(unsafe { BasicBlock::ref_from_raw(block, LowLevelILBlock { function: self }) })
210210
}
211211
}
212+
213+
pub fn set_indirect_branches(&self, branches: &Vec<Location>) {
214+
let mut bn_branches: Box<[BNArchitectureAndAddress]> = branches
215+
.iter()
216+
.map(|loc| BNArchitectureAndAddress {
217+
address: loc.addr,
218+
arch: self.arch().handle,
219+
})
220+
.collect();
221+
222+
unsafe {
223+
BNLowLevelILSetIndirectBranches(self.handle, bn_branches.as_mut_ptr(), branches.len());
224+
}
225+
}
212226
}
213227

214228
impl<M: FunctionMutability> LowLevelILFunction<M, NonSSA> {

0 commit comments

Comments
 (0)