summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/binaryview.py3
-rw-r--r--python/databuffer.py4
-rw-r--r--python/highlevelil.py15
-rw-r--r--python/mediumlevelil.py15
4 files changed, 34 insertions, 3 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 9c318f0a..35be7068 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -6047,6 +6047,9 @@ class BinaryView:
raise TypeError("Removal is only supported with a Component or string representing its Guid")
+ def get_constant_data(self, addr: int) -> 'DataBuffer':
+ return databuffer.DataBuffer(handle=core.BNGetConstantData(self.handle, addr))
+
def get_strings(self, start: Optional[int] = None, length: Optional[int] = None) -> List['StringReference']:
"""
``get_strings`` returns a list of strings defined in the binary in the optional virtual address range:
diff --git a/python/databuffer.py b/python/databuffer.py
index bbcdd37b..44b64ab5 100644
--- a/python/databuffer.py
+++ b/python/databuffer.py
@@ -143,8 +143,8 @@ class DataBuffer:
return False
return bytes(self) == bytes(other)
- def escape(self) -> str:
- return core.BNDataBufferToEscapedString(self.handle)
+ def escape(self, null_terminates=False) -> str:
+ return core.BNDataBufferToEscapedString(self.handle, null_terminates)
def unescape(self) -> 'DataBuffer':
return DataBuffer(handle=core.BNDecodeEscapedString(str(self)))
diff --git a/python/highlevelil.py b/python/highlevelil.py
index b9bb3e88..1f8c3f84 100644
--- a/python/highlevelil.py
+++ b/python/highlevelil.py
@@ -38,6 +38,7 @@ from . import types
from . import highlight
from . import flowgraph
from . import variable
+from . import databuffer
from .interaction import show_graph_report
from .commonil import (
BaseILInstruction, Tailcall, Syscall, Localcall, Comparison, Signed, UnaryOperation, BinaryOperation, SSA, Phi,
@@ -54,7 +55,7 @@ OperandsType = Tuple[ExpressionIndex, ExpressionIndex, ExpressionIndex, Expressi
HighLevelILOperandType = Union['HighLevelILInstruction', 'lowlevelil.ILIntrinsic', 'variable.Variable',
'mediumlevelil.SSAVariable', List[int], List['variable.Variable'],
List['mediumlevelil.SSAVariable'], List['HighLevelILInstruction'], Optional[int], float,
- 'GotoLabel']
+ 'GotoLabel', databuffer.DataBuffer]
VariablesList = List[Union['mediumlevelil.SSAVariable', 'variable.Variable']]
StringOrType = Union[str, '_types.Type', '_types.TypeBuilder']
@@ -1402,6 +1403,17 @@ class HighLevelILConst(HighLevelILInstruction, Constant):
@dataclass(frozen=True, repr=False, eq=False)
+class HighLevelILConstData(HighLevelILInstruction, Constant):
+ @property
+ def constant(self) -> 'DataBuffer':
+ return self.function.source_function.view.get_constant_data(self._get_int(0))
+
+ @property
+ def operands(self) -> List[HighLevelILOperandType]:
+ return [self.constant]
+
+
+@dataclass(frozen=True, repr=False, eq=False)
class HighLevelILConstPtr(HighLevelILInstruction, Constant):
@property
def constant(self) -> int:
@@ -1978,6 +1990,7 @@ ILInstruction = {
HighLevelILDerefFieldSsa, # ("src", "expr"), ("src_memory", "int"), ("offset", "int"), ("member_index", "member_index"),
HighLevelILOperation.HLIL_ADDRESS_OF: HighLevelILAddressOf, # ("src", "expr"),
HighLevelILOperation.HLIL_CONST: HighLevelILConst, # ("constant", "int"),
+ HighLevelILOperation.HLIL_CONST_DATA: HighLevelILConstData, # ("constant", "int"),
HighLevelILOperation.HLIL_CONST_PTR: HighLevelILConstPtr, # ("constant", "int"),
HighLevelILOperation.HLIL_EXTERN_PTR: HighLevelILExternPtr, # ("constant", "int"), ("offset", "int"),
HighLevelILOperation.HLIL_FLOAT_CONST: HighLevelILFloatConst, # ("constant", "float"),
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 535723f7..6d6077c7 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -36,6 +36,7 @@ from . import flowgraph
from . import variable
from . import architecture
from . import binaryview
+from . import databuffer
from .interaction import show_graph_report
from .commonil import (
BaseILInstruction, Constant, BinaryOperation, UnaryOperation, Comparison, SSA, Phi, FloatingPoint, ControlFlow,
@@ -146,6 +147,8 @@ class MediumLevelILInstruction(BaseILInstruction):
("src", "var"), ("offset", "int")
], MediumLevelILOperation.MLIL_CONST: [("constant", "int")], MediumLevelILOperation.MLIL_CONST_PTR: [
("constant", "int")
+ ], MediumLevelILOperation.MLIL_CONST_DATA: [("constant", "int")], MediumLevelILOperation.MLIL_CONST_DATA: [
+ ("constant", "int")
], MediumLevelILOperation.MLIL_EXTERN_PTR: [
("constant", "int"), ("offset", "int")
], MediumLevelILOperation.MLIL_FLOAT_CONST: [("constant", "float")], MediumLevelILOperation.MLIL_IMPORT: [
@@ -1029,6 +1032,17 @@ class MediumLevelILConst(MediumLevelILConstBase):
@dataclass(frozen=True, repr=False, eq=False)
+class MediumLevelILConstData(MediumLevelILConstBase):
+ @property
+ def constant(self) -> 'DataBuffer':
+ return self.function.source_function.view.get_constant_data(self._get_int(0))
+
+ @property
+ def operands(self) -> List[databuffer.DataBuffer]:
+ return [self.constant]
+
+
+@dataclass(frozen=True, repr=False, eq=False)
class MediumLevelILConstPtr(MediumLevelILConstBase):
@property
def constant(self) -> int:
@@ -2488,6 +2502,7 @@ ILInstruction = {
MediumLevelILOperation.MLIL_VAR: MediumLevelILVar, # [("src", "var")],
MediumLevelILOperation.MLIL_ADDRESS_OF: MediumLevelILAddressOf, # [("src", "var")],
MediumLevelILOperation.MLIL_CONST: MediumLevelILConst, # [("constant", "int")],
+ MediumLevelILOperation.MLIL_CONST_DATA: MediumLevelILConstData, # [("constant", "int")],
MediumLevelILOperation.MLIL_CONST_PTR: MediumLevelILConstPtr, # [("constant", "int")],
MediumLevelILOperation.MLIL_FLOAT_CONST: MediumLevelILFloatConst, # [("constant", "float")],
MediumLevelILOperation.MLIL_IMPORT: MediumLevelILImport, # [("constant", "int")],