From 29fa00a44648a81da18b2e0797e8c7fb7295b795 Mon Sep 17 00:00:00 2001 From: Xusheng Date: Tue, 3 Jan 2023 12:33:27 +0800 Subject: Add `replace_expr` to MLIL/HLIL in Python API --- python/mediumlevelil.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'python/mediumlevelil.py') diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py index 937fc07e..49c932f3 100644 --- a/python/mediumlevelil.py +++ b/python/mediumlevelil.py @@ -48,6 +48,8 @@ from .commonil import ( TokenList = List['function.InstructionTextToken'] ExpressionIndex = NewType('ExpressionIndex', int) InstructionIndex = NewType('InstructionIndex', int) +Index = Union[ExpressionIndex, InstructionIndex] +InstructionOrExpression = Union['MediumLevelILInstruction', Index] MLILInstructionsType = Generator['MediumLevelILInstruction', None, None] MLILBasicBlocksType = Generator['MediumLevelILBasicBlock', None, None] OperandsType = Tuple[ExpressionIndex, ExpressionIndex, ExpressionIndex, ExpressionIndex, ExpressionIndex] @@ -2879,6 +2881,26 @@ class MediumLevelILFunction: _operation = operation.value return ExpressionIndex(core.BNMediumLevelILAddExpr(self.handle, _operation, size, a, b, c, d, e)) + def replace_expr(self, original: InstructionOrExpression, new: InstructionOrExpression) -> None: + """ + ``replace_expr`` allows modification of MLIL expressions + + :param ExpressionIndex original: the ExpressionIndex to replace (may also be an expression index) + :param ExpressionIndex new: the ExpressionIndex to add to the current LowLevelILFunction (may also be an expression index) + :rtype: None + """ + if isinstance(original, MediumLevelILInstruction): + original = original.expr_index + elif isinstance(original, int): + original = ExpressionIndex(original) + + if isinstance(new, MediumLevelILInstruction): + new = new.expr_index + elif isinstance(new, int): + new = ExpressionIndex(new) + + core.BNReplaceMediumLevelILExpr(self.handle, original, new) + def append(self, expr: ExpressionIndex) -> int: """ ``append`` adds the ExpressionIndex ``expr`` to the current MediumLevelILFunction. -- cgit v1.3.1