summaryrefslogtreecommitdiff
path: root/python/commonil.py
diff options
context:
space:
mode:
authorGlenn Smith <glenn@vector35.com>2025-02-24 17:04:34 -0500
committerGlenn Smith <glenn@vector35.com>2025-03-05 16:39:57 -0500
commit0964368357272921723837998074043356784550 (patch)
treeef6ff8dbc260177984ef2e5a9d10c035157d6089 /python/commonil.py
parentf2d653fd89262d73fa9d4f221cd45bae873a6ca9 (diff)
Python: Add ability to construct expressions with locations
Co-Authored-By: ltlly <a1253213025@163.com>
Diffstat (limited to 'python/commonil.py')
-rw-r--r--python/commonil.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/python/commonil.py b/python/commonil.py
index b665165d..74399184 100644
--- a/python/commonil.py
+++ b/python/commonil.py
@@ -19,10 +19,14 @@
# IN THE SOFTWARE.
from dataclasses import dataclass
+from typing import Union
from .flowgraph import FlowGraph, FlowGraphNode
from .enums import BranchType
from .interaction import show_graph_report
from .log import log_warn
+from . import lowlevelil
+from . import mediumlevelil
+from . import highlevelil
# This file contains a list of top level abstract classes for implementing BNIL instructions
@@ -204,3 +208,27 @@ class SSAVariableInstruction(SSA, VariableInstruction):
@dataclass(frozen=True, repr=False, eq=False)
class AliasedVariableInstruction(VariableInstruction):
pass
+
+
+@dataclass
+class ILSourceLocation:
+ """
+ ILSourceLocation is used to indicate where expressions were defined during the lifting process
+ and gets propagated through the lifting process as an instruction's address/source_operand properties.
+ These are used for, for example, integer display types and expression addresses.
+ """
+ address: int
+ source_operand: int
+
+ @classmethod
+ def from_instruction(
+ cls,
+ instr: Union['lowlevelil.LowLevelILInstruction', 'mediumlevelil.MediumLevelILInstruction', 'highlevelil.HighLevelILInstruction']
+ ) -> 'ILSourceLocation':
+ """
+ Get the source location of a given instruction
+ :param instr: Instruction, Low, Medium, or High level
+ :return: Its location
+ """
+ return cls(instr.address, instr.source_operand)
+