summaryrefslogtreecommitdiff
path: root/rust/src/hlil/operation.rs
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2024-02-11 18:40:23 -0500
committerKyle Martin <krm504@nyu.edu>2024-03-18 17:46:37 -0400
commite66a44d96a1de93978d7db6caa874a485e3088e2 (patch)
treefd9867dac8254d6a9a8427a7d80e85236f611b72 /rust/src/hlil/operation.rs
parent9939d850f0b8ccaf1ae048bcb5f788a6c3e606bf (diff)
Instantiate `HighLevelILInstruction` inline and remove constructors
Diffstat (limited to 'rust/src/hlil/operation.rs')
-rw-r--r--rust/src/hlil/operation.rs376
1 files changed, 1 insertions, 375 deletions
diff --git a/rust/src/hlil/operation.rs b/rust/src/hlil/operation.rs
index eeb322e3..a98a7d32 100644
--- a/rust/src/hlil/operation.rs
+++ b/rust/src/hlil/operation.rs
@@ -1,4 +1,3 @@
-use binaryninjacore_sys::BNFromVariableIdentifier;
use binaryninjacore_sys::BNGetGotoLabelName;
use crate::function::Function;
@@ -7,29 +6,6 @@ use crate::types::{ConstantData, ILIntrinsic, SSAVariable, Variable};
use super::HighLevelILLiftedInstruction;
-fn get_float(value: u64, size: usize) -> f64 {
- match size {
- 4 => f32::from_bits(value as u32) as f64,
- 8 => f64::from_bits(value),
- // TODO how to handle this value?
- size => todo!("float size {}", size),
- }
-}
-
-fn get_var(id: u64) -> Variable {
- unsafe { Variable::from_raw(BNFromVariableIdentifier(id)) }
-}
-
-fn get_member_index(idx: u64) -> Option<usize> {
- (idx as i64 > 0).then_some(idx as usize)
-}
-
-fn get_var_ssa(input: (u64, usize)) -> SSAVariable {
- let raw = unsafe { BNFromVariableIdentifier(input.0) };
- let var = unsafe { Variable::from_raw(raw) };
- SSAVariable::new(var, input.1)
-}
-
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GotoLabel {
pub(crate) function: Ref<Function>,
@@ -57,11 +33,6 @@ pub struct LiftedBinaryOpCarry {
pub right: Box<HighLevelILLiftedInstruction>,
pub carry: Box<HighLevelILLiftedInstruction>,
}
-impl BinaryOpCarry {
- pub(crate) fn new(left: usize, right: usize, carry: usize) -> Self {
- Self { left, right, carry }
- }
-}
// ADD, SUB, AND, OR, XOR, LSL, LSR, ASR, ROL, ROR, MUL, MULU_DP, MULS_DP, DIVU, DIVU_DP, DIVS, DIVS_DP, MODU, MODU_DP, MODS, MODS_DP, CMP_E, CMP_NE, CMP_SLT, CMP_ULT, CMP_SLE, CMP_ULE, CMP_SGE, CMP_UGE, CMP_SGT, CMP_UGT, TEST_BIT, ADD_OVERFLOW, FADD, FSUB, FMUL, FDIV, FCMP_E, FCMP_NE, FCMP_LT, FCMP_LE, FCMP_GE, FCMP_GT, FCMP_O, FCMP_UO
#[derive(Copy, Clone)]
@@ -74,11 +45,6 @@ pub struct LiftedBinaryOp {
pub left: Box<HighLevelILLiftedInstruction>,
pub right: Box<HighLevelILLiftedInstruction>,
}
-impl BinaryOp {
- pub(crate) fn new(left: usize, right: usize) -> Self {
- Self { left, right }
- }
-}
// ARRAY_INDEX
#[derive(Copy, Clone)]
@@ -91,11 +57,6 @@ pub struct LiftedArrayIndex {
pub src: Box<HighLevelILLiftedInstruction>,
pub index: Box<HighLevelILLiftedInstruction>,
}
-impl ArrayIndex {
- pub(crate) fn new(src: usize, index: usize) -> Self {
- Self { src, index }
- }
-}
// ARRAY_INDEX_SSA
#[derive(Copy, Clone)]
@@ -110,15 +71,6 @@ pub struct LiftedArrayIndexSsa {
pub src_memory: u64,
pub index: Box<HighLevelILLiftedInstruction>,
}
-impl ArrayIndexSsa {
- pub(crate) fn new(src: usize, src_memory: u64, index: usize) -> Self {
- Self {
- src,
- src_memory,
- index,
- }
- }
-}
// ASSIGN
#[derive(Copy, Clone)]
@@ -131,11 +83,6 @@ pub struct LiftedAssign {
pub dest: Box<HighLevelILLiftedInstruction>,
pub src: Box<HighLevelILLiftedInstruction>,
}
-impl Assign {
- pub(crate) fn new(dest: usize, src: usize) -> Self {
- Self { dest, src }
- }
-}
// ASSIGN_MEM_SSA
#[derive(Copy, Clone)]
@@ -152,16 +99,6 @@ pub struct LiftedAssignMemSsa {
pub src: Box<HighLevelILLiftedInstruction>,
pub src_memory: u64,
}
-impl AssignMemSsa {
- pub(crate) fn new(dest: usize, dest_memory: u64, src: usize, src_memory: u64) -> Self {
- Self {
- dest,
- dest_memory,
- src,
- src_memory,
- }
- }
-}
// ASSIGN_UNPACK
#[derive(Copy, Clone)]
@@ -175,15 +112,6 @@ pub struct LiftedAssignUnpack {
pub dest: Vec<HighLevelILLiftedInstruction>,
pub src: Box<HighLevelILLiftedInstruction>,
}
-impl AssignUnpack {
- pub(crate) fn new(num_dests: usize, first_dest: usize, src: usize) -> Self {
- Self {
- num_dests,
- first_dest,
- src,
- }
- }
-}
// ASSIGN_UNPACK_MEM_SSA
#[derive(Copy, Clone)]
@@ -201,23 +129,6 @@ pub struct LiftedAssignUnpackMemSsa {
pub src: Box<HighLevelILLiftedInstruction>,
pub src_memory: u64,
}
-impl AssignUnpackMemSsa {
- pub(crate) fn new(
- num_dests: usize,
- first_dest: usize,
- dest_memory: u64,
- src: usize,
- src_memory: u64,
- ) -> Self {
- Self {
- num_dests,
- first_dest,
- dest_memory,
- src,
- src_memory,
- }
- }
-}
// BLOCK
#[derive(Copy, Clone)]
@@ -229,14 +140,6 @@ pub struct Block {
pub struct LiftedBlock {
pub body: Vec<HighLevelILLiftedInstruction>,
}
-impl Block {
- pub(crate) fn new(num_params: usize, first_param: usize) -> Self {
- Self {
- num_params,
- first_param,
- }
- }
-}
// CALL, TAILCALL
#[derive(Copy, Clone)]
@@ -250,15 +153,6 @@ pub struct LiftedCall {
pub dest: Box<HighLevelILLiftedInstruction>,
pub params: Vec<HighLevelILLiftedInstruction>,
}
-impl Call {
- pub(crate) fn new(dest: usize, num_params: usize, first_param: usize) -> Self {
- Self {
- dest,
- num_params,
- first_param,
- }
- }
-}
// CALL_SSA
#[derive(Copy, Clone)]
@@ -276,23 +170,6 @@ pub struct LiftedCallSsa {
pub dest_memory: u64,
pub src_memory: u64,
}
-impl CallSsa {
- pub(crate) fn new(
- dest: usize,
- num_params: usize,
- first_param: usize,
- dest_memory: u64,
- src_memory: u64,
- ) -> Self {
- Self {
- dest,
- num_params,
- first_param,
- dest_memory,
- src_memory,
- }
- }
-}
// CASE
#[derive(Copy, Clone)]
@@ -306,26 +183,12 @@ pub struct LiftedCase {
pub values: Vec<HighLevelILLiftedInstruction>,
pub body: Box<HighLevelILLiftedInstruction>,
}
-impl Case {
- pub(crate) fn new(num_values: usize, first_value: usize, body: usize) -> Self {
- Self {
- num_values,
- first_value,
- body,
- }
- }
-}
// CONST, CONST_PTR, IMPORT
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct Const {
pub constant: u64,
}
-impl Const {
- pub(crate) fn new(constant: u64) -> Self {
- Self { constant }
- }
-}
// CONST_DATA
#[derive(Copy, Clone)]
@@ -338,15 +201,6 @@ pub struct ConstData {
pub struct LiftedConstantData {
pub constant_data: ConstantData,
}
-impl ConstData {
- pub(crate) fn new(constant_data_kind: u32, constant_data_value: i64, size: usize) -> Self {
- Self {
- constant_data_kind,
- constant_data_value,
- size,
- }
- }
-}
// DEREF, ADDRESS_OF, NEG, NOT, SX, ZX, LOW_PART, BOOL_TO_INT, UNIMPL_MEM, FSQRT, FNEG, FABS, FLOAT_TO_INT, INT_TO_FLOAT, FLOAT_CONV, ROUND_TO_INT, FLOOR, CEIL, FTRUNC
#[derive(Copy, Clone)]
@@ -357,11 +211,6 @@ pub struct UnaryOp {
pub struct LiftedUnaryOp {
pub src: Box<HighLevelILLiftedInstruction>,
}
-impl UnaryOp {
- pub(crate) fn new(src: usize) -> Self {
- Self { src }
- }
-}
// DEREF_FIELD_SSA
#[derive(Copy, Clone)]
@@ -378,16 +227,6 @@ pub struct LiftedDerefFieldSsa {
pub offset: u64,
pub member_index: Option<usize>,
}
-impl DerefFieldSsa {
- pub(crate) fn new(src: usize, src_memory: u64, offset: u64, member_index: u64) -> Self {
- Self {
- src,
- src_memory,
- offset,
- member_index: get_member_index(member_index),
- }
- }
-}
// DEREF_SSA
#[derive(Copy, Clone)]
@@ -400,11 +239,6 @@ pub struct LiftedDerefSsa {
pub src: Box<HighLevelILLiftedInstruction>,
pub src_memory: u64,
}
-impl DerefSsa {
- pub(crate) fn new(src: usize, src_memory: u64) -> Self {
- Self { src, src_memory }
- }
-}
// EXTERN_PTR
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
@@ -412,24 +246,12 @@ pub struct ExternPtr {
pub constant: u64,
pub offset: u64,
}
-impl ExternPtr {
- pub(crate) fn new(constant: u64, offset: u64) -> Self {
- Self { constant, offset }
- }
-}
// FLOAT_CONST
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct FloatConst {
pub constant: f64,
}
-impl FloatConst {
- pub(crate) fn new(constant: u64, size: usize) -> Self {
- Self {
- constant: get_float(constant, size),
- }
- }
-}
// FOR
#[derive(Copy, Clone)]
@@ -446,16 +268,6 @@ pub struct LiftedForLoop {
pub update: Box<HighLevelILLiftedInstruction>,
pub body: Box<HighLevelILLiftedInstruction>,
}
-impl ForLoop {
- pub(crate) fn new(init: usize, condition: usize, update: usize, body: usize) -> Self {
- Self {
- init,
- condition,
- update,
- body,
- }
- }
-}
// FOR_SSA
#[derive(Copy, Clone)]
@@ -474,23 +286,6 @@ pub struct LiftedForLoopSsa {
pub update: Box<HighLevelILLiftedInstruction>,
pub body: Box<HighLevelILLiftedInstruction>,
}
-impl ForLoopSsa {
- pub(crate) fn new(
- init: usize,
- condition_phi: usize,
- condition: usize,
- update: usize,
- body: usize,
- ) -> Self {
- Self {
- init,
- condition_phi,
- condition,
- update,
- body,
- }
- }
-}
// GOTO, LABEL
#[derive(Copy, Clone)]
@@ -501,11 +296,7 @@ pub struct Label {
pub struct LiftedLabel {
pub target: GotoLabel,
}
-impl Label {
- pub(crate) fn new(target: u64) -> Self {
- Self { target }
- }
-}
+
// IF
#[derive(Copy, Clone)]
pub struct If {
@@ -519,15 +310,6 @@ pub struct LiftedIf {
pub cond_true: Box<HighLevelILLiftedInstruction>,
pub cond_false: Box<HighLevelILLiftedInstruction>,
}
-impl If {
- pub(crate) fn new(condition: usize, cond_true: usize, cond_false: usize) -> Self {
- Self {
- condition,
- cond_true,
- cond_false,
- }
- }
-}
// INTRINSIC
#[derive(Copy, Clone)]
@@ -541,15 +323,6 @@ pub struct LiftedIntrinsic {
pub intrinsic: ILIntrinsic,
pub params: Vec<HighLevelILLiftedInstruction>,
}
-impl Intrinsic {
- pub(crate) fn new(intrinsic: u32, num_params: usize, first_param: usize) -> Self {
- Self {
- intrinsic,
- num_params,
- first_param,
- }
- }
-}
// INTRINSIC_SSA
#[derive(Copy, Clone)]
@@ -567,23 +340,6 @@ pub struct LiftedIntrinsicSsa {
pub dest_memory: u64,
pub src_memory: u64,
}
-impl IntrinsicSsa {
- pub(crate) fn new(
- intrinsic: u32,
- num_params: usize,
- first_param: usize,
- dest_memory: u64,
- src_memory: u64,
- ) -> Self {
- Self {
- intrinsic,
- num_params,
- first_param,
- dest_memory,
- src_memory,
- }
- }
-}
// JUMP
#[derive(Copy, Clone)]
@@ -594,11 +350,6 @@ pub struct Jump {
pub struct LiftedJump {
pub dest: Box<HighLevelILLiftedInstruction>,
}
-impl Jump {
- pub(crate) fn new(dest: usize) -> Self {
- Self { dest }
- }
-}
// MEM_PHI
#[derive(Copy, Clone)]
@@ -612,15 +363,6 @@ pub struct LiftedMemPhi {
pub dest: u64,
pub src: Vec<u64>,
}
-impl MemPhi {
- pub(crate) fn new(dest: u64, num_srcs: usize, first_src: usize) -> Self {
- Self {
- dest,
- num_srcs,
- first_src,
- }
- }
-}
// RET
#[derive(Copy, Clone)]
@@ -632,14 +374,6 @@ pub struct Ret {
pub struct LiftedRet {
pub src: Vec<HighLevelILLiftedInstruction>,
}
-impl Ret {
- pub(crate) fn new(num_srcs: usize, first_src: usize) -> Self {
- Self {
- first_src,
- num_srcs,
- }
- }
-}
// SPLIT
#[derive(Copy, Clone)]
@@ -652,11 +386,6 @@ pub struct LiftedSplit {
pub high: Box<HighLevelILLiftedInstruction>,
pub low: Box<HighLevelILLiftedInstruction>,
}
-impl Split {
- pub(crate) fn new(high: usize, low: usize) -> Self {
- Self { high, low }
- }
-}
// STRUCT_FIELD, DEREF_FIELD
#[derive(Copy, Clone)]
@@ -671,15 +400,6 @@ pub struct LiftedStructField {
pub offset: u64,
pub member_index: Option<usize>,
}
-impl StructField {
- pub(crate) fn new(src: usize, offset: u64, member_index: u64) -> Self {
- Self {
- src,
- offset,
- member_index: get_member_index(member_index),
- }
- }
-}
// SWITCH
#[derive(Copy, Clone)]
@@ -695,21 +415,6 @@ pub struct LiftedSwitch {
pub default: Box<HighLevelILLiftedInstruction>,
pub cases: Vec<HighLevelILLiftedInstruction>,
}
-impl Switch {
- pub(crate) fn new(
- condition: usize,
- default: usize,
- num_cases: usize,
- first_case: usize,
- ) -> Self {
- Self {
- condition,
- default,
- num_cases,
- first_case,
- }
- }
-}
// SYSCALL
#[derive(Copy, Clone)]
@@ -721,14 +426,6 @@ pub struct Syscall {
pub struct LiftedSyscall {
pub params: Vec<HighLevelILLiftedInstruction>,
}
-impl Syscall {
- pub(crate) fn new(num_params: usize, first_param: usize) -> Self {
- Self {
- num_params,
- first_param,
- }
- }
-}
// SYSCALL_SSA
#[derive(Copy, Clone)]
@@ -744,43 +441,18 @@ pub struct LiftedSyscallSsa {
pub dest_memory: u64,
pub src_memory: u64,
}
-impl SyscallSsa {
- pub(crate) fn new(
- num_params: usize,
- first_param: usize,
- dest_memory: u64,
- src_memory: u64,
- ) -> Self {
- Self {
- num_params,
- first_param,
- dest_memory,
- src_memory,
- }
- }
-}
// TRAP
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct Trap {
pub vector: u64,
}
-impl Trap {
- pub(crate) fn new(vector: u64) -> Self {
- Self { vector }
- }
-}
// VAR_DECLARE, VAR
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct Var {
pub var: Variable,
}
-impl Var {
- pub(crate) fn new(var: u64) -> Self {
- Self { var: get_var(var) }
- }
-}
// VAR_INIT
#[derive(Copy, Clone)]
@@ -793,14 +465,6 @@ pub struct LiftedVarInit {
pub dest: Variable,
pub src: Box<HighLevelILLiftedInstruction>,
}
-impl VarInit {
- pub(crate) fn new(dest: u64, src: usize) -> Self {
- Self {
- dest: get_var(dest),
- src,
- }
- }
-}
// VAR_INIT_SSA
#[derive(Copy, Clone)]
@@ -813,14 +477,6 @@ pub struct LiftedVarInitSsa {
pub dest: SSAVariable,
pub src: Box<HighLevelILLiftedInstruction>,
}
-impl VarInitSsa {
- pub(crate) fn new(dest: (u64, usize), src: usize) -> Self {
- Self {
- dest: get_var_ssa(dest),
- src,
- }
- }
-}
// VAR_PHI
#[derive(Copy, Clone)]
@@ -834,28 +490,12 @@ pub struct LiftedVarPhi {
pub dest: SSAVariable,
pub src: Vec<SSAVariable>,
}
-impl VarPhi {
- pub(crate) fn new(dest: (u64, usize), num_srcs: usize, first_src: usize) -> Self {
- Self {
- dest: get_var_ssa(dest),
- num_srcs,
- first_src,
- }
- }
-}
// VAR_SSA
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct VarSsa {
pub var: SSAVariable,
}
-impl VarSsa {
- pub(crate) fn new(var: (u64, usize)) -> Self {
- Self {
- var: get_var_ssa(var),
- }
- }
-}
// WHILE, DO_WHILE
#[derive(Copy, Clone)]
@@ -868,11 +508,6 @@ pub struct LiftedWhile {
pub condition: Box<HighLevelILLiftedInstruction>,
pub body: Box<HighLevelILLiftedInstruction>,
}
-impl While {
- pub(crate) fn new(condition: usize, body: usize) -> Self {
- Self { condition, body }
- }
-}
// WHILE_SSA, DO_WHILE_SSA
#[derive(Copy, Clone)]
@@ -887,12 +522,3 @@ pub struct LiftedWhileSsa {
pub condition: Box<HighLevelILLiftedInstruction>,
pub body: Box<HighLevelILLiftedInstruction>,
}
-impl WhileSsa {
- pub(crate) fn new(condition_phi: usize, condition: usize, body: usize) -> Self {
- Self {
- condition_phi,
- condition,
- body,
- }
- }
-}