Skip to content

Commit a87589b

Browse files
committed
[Rust] Allow mapping between SSA and non-SSA forms of instructions / expressions
1 parent 1431470 commit a87589b

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,42 @@ where
100100
}
101101
}
102102

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

0 commit comments

Comments
 (0)