diff --git a/rust/src/basicblock.rs b/rust/src/basicblock.rs index f28e596f1..f4f84ea35 100644 --- a/rust/src/basicblock.rs +++ b/rust/src/basicblock.rs @@ -110,14 +110,14 @@ pub trait BlockContext: Clone + Sync + Send + Sized { type Instruction; type Iter: Iterator; - fn start(&self, block: &BasicBlock) -> Self::Instruction; - fn iter(&self, block: &BasicBlock) -> Self::Iter; + fn start(block: &BasicBlock) -> Self::Instruction; + fn iter(block: &BasicBlock) -> Self::Iter; } #[derive(PartialEq, Eq, Hash)] pub struct BasicBlock { pub(crate) handle: *mut BNBasicBlock, - context: C, + pub(crate) context: C, } unsafe impl Send for BasicBlock {} @@ -144,7 +144,7 @@ impl BasicBlock { } pub fn iter(&self) -> C::Iter { - self.context.iter(self) + C::iter(self) } pub fn raw_start(&self) -> u64 { diff --git a/rust/src/function.rs b/rust/src/function.rs index 74e05ea55..c1c53adbd 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -98,11 +98,11 @@ impl BlockContext for NativeBlock { type Iter = NativeBlockIter; type Instruction = u64; - fn start(&self, block: &BasicBlock) -> u64 { + fn start(block: &BasicBlock) -> u64 { block.raw_start() } - fn iter(&self, block: &BasicBlock) -> NativeBlockIter { + fn iter(block: &BasicBlock) -> NativeBlockIter { NativeBlockIter { arch: block.arch(), bv: block.function().view(), diff --git a/rust/src/hlil/block.rs b/rust/src/hlil/block.rs index 0bbedd182..7e3a194f3 100644 --- a/rust/src/hlil/block.rs +++ b/rust/src/hlil/block.rs @@ -39,16 +39,19 @@ impl BlockContext for HighLevelILBlock { type Iter = HighLevelILBlockIter; type Instruction = HighLevelILInstruction; - fn start(&self, block: &BasicBlock) -> HighLevelILInstruction { + fn start(block: &BasicBlock) -> HighLevelILInstruction { let expr_idx = unsafe { - BNGetHighLevelILIndexForInstruction(self.function.handle, block.raw_start() as usize) + BNGetHighLevelILIndexForInstruction( + block.context.function.handle, + block.raw_start() as usize, + ) }; - HighLevelILInstruction::new(self.function.to_owned(), expr_idx) + HighLevelILInstruction::new(block.context.function.to_owned(), expr_idx) } - fn iter(&self, block: &BasicBlock) -> HighLevelILBlockIter { + fn iter(block: &BasicBlock) -> HighLevelILBlockIter { HighLevelILBlockIter { - function: self.function.to_owned(), + function: block.context.function.to_owned(), range: block.raw_start()..block.raw_end(), } } diff --git a/rust/src/llil/block.rs b/rust/src/llil/block.rs index d904d2d8d..8c3b7369d 100644 --- a/rust/src/llil/block.rs +++ b/rust/src/llil/block.rs @@ -74,16 +74,16 @@ where type Iter = BlockIter<'func, A, M, F>; type Instruction = Instruction<'func, A, M, F>; - fn start(&self, block: &BasicBlock) -> Instruction<'func, A, M, F> { + fn start(block: &BasicBlock) -> Instruction<'func, A, M, F> { Instruction { - function: self.function, + function: block.context.function, instr_idx: block.raw_start() as usize, } } - fn iter(&self, block: &BasicBlock) -> BlockIter<'func, A, M, F> { + fn iter(block: &BasicBlock) -> BlockIter<'func, A, M, F> { BlockIter { - function: self.function, + function: block.context.function, range: block.raw_start()..block.raw_end(), } } diff --git a/rust/src/llil/mod.rs b/rust/src/llil/mod.rs index b9424e860..8bbb2f5ba 100644 --- a/rust/src/llil/mod.rs +++ b/rust/src/llil/mod.rs @@ -24,7 +24,7 @@ use crate::architecture::Architecture; use crate::architecture::Register as ArchReg; use crate::function::Location; -mod block; +pub(crate) mod block; mod expression; mod function; mod instruction; diff --git a/rust/src/mlil/block.rs b/rust/src/mlil/block.rs index 015c7ba4e..9282b5b61 100644 --- a/rust/src/mlil/block.rs +++ b/rust/src/mlil/block.rs @@ -39,16 +39,19 @@ impl BlockContext for MediumLevelILBlock { type Iter = MediumLevelILBlockIter; type Instruction = MediumLevelILInstruction; - fn start(&self, block: &BasicBlock) -> MediumLevelILInstruction { + fn start(block: &BasicBlock) -> MediumLevelILInstruction { let expr_idx = unsafe { - BNGetMediumLevelILIndexForInstruction(self.function.handle, block.raw_start() as usize) + BNGetMediumLevelILIndexForInstruction( + block.context.function.handle, + block.raw_start() as usize, + ) }; - MediumLevelILInstruction::new(self.function.to_owned(), expr_idx) + MediumLevelILInstruction::new(block.context.function.to_owned(), expr_idx) } - fn iter(&self, block: &BasicBlock) -> MediumLevelILBlockIter { + fn iter(block: &BasicBlock) -> MediumLevelILBlockIter { MediumLevelILBlockIter { - function: self.function.to_owned(), + function: block.context.function.to_owned(), range: block.raw_start()..block.raw_end(), } }