Skip to content

Commit 08d88d8

Browse files
committed
[Rust] Allow mapping between SSA and non-SSA forms of instructions / expressions
1 parent 5ecf8d5 commit 08d88d8

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

rust/src/low_level_il/expression.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,36 @@ where
104104
}
105105
}
106106

107+
impl<M, R> LowLevelILExpression<'_, M, SSA, R>
108+
where
109+
M: FunctionMutability,
110+
R: ExpressionResultType,
111+
{
112+
pub fn non_ssa_form<'func>(
113+
&self,
114+
non_ssa: &'func LowLevelILFunction<M, NonSSA>,
115+
) -> LowLevelILExpression<'func, M, NonSSA, R> {
116+
use binaryninjacore_sys::BNGetLowLevelILNonSSAExprIndex;
117+
let idx = unsafe { BNGetLowLevelILNonSSAExprIndex(self.function.handle, self.index.0) };
118+
LowLevelILExpression::new(non_ssa, LowLevelExpressionIndex(idx))
119+
}
120+
}
121+
122+
impl<M, R> LowLevelILExpression<'_, M, NonSSA, R>
123+
where
124+
M: FunctionMutability,
125+
R: ExpressionResultType,
126+
{
127+
pub fn ssa_form<'func>(
128+
&self,
129+
ssa: &'func LowLevelILFunction<M, SSA>,
130+
) -> LowLevelILExpression<'func, M, SSA, R> {
131+
use binaryninjacore_sys::BNGetLowLevelILSSAExprIndex;
132+
let idx = unsafe { BNGetLowLevelILSSAExprIndex(self.function.handle, self.index.0) };
133+
LowLevelILExpression::new(ssa, LowLevelExpressionIndex(idx))
134+
}
135+
}
136+
107137
impl<'func, M> ExpressionHandler<'func, M, SSA> for LowLevelILExpression<'func, M, SSA, ValueExpr>
108138
where
109139
M: FunctionMutability,

rust/src/low_level_il/instruction.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,48 @@ where
100100
}
101101
}
102102

103+
impl<'func, M> LowLevelILInstruction<'func, M, NonSSA>
104+
where
105+
M: FunctionMutability,
106+
{
107+
pub fn ssa_form(
108+
&self,
109+
ssa: &'func LowLevelILFunction<M, SSA>,
110+
) -> LowLevelILInstruction<'func, M, SSA> {
111+
use binaryninjacore_sys::BNGetLowLevelILSSAInstructionIndex;
112+
let idx = unsafe { BNGetLowLevelILSSAInstructionIndex(self.function.handle, self.index.0) };
113+
LowLevelILInstruction::new(ssa, LowLevelInstructionIndex(idx))
114+
}
115+
}
116+
117+
impl<'func, M> LowLevelILInstruction<'func, M, SSA>
118+
where
119+
M: FunctionMutability,
120+
{
121+
pub fn non_ssa_form(
122+
&self,
123+
non_ssa: &'func LowLevelILFunction<M, NonSSA>,
124+
) -> LowLevelILInstruction<'func, M, NonSSA> {
125+
use binaryninjacore_sys::BNGetLowLevelILNonSSAInstructionIndex;
126+
let idx =
127+
unsafe { BNGetLowLevelILNonSSAInstructionIndex(self.function.handle, self.index.0) };
128+
LowLevelILInstruction::new(non_ssa, LowLevelInstructionIndex(idx))
129+
}
130+
}
131+
132+
impl<M, F> Clone for LowLevelILInstruction<'_, M, F>
133+
where
134+
M: FunctionMutability,
135+
F: FunctionForm,
136+
{
137+
fn clone(&self) -> Self {
138+
Self {
139+
function: self.function,
140+
index: self.index,
141+
}
142+
}
143+
}
144+
103145
impl<M, F> Debug for LowLevelILInstruction<'_, M, F>
104146
where
105147
M: FunctionMutability,

0 commit comments

Comments
 (0)