summaryrefslogtreecommitdiff
path: root/python/highlevelil.py
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2024-03-07 21:32:43 -0500
committerGlenn Smith <glenn@vector35.com>2024-03-07 21:32:43 -0500
commit4620519194636807511824023284542848735054 (patch)
tree79f124def81e468f1e83a305174725ca1ff34fa0 /python/highlevelil.py
parent72cc84aabd188e4add6e5012df86414b65d95bc8 (diff)
Python: More IL expr functions
- XLILFunction.get_expr: Get an expr by index - XLILFunction.copy_expr: Copy an IL expr to a new expr - XLILInstruction.raw_operands: the straight integers from the core - Extra accessors on XLILLabel
Diffstat (limited to 'python/highlevelil.py')
-rw-r--r--python/highlevelil.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/python/highlevelil.py b/python/highlevelil.py
index 7efbcbb8..2b4d9153 100644
--- a/python/highlevelil.py
+++ b/python/highlevelil.py
@@ -767,6 +767,11 @@ class HighLevelILInstruction(BaseILInstruction):
return GotoLabel(self.function, self.core_instr.operands[operand_index])
@property
+ def raw_operands(self) -> OperandsType:
+ """Raw operand expression indices as specified by the core structure (read-only)"""
+ return self.instr.operands
+
+ @property
def operands(self) -> List[HighLevelILOperandType]:
"""Operands for the instruction"""
return list(map(lambda x: x[1], self.detailed_operands))
@@ -2783,6 +2788,43 @@ class HighLevelILFunction:
operation_value = operation.value
return ExpressionIndex(core.BNHighLevelILAddExpr(self.handle, operation_value, size, a, b, c, d, e))
+ def get_expr_count(self) -> int:
+ """
+ ``get_expr_count`` gives a the total number of expressions in this IL function
+
+ You can use this to enumerate all expressions in conjunction with :py:func:`get_expr`
+
+ .. warning :: Not all IL expressions are valid, even if their index is within the bounds of the function,
+ they might not be used by the function and might not contain properly structured data.
+
+ :return: The number of expressions in the function
+ """
+ return core.BNGetHighLevelILExprCount(self.handle)
+
+ def get_expr(self, index: ExpressionIndex) -> Optional[HighLevelILInstruction]:
+ """
+ ``get_expr`` retrieves the IL expression at a given expression index in the function.
+
+ .. warning :: Not all IL expressions are valid, even if their index is within the bounds of the function,
+ they might not be used by the function and might not contain properly structured data.
+
+ :param index: Index of desired expression in function
+ :return: A HighLevelILInstruction object for the expression, if it exists. Otherwise, None
+ """
+ if index >= self.get_expr_count():
+ return None
+
+ return HighLevelILInstruction.create(self, index)
+
+ def copy_expr(self, original: HighLevelILInstruction) -> ExpressionIndex:
+ """
+ ``copy_expr`` adds an expression to the function which is equivalent to the given expression
+
+ :param HighLevelILInstruction original: the original IL Instruction you want to copy
+ :return: The index of the newly copied expression
+ """
+ return self.expr(original.operation, original.raw_operands[0], original.raw_operands[1], original.raw_operands[2], original.raw_operands[3], original.raw_operands[4], original.size)
+
def replace_expr(self, original: InstructionOrExpression, new: InstructionOrExpression) -> None:
"""
``replace_expr`` allows modification of HLIL expressions