diff options
| author | Rubens Brandao <git@rubens.io> | 2023-11-18 15:58:33 -0300 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2023-11-21 15:18:50 -0500 |
| commit | 8c9cdd38c3302280087c9e6d94f7f57083885edd (patch) | |
| tree | 8bccf380b4470e0de8ac11c23b164e0acf6ffbb0 /rust/src/mlil/block.rs | |
| parent | b040fcfce48db861600eeb122cd0e2ff802fac96 (diff) | |
add mlil to rust
Diffstat (limited to 'rust/src/mlil/block.rs')
| -rw-r--r-- | rust/src/mlil/block.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/rust/src/mlil/block.rs b/rust/src/mlil/block.rs new file mode 100644 index 00000000..734d6512 --- /dev/null +++ b/rust/src/mlil/block.rs @@ -0,0 +1,63 @@ +use std::ops::Range; + +use binaryninjacore_sys::BNGetMediumLevelILIndexForInstruction; + +use crate::basicblock::{BasicBlock, BlockContext}; +use crate::rc::Ref; + +use super::{MediumLevelILFunction, MediumLevelILInstruction}; + +pub struct MediumLevelILBlockIter { + function: Ref<MediumLevelILFunction>, + range: Range<u64>, +} + +impl Iterator for MediumLevelILBlockIter { + type Item = MediumLevelILInstruction; + + fn next(&mut self) -> Option<Self::Item> { + self.range + .next() + .map(|i| unsafe { + BNGetMediumLevelILIndexForInstruction(self.function.handle, i as usize) + }) + .map(|i| MediumLevelILInstruction::new(&self.function, i)) + } +} + +pub struct MediumLevelILBlock { + pub(crate) function: Ref<MediumLevelILFunction>, +} + +impl core::fmt::Debug for MediumLevelILBlock { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, "mlil_bb {:?}", self.function) + } +} + +impl BlockContext for MediumLevelILBlock { + type Iter = MediumLevelILBlockIter; + type Instruction = MediumLevelILInstruction; + + fn start(&self, block: &BasicBlock<Self>) -> MediumLevelILInstruction { + let expr_idx = unsafe { + BNGetMediumLevelILIndexForInstruction(self.function.handle, block.raw_start() as usize) + }; + MediumLevelILInstruction::new(&self.function, expr_idx) + } + + fn iter(&self, block: &BasicBlock<Self>) -> MediumLevelILBlockIter { + MediumLevelILBlockIter { + function: self.function.to_owned(), + range: block.raw_start()..block.raw_end(), + } + } +} + +impl Clone for MediumLevelILBlock { + fn clone(&self) -> Self { + MediumLevelILBlock { + function: self.function.to_owned(), + } + } +} |
