Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify BlockContext #5370

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rust/src/basicblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ pub trait BlockContext: Clone + Sync + Send + Sized {
type Instruction;
type Iter: Iterator<Item = Self::Instruction>;

fn start(&self, block: &BasicBlock<Self>) -> Self::Instruction;
fn iter(&self, block: &BasicBlock<Self>) -> Self::Iter;
fn start(block: &BasicBlock<Self>) -> Self::Instruction;
fn iter(block: &BasicBlock<Self>) -> Self::Iter;
}

#[derive(PartialEq, Eq, Hash)]
pub struct BasicBlock<C: BlockContext> {
pub(crate) handle: *mut BNBasicBlock,
context: C,
pub(crate) context: C,
}

unsafe impl<C: BlockContext> Send for BasicBlock<C> {}
Expand All @@ -144,7 +144,7 @@ impl<C: BlockContext> BasicBlock<C> {
}

pub fn iter(&self) -> C::Iter {
self.context.iter(self)
C::iter(self)
}

pub fn raw_start(&self) -> u64 {
Expand Down
4 changes: 2 additions & 2 deletions rust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ impl BlockContext for NativeBlock {
type Iter = NativeBlockIter;
type Instruction = u64;

fn start(&self, block: &BasicBlock<Self>) -> u64 {
fn start(block: &BasicBlock<Self>) -> u64 {
block.raw_start()
}

fn iter(&self, block: &BasicBlock<Self>) -> NativeBlockIter {
fn iter(block: &BasicBlock<Self>) -> NativeBlockIter {
NativeBlockIter {
arch: block.arch(),
bv: block.function().view(),
Expand Down
13 changes: 8 additions & 5 deletions rust/src/hlil/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ impl BlockContext for HighLevelILBlock {
type Iter = HighLevelILBlockIter;
type Instruction = HighLevelILInstruction;

fn start(&self, block: &BasicBlock<Self>) -> HighLevelILInstruction {
fn start(block: &BasicBlock<Self>) -> 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<Self>) -> HighLevelILBlockIter {
fn iter(block: &BasicBlock<Self>) -> HighLevelILBlockIter {
HighLevelILBlockIter {
function: self.function.to_owned(),
function: block.context.function.to_owned(),
range: block.raw_start()..block.raw_end(),
}
}
Expand Down
8 changes: 4 additions & 4 deletions rust/src/llil/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ where
type Iter = BlockIter<'func, A, M, F>;
type Instruction = Instruction<'func, A, M, F>;

fn start(&self, block: &BasicBlock<Self>) -> Instruction<'func, A, M, F> {
fn start(block: &BasicBlock<Self>) -> 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<Self>) -> BlockIter<'func, A, M, F> {
fn iter(block: &BasicBlock<Self>) -> BlockIter<'func, A, M, F> {
BlockIter {
function: self.function,
function: block.context.function,
range: block.raw_start()..block.raw_end(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/llil/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions rust/src/mlil/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ impl BlockContext for MediumLevelILBlock {
type Iter = MediumLevelILBlockIter;
type Instruction = MediumLevelILInstruction;

fn start(&self, block: &BasicBlock<Self>) -> MediumLevelILInstruction {
fn start(block: &BasicBlock<Self>) -> 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<Self>) -> MediumLevelILBlockIter {
fn iter(block: &BasicBlock<Self>) -> MediumLevelILBlockIter {
MediumLevelILBlockIter {
function: self.function.to_owned(),
function: block.context.function.to_owned(),
range: block.raw_start()..block.raw_end(),
}
}
Expand Down
Loading