diff options
| author | Mark Rowe <mrowe@bdash.net.nz> | 2025-05-27 13:35:46 -0700 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-05-30 19:17:10 -0400 |
| commit | abc355d98467bc1fce4368d4a7e1aff0e12cc3c3 (patch) | |
| tree | 14a007e2fa010bc93825c7b9e4cd4355f944a88c /rust/src/low_level_il | |
| parent | bcec9c097cd913a06d2877d958cc53065476a82c (diff) | |
[Rust] Support retrieving use / def of SSA registers in LLIL
Diffstat (limited to 'rust/src/low_level_il')
| -rw-r--r-- | rust/src/low_level_il/function.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/rust/src/low_level_il/function.rs b/rust/src/low_level_il/function.rs index 6bd1847a..8af89652 100644 --- a/rust/src/low_level_il/function.rs +++ b/rust/src/low_level_il/function.rs @@ -224,6 +224,57 @@ impl Ref<LowLevelILFunction<Mutable, NonSSA>> { } } +impl<M: FunctionMutability> Ref<LowLevelILFunction<M, SSA>> { + /// Return a vector of all instructions that use the given SSA register. + #[must_use] + pub fn get_ssa_register_uses<R: ArchReg>( + &self, + reg: LowLevelILSSARegisterKind<R>, + ) -> Vec<LowLevelILInstruction<M, SSA>> { + use binaryninjacore_sys::BNGetLowLevelILSSARegisterUses; + let register_id = match reg { + LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(), + LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(), + }; + let mut count = 0; + let instrs = unsafe { + BNGetLowLevelILSSARegisterUses( + self.handle, + register_id.into(), + reg.version() as usize, + &mut count, + ) + }; + let result = unsafe { std::slice::from_raw_parts(instrs, count) } + .iter() + .map(|idx| LowLevelILInstruction::new(self, LowLevelInstructionIndex(*idx))) + .collect(); + unsafe { BNFreeILInstructionList(instrs) }; + result + } + + /// Returns the instruction that defines the given SSA register. + #[must_use] + pub fn get_ssa_register_definition<R: ArchReg>( + &self, + reg: &LowLevelILSSARegisterKind<R>, + ) -> Option<LowLevelILInstruction<M, SSA>> { + use binaryninjacore_sys::BNGetLowLevelILSSARegisterDefinition; + let register_id = match reg { + LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(), + LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(), + }; + let instr_idx = unsafe { + BNGetLowLevelILSSARegisterDefinition( + self.handle, + register_id.into(), + reg.version() as usize, + ) + }; + self.instruction_from_index(LowLevelInstructionIndex(instr_idx)) + } +} + impl<M, F> ToOwned for LowLevelILFunction<M, F> where M: FunctionMutability, |
