From 68b00cdf45551ba64c4f7217963055fc5a1a0cc4 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 30 May 2025 16:39:32 -0400 Subject: [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 --- rust/src/high_level_il/function.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'rust/src/high_level_il/function.rs') diff --git a/rust/src/high_level_il/function.rs b/rust/src/high_level_il/function.rs index a65a244c..0a55470e 100644 --- a/rust/src/high_level_il/function.rs +++ b/rust/src/high_level_il/function.rs @@ -3,7 +3,9 @@ use std::hash::{Hash, Hasher}; use binaryninjacore_sys::*; -use super::{HighLevelILBlock, HighLevelILInstruction, HighLevelInstructionIndex}; +use super::{ + HighLevelExpressionIndex, HighLevelILBlock, HighLevelILInstruction, HighLevelInstructionIndex, +}; use crate::basic_block::BasicBlock; use crate::function::{Function, Location}; use crate::rc::{Array, Ref, RefCountable}; @@ -35,31 +37,34 @@ impl HighLevelILFunction { if index.0 >= self.instruction_count() { None } else { - Some(HighLevelILInstruction::new(self.to_owned(), index)) + Some(HighLevelILInstruction::from_instr_index( + self.to_owned(), + index, + )) } } pub fn instruction_from_expr_index( &self, - expr_index: HighLevelInstructionIndex, + expr_index: HighLevelExpressionIndex, ) -> Option { if expr_index.0 >= self.expression_count() { None } else { - Some(HighLevelILInstruction::new_expr( + Some(HighLevelILInstruction::from_expr_index( self.to_owned(), expr_index, )) } } - // TODO: This returns an expression index! - pub fn root_instruction_index(&self) -> HighLevelInstructionIndex { - HighLevelInstructionIndex(unsafe { BNGetHighLevelILRootExpr(self.handle) }) + pub fn root_expression_index(&self) -> HighLevelExpressionIndex { + HighLevelExpressionIndex(unsafe { BNGetHighLevelILRootExpr(self.handle) }) } pub fn root(&self) -> HighLevelILInstruction { - HighLevelILInstruction::new_expr(self.as_ast(), self.root_instruction_index()) + self.instruction_from_expr_index(self.root_expression_index()) + .expect("Invalid root expression index") } pub fn set_root(&self, new_root: &HighLevelILInstruction) { -- cgit v1.3.1