From c1b9992365963916e185c3ce62ebab576486dbad Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 19 Jun 2024 12:55:57 -0400 Subject: [PATCH] Make Expression cloneable --- rust/src/llil/expression.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rust/src/llil/expression.rs b/rust/src/llil/expression.rs index d8a3a643e..7f114e448 100644 --- a/rust/src/llil/expression.rs +++ b/rust/src/llil/expression.rs @@ -83,6 +83,36 @@ where } } +impl<'func, A, V, R> Clone for Expression<'func, A, Mutable, NonSSA, R> + where + A: 'func + Architecture, + V: NonSSAVariant, + R: ExpressionResultType, +{ + fn clone(&self) -> Self { + use binaryninjacore_sys::BNLowLevelILAddExpr; + + let expr = unsafe { + BNGetLowLevelILByIndex(self.function.handle, self.expr_idx) + }; + + let cloned_expr_idx = unsafe { + BNLowLevelILAddExpr( + self.function.handle, + expr.operation, + expr.size, + expr.flags, + expr.operands[0], + expr.operands[1], + expr.operands[2], + expr.operands[3], + ) + }; + + Expression::new(self.function, cloned_expr_idx) + } +} + fn common_info<'func, A, M, F>( function: &'func Function, op: BNLowLevelILInstruction,