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/high_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/high_level_il/function.rs')
| -rw-r--r-- | rust/src/high_level_il/function.rs | 21 |
1 files changed, 13 insertions, 8 deletions
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<HighLevelILInstruction> { 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) { |
