From 462276a4aa998e0b0ef804dd8d3b2eaa84a82f98 Mon Sep 17 00:00:00 2001 From: Michael Krasnitski Date: Tue, 27 Feb 2024 14:26:56 -0500 Subject: Move `ILFunction` trait into `operand_iter.rs` to make it private --- rust/src/operand_iter.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'rust/src/operand_iter.rs') diff --git a/rust/src/operand_iter.rs b/rust/src/operand_iter.rs index eca92cf3..5f0fbd8e 100644 --- a/rust/src/operand_iter.rs +++ b/rust/src/operand_iter.rs @@ -1,9 +1,49 @@ use binaryninjacore_sys::BNFromVariableIdentifier; +use binaryninjacore_sys::BNGetHighLevelILByIndex; +use binaryninjacore_sys::BNGetMediumLevelILByIndex; +use binaryninjacore_sys::BNHighLevelILOperation; +use binaryninjacore_sys::BNMediumLevelILOperation; -use crate::function::ILFunction; +use crate::hlil::{HighLevelILFunction, HighLevelILInstruction}; +use crate::mlil::{MediumLevelILFunction, MediumLevelILInstruction}; use crate::rc::{Ref, RefCountable}; use crate::types::{SSAVariable, Variable}; +pub trait ILFunction { + type Instruction; + + fn il_instruction_from_idx(&self, expr_idx: usize) -> Self::Instruction; + fn operands_from_idx(&self, expr_idx: usize) -> [u64; 5]; +} + +impl ILFunction for MediumLevelILFunction { + type Instruction = MediumLevelILInstruction; + + fn il_instruction_from_idx(&self, expr_idx: usize) -> Self::Instruction { + self.instruction_from_idx(expr_idx) + } + + fn operands_from_idx(&self, expr_idx: usize) -> [u64; 5] { + let node = unsafe { BNGetMediumLevelILByIndex(self.handle, expr_idx) }; + assert_eq!(node.operation, BNMediumLevelILOperation::MLIL_UNDEF); + node.operands + } +} + +impl ILFunction for HighLevelILFunction { + type Instruction = HighLevelILInstruction; + + fn il_instruction_from_idx(&self, expr_idx: usize) -> Self::Instruction { + self.instruction_from_idx(expr_idx) + } + + fn operands_from_idx(&self, expr_idx: usize) -> [u64; 5] { + let node = unsafe { BNGetHighLevelILByIndex(self.handle, expr_idx, self.full_ast) }; + assert_eq!(node.operation, BNHighLevelILOperation::HLIL_UNDEF); + node.operands + } +} + pub struct OperandIter { function: Ref, remaining: usize, -- cgit v1.3.1