diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-09 14:00:38 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 2a9beeec15d3f32312a0c4f8ad5ddbcfcbc97a89 (patch) | |
| tree | 5562dd4acafb32f6e9826a4247f910507cec4c8d /rust/src/low_level_il/instruction.rs | |
| parent | 6617b0afa09f549d0a5c9c53063f3ad8ab82b7e4 (diff) | |
[Rust] Support SSA form properly in low level IL
Diffstat (limited to 'rust/src/low_level_il/instruction.rs')
| -rw-r--r-- | rust/src/low_level_il/instruction.rs | 108 |
1 files changed, 80 insertions, 28 deletions
diff --git a/rust/src/low_level_il/instruction.rs b/rust/src/low_level_il/instruction.rs index ded9c6f3..90d2f1d8 100644 --- a/rust/src/low_level_il/instruction.rs +++ b/rust/src/low_level_il/instruction.rs @@ -207,9 +207,14 @@ where { Nop(Operation<'func, M, F, operation::NoArgs>), SetReg(Operation<'func, M, F, operation::SetReg>), + SetRegSsa(Operation<'func, M, F, operation::SetRegSsa>), + SetRegPartialSsa(Operation<'func, M, F, operation::SetRegPartialSsa>), SetRegSplit(Operation<'func, M, F, operation::SetRegSplit>), + SetRegSplitSsa(Operation<'func, M, F, operation::SetRegSplitSsa>), SetFlag(Operation<'func, M, F, operation::SetFlag>), + SetFlagSsa(Operation<'func, M, F, operation::SetFlagSsa>), Store(Operation<'func, M, F, operation::Store>), + StoreSsa(Operation<'func, M, F, operation::StoreSsa>), // TODO needs a real op Push(Operation<'func, M, F, operation::UnaryOp>), @@ -219,7 +224,9 @@ where JumpTo(Operation<'func, M, F, operation::JumpTo>), Call(Operation<'func, M, F, operation::Call>), + CallSsa(Operation<'func, M, F, operation::CallSsa>), TailCall(Operation<'func, M, F, operation::Call>), + TailCallSsa(Operation<'func, M, F, operation::CallSsa>), Ret(Operation<'func, M, F, operation::Ret>), NoRet(Operation<'func, M, F, operation::NoArgs>), @@ -228,6 +235,7 @@ where Goto(Operation<'func, M, F, operation::Goto>), Syscall(Operation<'func, M, F, operation::Syscall>), + SyscallSsa(Operation<'func, M, F, operation::SyscallSsa>), Intrinsic(Operation<'func, M, F, operation::Intrinsic>), Bp(Operation<'func, M, F, operation::NoArgs>), Trap(Operation<'func, M, F, operation::Trap>), @@ -250,50 +258,80 @@ where use binaryninjacore_sys::BNLowLevelILOperation::*; match op.operation { - LLIL_NOP => LowLevelILInstructionKind::Nop(Operation::new(function, op)), - LLIL_SET_REG | LLIL_SET_REG_SSA => { - LowLevelILInstructionKind::SetReg(Operation::new(function, op)) + LLIL_NOP => LowLevelILInstructionKind::Nop(Operation::new(function, op, expr_index)), + LLIL_SET_REG => { + LowLevelILInstructionKind::SetReg(Operation::new(function, op, expr_index)) } - LLIL_SET_REG_SPLIT | LLIL_SET_REG_SPLIT_SSA => { - LowLevelILInstructionKind::SetRegSplit(Operation::new(function, op)) + LLIL_SET_REG_SSA => { + LowLevelILInstructionKind::SetRegSsa(Operation::new(function, op, expr_index)) } - LLIL_SET_FLAG | LLIL_SET_FLAG_SSA => { - LowLevelILInstructionKind::SetFlag(Operation::new(function, op)) + LLIL_SET_REG_SSA_PARTIAL => LowLevelILInstructionKind::SetRegPartialSsa( + Operation::new(function, op, expr_index), + ), + LLIL_SET_REG_SPLIT => { + LowLevelILInstructionKind::SetRegSplit(Operation::new(function, op, expr_index)) } - LLIL_STORE | LLIL_STORE_SSA => { - LowLevelILInstructionKind::Store(Operation::new(function, op)) + LLIL_SET_REG_SPLIT_SSA => { + LowLevelILInstructionKind::SetRegSplitSsa(Operation::new(function, op, expr_index)) } - LLIL_PUSH => LowLevelILInstructionKind::Push(Operation::new(function, op)), + LLIL_SET_FLAG => { + LowLevelILInstructionKind::SetFlag(Operation::new(function, op, expr_index)) + } + LLIL_SET_FLAG_SSA => { + LowLevelILInstructionKind::SetFlagSsa(Operation::new(function, op, expr_index)) + } + LLIL_STORE => { + LowLevelILInstructionKind::Store(Operation::new(function, op, expr_index)) + } + LLIL_STORE_SSA => { + LowLevelILInstructionKind::StoreSsa(Operation::new(function, op, expr_index)) + } + LLIL_PUSH => LowLevelILInstructionKind::Push(Operation::new(function, op, expr_index)), LLIL_REG_STACK_PUSH => { - LowLevelILInstructionKind::RegStackPush(Operation::new(function, op)) + LowLevelILInstructionKind::RegStackPush(Operation::new(function, op, expr_index)) } - LLIL_JUMP => LowLevelILInstructionKind::Jump(Operation::new(function, op)), - LLIL_JUMP_TO => LowLevelILInstructionKind::JumpTo(Operation::new(function, op)), + LLIL_JUMP => LowLevelILInstructionKind::Jump(Operation::new(function, op, expr_index)), + LLIL_JUMP_TO => { + LowLevelILInstructionKind::JumpTo(Operation::new(function, op, expr_index)) + } - LLIL_CALL | LLIL_CALL_STACK_ADJUST | LLIL_CALL_SSA => { - LowLevelILInstructionKind::Call(Operation::new(function, op)) + LLIL_CALL | LLIL_CALL_STACK_ADJUST => { + LowLevelILInstructionKind::Call(Operation::new(function, op, expr_index)) + } + LLIL_CALL_SSA => { + LowLevelILInstructionKind::CallSsa(Operation::new(function, op, expr_index)) + } + LLIL_TAILCALL => { + LowLevelILInstructionKind::TailCall(Operation::new(function, op, expr_index)) } - LLIL_TAILCALL | LLIL_TAILCALL_SSA => { - LowLevelILInstructionKind::TailCall(Operation::new(function, op)) + LLIL_TAILCALL_SSA => { + LowLevelILInstructionKind::TailCallSsa(Operation::new(function, op, expr_index)) } - LLIL_RET => LowLevelILInstructionKind::Ret(Operation::new(function, op)), - LLIL_NORET => LowLevelILInstructionKind::NoRet(Operation::new(function, op)), + LLIL_RET => LowLevelILInstructionKind::Ret(Operation::new(function, op, expr_index)), + LLIL_NORET => { + LowLevelILInstructionKind::NoRet(Operation::new(function, op, expr_index)) + } - LLIL_IF => LowLevelILInstructionKind::If(Operation::new(function, op)), - LLIL_GOTO => LowLevelILInstructionKind::Goto(Operation::new(function, op)), + LLIL_IF => LowLevelILInstructionKind::If(Operation::new(function, op, expr_index)), + LLIL_GOTO => LowLevelILInstructionKind::Goto(Operation::new(function, op, expr_index)), - LLIL_SYSCALL | LLIL_SYSCALL_SSA => { - LowLevelILInstructionKind::Syscall(Operation::new(function, op)) + LLIL_SYSCALL => { + LowLevelILInstructionKind::Syscall(Operation::new(function, op, expr_index)) + } + LLIL_SYSCALL_SSA => { + LowLevelILInstructionKind::SyscallSsa(Operation::new(function, op, expr_index)) } LLIL_INTRINSIC | LLIL_INTRINSIC_SSA => { - LowLevelILInstructionKind::Intrinsic(Operation::new(function, op)) + LowLevelILInstructionKind::Intrinsic(Operation::new(function, op, expr_index)) + } + LLIL_BP => LowLevelILInstructionKind::Bp(Operation::new(function, op, expr_index)), + LLIL_TRAP => LowLevelILInstructionKind::Trap(Operation::new(function, op, expr_index)), + LLIL_UNDEF => { + LowLevelILInstructionKind::Undef(Operation::new(function, op, expr_index)) } - LLIL_BP => LowLevelILInstructionKind::Bp(Operation::new(function, op)), - LLIL_TRAP => LowLevelILInstructionKind::Trap(Operation::new(function, op)), - LLIL_UNDEF => LowLevelILInstructionKind::Undef(Operation::new(function, op)), _ => LowLevelILInstructionKind::Value(LowLevelILExpression::new(function, expr_index)), } } @@ -314,17 +352,31 @@ where match self { SetReg(ref op) => visit!(&op.source_expr()), + SetRegSsa(ref op) => visit!(&op.source_expr()), + SetRegPartialSsa(ref op) => visit!(&op.source_expr()), SetRegSplit(ref op) => visit!(&op.source_expr()), + SetRegSplitSsa(ref op) => visit!(&op.source_expr()), SetFlag(ref op) => visit!(&op.source_expr()), + SetFlagSsa(ref op) => visit!(&op.source_expr()), Store(ref op) => { - visit!(&op.dest_mem_expr()); + visit!(&op.dest_expr()); + visit!(&op.source_expr()); + } + StoreSsa(ref op) => { + visit!(&op.dest_expr()); visit!(&op.source_expr()); } Push(ref op) => visit!(&op.operand()), RegStackPush(ref op) => visit!(&op.source_expr()), Jump(ref op) => visit!(&op.target()), JumpTo(ref op) => visit!(&op.target()), + SyscallSsa(ref op) => { + visit!(&op.output_expr()); + visit!(&op.param_expr()); + visit!(&op.stack_expr()); + } Call(ref op) | TailCall(ref op) => visit!(&op.target()), + CallSsa(ref op) | TailCallSsa(ref op) => visit!(&op.target()), Ret(ref op) => visit!(&op.target()), If(ref op) => visit!(&op.condition()), Intrinsic(ref _op) => { |
