diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-30 16:39:32 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-05-30 19:17:10 -0400 |
| commit | 68b00cdf45551ba64c4f7217963055fc5a1a0cc4 (patch) | |
| tree | f6bdef06bc02d16596bdf62870c8a1cfafe49859 /rust/src/medium_level_il/function.rs | |
| parent | 77ab5e812af200b8e3bca0aac31d5fe0f638fba3 (diff) | |
[Rust] Express expression vs instruction index for MLIL and HLIL APIs
This was done to fix unintended behavior using an instruction or expression index in place of the other.
Fixes https://github.com/Vector35/binaryninja-api/issues/6897
Diffstat (limited to 'rust/src/medium_level_il/function.rs')
| -rw-r--r-- | rust/src/medium_level_il/function.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/rust/src/medium_level_il/function.rs b/rust/src/medium_level_il/function.rs index bdbe3159..8751111b 100644 --- a/rust/src/medium_level_il/function.rs +++ b/rust/src/medium_level_il/function.rs @@ -2,7 +2,10 @@ use binaryninjacore_sys::*; use std::fmt::{Debug, Formatter}; use std::hash::{Hash, Hasher}; -use super::{MediumLevelILBlock, MediumLevelILInstruction, MediumLevelInstructionIndex}; +use super::{ + MediumLevelExpressionIndex, MediumLevelILBlock, MediumLevelILInstruction, + MediumLevelInstructionIndex, +}; use crate::architecture::CoreArchitecture; use crate::basic_block::BasicBlock; use crate::confidence::Conf; @@ -33,7 +36,7 @@ impl MediumLevelILFunction { } pub fn instruction_at<L: Into<Location>>(&self, loc: L) -> Option<MediumLevelILInstruction> { - Some(MediumLevelILInstruction::new( + Some(MediumLevelILInstruction::from_instr_index( self.to_owned(), self.instruction_index_at(loc)?, )) @@ -64,18 +67,21 @@ impl MediumLevelILFunction { if index.0 >= self.instruction_count() { None } else { - Some(MediumLevelILInstruction::new(self.to_owned(), index)) + Some(MediumLevelILInstruction::from_instr_index( + self.to_owned(), + index, + )) } } pub fn instruction_from_expr_index( &self, - expr_index: MediumLevelInstructionIndex, + expr_index: MediumLevelExpressionIndex, ) -> Option<MediumLevelILInstruction> { if expr_index.0 >= self.expression_count() { None } else { - Some(MediumLevelILInstruction::new_expr( + Some(MediumLevelILInstruction::from_expr_index( self.to_owned(), expr_index, )) @@ -402,7 +408,7 @@ impl MediumLevelILFunction { unsafe { BNMediumLevelILSetCurrentAddress(self.handle, arch, location.addr) } } - /// Returns the [`BasicBlock`] at the given instruction `index`. + /// Returns the [`BasicBlock`] at the given instruction `index`. Function must be finalized. /// /// You can also retrieve this using [`MediumLevelILInstruction::basic_block`]. pub fn basic_block_containing_index( |
