From 1c01b00d87e45c7ae8eb6320b20e7dcf67915d77 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Thu, 10 Jul 2025 01:32:32 -0400 Subject: Move LLIL instruction retrieval into the LLIL function where it belongs The python API was kept the same seeing as we are close to the release, will likely start deprecating some of those API's soon. --- rust/src/low_level_il/instruction.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'rust/src/low_level_il/instruction.rs') diff --git a/rust/src/low_level_il/instruction.rs b/rust/src/low_level_il/instruction.rs index 04a1d2d5..2d96d121 100644 --- a/rust/src/low_level_il/instruction.rs +++ b/rust/src/low_level_il/instruction.rs @@ -13,16 +13,16 @@ // limitations under the License. use crate::basic_block::BasicBlock; -use crate::rc::Ref; +use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Ref}; use super::block::LowLevelILBlock; use super::operation; use super::operation::Operation; use super::VisitorAction; use super::*; -use binaryninjacore_sys::BNGetLowLevelILByIndex; use binaryninjacore_sys::BNGetLowLevelILIndexForInstruction; use binaryninjacore_sys::BNLowLevelILInstruction; +use binaryninjacore_sys::{BNFreeILInstructionList, BNGetLowLevelILByIndex}; use std::fmt::{Debug, Display, Formatter}; #[repr(transparent)] @@ -53,6 +53,22 @@ impl Display for LowLevelInstructionIndex { } } +impl CoreArrayProvider for LowLevelInstructionIndex { + type Raw = usize; + type Context = (); + type Wrapped<'a> = Self; +} + +unsafe impl CoreArrayProviderInner for LowLevelInstructionIndex { + unsafe fn free(raw: *mut Self::Raw, _count: usize, _context: &Self::Context) { + BNFreeILInstructionList(raw) + } + + unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, _context: &'a Self::Context) -> Self::Wrapped<'a> { + Self::from(*raw) + } +} + // TODO: Probably want to rename this with a LowLevelIL prefix to avoid collisions when we add handlers for other ILs pub trait InstructionHandler<'func, M, F> where -- cgit v1.3.1