Skip to content
Closed
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
15 changes: 15 additions & 0 deletions rust/src/low_level_il/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ where
Array::new(blocks, count, context)
}
}

/// Returns the [`BasicBlock`] at the given instruction `index`.
///
/// You can also retrieve this using [`LowLevelILInstruction::basic_block`].
pub fn basic_block_containing_index(
&self,
index: LowLevelInstructionIndex,
) -> Option<Ref<BasicBlock<LowLevelILBlock<M, F>>>> {
let block = unsafe { BNGetLowLevelILBasicBlockForInstruction(self.handle, index.0) };
if block.is_null() {
None
} else {
Some(unsafe { BasicBlock::ref_from_raw(block, LowLevelILBlock { function: self }) })
}
}
}

impl<M: FunctionMutability> LowLevelILFunction<M, NonSSA> {
Expand Down
10 changes: 10 additions & 0 deletions rust/src/low_level_il/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::basic_block::BasicBlock;
use crate::rc::Ref;

use super::block::LowLevelILBlock;
use super::operation;
use super::operation::Operation;
use super::VisitorAction;
Expand Down Expand Up @@ -98,6 +102,12 @@ where
pub fn into_raw(&self) -> BNLowLevelILInstruction {
unsafe { BNGetLowLevelILByIndex(self.function.handle, self.expr_idx().0) }
}

/// Returns the [`BasicBlock`] containing the given [`LowLevelILInstruction`].
pub fn basic_block(&self) -> Option<Ref<BasicBlock<LowLevelILBlock<'func, M, F>>>> {
// TODO: We might be able to .expect this if we guarantee that self.index is valid.
self.function.basic_block_containing_index(self.index)
}
}

impl<M, F> Debug for LowLevelILInstruction<'_, M, F>
Expand Down
Loading