summaryrefslogtreecommitdiff
path: root/python/binaryview.py
diff options
context:
space:
mode:
authorXusheng <xusheng@vector35.com>2023-01-18 11:15:17 +0800
committerXusheng <xusheng@vector35.com>2023-01-19 09:50:35 +0800
commite4ab8f35ce16baafe11d7056d1d1304f3c057cd5 (patch)
tree415154972bad461bdc2e5a3a93f4c7c6b5f767c0 /python/binaryview.py
parent919384bb2bb9216e000750a00793549ef7a46d87 (diff)
Deprecate __len__ of Segment
Print a warning message when a deprecated function/property/class is used
Diffstat (limited to 'python/binaryview.py')
-rw-r--r--python/binaryview.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/python/binaryview.py b/python/binaryview.py
index 917d9e51..16c04279 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -68,6 +68,7 @@ from . import workflow as _workflow
from . import function as _function
from . import types as _types
from . import platform as _platform
+from . import deprecation
PathType = Union[str, os.PathLike]
InstructionsType = Generator[Tuple[List['_function.InstructionTextToken'], int], None, None]
@@ -1306,8 +1307,14 @@ class Segment:
x = "x" if self.executable else "-"
return f"<segment: {self.start:#x}-{self.end:#x}, {r}{w}{x}>"
+ @deprecation.deprecated(details="Use .length instead. Python disallows the length of an object to "
+ ">= 0x8000000000000000. See https://bugs.python.org/issue21444.")
def __len__(self):
- return core.BNSegmentGetLength(self.handle)
+ return self.length
+
+ @property
+ def length(self):
+ return int(core.BNSegmentGetLength(self.handle))
def __eq__(self, other):
if not isinstance(other, self.__class__):
@@ -1403,11 +1410,9 @@ class Section:
def __repr__(self):
return f"<section {self.name}: {self.start:#x}-{self.end:#x}>"
- @decorators.deprecated
+ @deprecation.deprecated(details="Use .length instead. Python disallows the length of an object to "
+ ">= 0x8000000000000000. See https://bugs.python.org/issue21444.")
def __len__(self):
- # deprecated - Python does allow the returning of integers >= 0x8000000000000000
- # please use .length instead
- # for more information about this limitation in python see https://bugs.python.org/issue21444
return self.length
def __eq__(self, other):
@@ -2036,11 +2041,9 @@ class BinaryView:
return f"<BinaryView: '{filename}', {size}>"
return f"<BinaryView: {size}>"
- @decorators.deprecated
+ @deprecation.deprecated(details="Use .length instead. Python disallows the length of an object to "
+ ">= 0x8000000000000000. See https://bugs.python.org/issue21444.")
def __len__(self):
- # deprecated - Python does allow the returning of integers >= 0x8000000000000000
- # please use .length instead
- # for more information about this limitation in python see https://bugs.python.org/issue21444
return int(core.BNGetViewLength(self.handle))
@property
@@ -8699,14 +8702,20 @@ class BinaryWriter:
core.BNSeekBinaryWriterRelative(self._handle, offset)
-@decorators.deprecated
-@dataclass
+@dataclass(init=False)
class StructuredDataValue(object):
type: '_types.Type'
address: int
value: bytes
endian: Endianness
+ @deprecation.deprecated(details='StructuredDataValue is deprecated.')
+ def __init__(self, t: '_type.Type', addr: int, val: bytes, e: Endianness):
+ self.type = t
+ self.address = addr
+ self.value = val
+ self.endian = e
+
def __str__(self):
decode_str = "{}B".format(self.type.width)
return ' '.join([f"{x:02x}" for x in struct.unpack(decode_str, self.value)])
@@ -8742,7 +8751,6 @@ class StructuredDataValue(object):
return int(self)
-@decorators.deprecated
class StructuredDataView(object):
"""
``class StructuredDataView`` is a convenience class for reading structured binary data.
@@ -8761,6 +8769,7 @@ class StructuredDataView(object):
>>>
"""
+ @deprecation.deprecated(details='StructuredDataView is deprecated. Use TypedDataAccessor or DataVariable.value instead.')
def __init__(self, bv: 'BinaryView', structure_name: '_types.QualifiedNameType', address: int):
self._bv = bv
self._structure_name = structure_name