summaryrefslogtreecommitdiff
path: root/rust/src/operand_iter.rs
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2024-02-27 14:26:56 -0500
committerKyle Martin <krm504@nyu.edu>2024-03-18 17:46:37 -0400
commit462276a4aa998e0b0ef804dd8d3b2eaa84a82f98 (patch)
tree913c2d20bfe987505475f3b40f32201ff7060133 /rust/src/operand_iter.rs
parent14abee20c4122608b21f3c2b55cba4a75d1b4308 (diff)
Move `ILFunction` trait into `operand_iter.rs` to make it private
Diffstat (limited to 'rust/src/operand_iter.rs')
-rw-r--r--rust/src/operand_iter.rs42
1 files changed, 41 insertions, 1 deletions
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,