diff options
| author | Michael Krasnitski <michael.krasnitski@gmail.com> | 2024-02-27 14:26:56 -0500 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2024-03-18 17:46:37 -0400 |
| commit | 462276a4aa998e0b0ef804dd8d3b2eaa84a82f98 (patch) | |
| tree | 913c2d20bfe987505475f3b40f32201ff7060133 /rust/src | |
| parent | 14abee20c4122608b21f3c2b55cba4a75d1b4308 (diff) | |
Move `ILFunction` trait into `operand_iter.rs` to make it private
Diffstat (limited to 'rust/src')
| -rw-r--r-- | rust/src/function.rs | 7 | ||||
| -rw-r--r-- | rust/src/hlil/function.rs | 18 | ||||
| -rw-r--r-- | rust/src/mlil/function.rs | 18 | ||||
| -rw-r--r-- | rust/src/operand_iter.rs | 42 |
4 files changed, 43 insertions, 42 deletions
diff --git a/rust/src/function.rs b/rust/src/function.rs index 16c7bf2f..273a0861 100644 --- a/rust/src/function.rs +++ b/rust/src/function.rs @@ -435,13 +435,6 @@ impl PartialEq for Function { } } -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]; -} - ///////////////// // AddressRange diff --git a/rust/src/hlil/function.rs b/rust/src/hlil/function.rs index 7ab9e519..4bad7f0f 100644 --- a/rust/src/hlil/function.rs +++ b/rust/src/hlil/function.rs @@ -2,16 +2,14 @@ use std::hash::{Hash, Hasher}; use binaryninjacore_sys::BNFreeHighLevelILFunction; use binaryninjacore_sys::BNGetHighLevelILBasicBlockList; -use binaryninjacore_sys::BNGetHighLevelILByIndex; use binaryninjacore_sys::BNGetHighLevelILInstructionCount; use binaryninjacore_sys::BNGetHighLevelILOwnerFunction; use binaryninjacore_sys::BNGetHighLevelILSSAForm; use binaryninjacore_sys::BNHighLevelILFunction; -use binaryninjacore_sys::BNHighLevelILOperation; use binaryninjacore_sys::BNNewHighLevelILFunctionReference; use crate::basicblock::BasicBlock; -use crate::function::{Function, ILFunction}; +use crate::function::Function; use crate::rc::{Array, Ref, RefCountable}; use super::{HighLevelILBlock, HighLevelILInstruction, HighLevelILLiftedInstruction}; @@ -85,20 +83,6 @@ impl HighLevelILFunction { } } -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 - } -} - impl ToOwned for HighLevelILFunction { type Owned = Ref<Self>; diff --git a/rust/src/mlil/function.rs b/rust/src/mlil/function.rs index b1e15f8b..16cc5102 100644 --- a/rust/src/mlil/function.rs +++ b/rust/src/mlil/function.rs @@ -2,18 +2,16 @@ use core::hash::{Hash, Hasher}; use binaryninjacore_sys::BNFreeMediumLevelILFunction; use binaryninjacore_sys::BNGetMediumLevelILBasicBlockList; -use binaryninjacore_sys::BNGetMediumLevelILByIndex; use binaryninjacore_sys::BNGetMediumLevelILInstructionCount; use binaryninjacore_sys::BNGetMediumLevelILOwnerFunction; use binaryninjacore_sys::BNGetMediumLevelILSSAForm; use binaryninjacore_sys::BNMediumLevelILFunction; use binaryninjacore_sys::BNMediumLevelILGetInstructionStart; -use binaryninjacore_sys::BNMediumLevelILOperation; use binaryninjacore_sys::BNNewMediumLevelILFunctionReference; use crate::basicblock::BasicBlock; +use crate::function::Function; use crate::function::Location; -use crate::function::{Function, ILFunction}; use crate::rc::{Array, Ref, RefCountable}; use super::{MediumLevelILBlock, MediumLevelILInstruction, MediumLevelILLiftedInstruction}; @@ -95,20 +93,6 @@ impl MediumLevelILFunction { } } -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 ToOwned for MediumLevelILFunction { type Owned = Ref<Self>; 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<F: ILFunction + RefCountable> { function: Ref<F>, remaining: usize, |
