summaryrefslogtreecommitdiff
path: root/python/lineardisassembly.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2020-05-02 11:01:35 -0400
committerPeter LaFosse <peter@vector35.com>2020-05-03 13:20:56 -0400
commit8f1bc5944b849f3ad0cbbd5972d5ab9948ed4d57 (patch)
tree43b48da8a1ec93b148575bc3346059e5316e6bf6 /python/lineardisassembly.py
parent5b84fdea8abcb4abba61d07e0d12b4115b516c52 (diff)
Fix up equality operators and had hash operators
Diffstat (limited to 'python/lineardisassembly.py')
-rw-r--r--python/lineardisassembly.py175
1 files changed, 94 insertions, 81 deletions
diff --git a/python/lineardisassembly.py b/python/lineardisassembly.py
index 3e49f5ee..44f0aeb9 100644
--- a/python/lineardisassembly.py
+++ b/python/lineardisassembly.py
@@ -35,12 +35,12 @@ class LinearDisassemblyLine(object):
self.block = block
self.contents = contents
- def __str__(self):
- return str(self.contents)
-
def __repr__(self):
return repr(self.contents)
+ def __str__(self):
+ return str(self.contents)
+
class LinearViewObjectIdentifier(object):
def __init__(self, name, start = None, end = None):
@@ -48,29 +48,8 @@ class LinearViewObjectIdentifier(object):
self._start = start
self._end = end
- @property
- def name(self):
- return self._name
-
- @property
- def address(self):
- return self._start
-
- @property
- def start(self):
- return self._start
-
- @property
- def end(self):
- return self._end
-
- @property
- def has_address(self):
- return self._start is not None
-
- @property
- def has_range(self):
- return self._start is not None and self._end is not None
+ def __repr__(self):
+ return "<LinearViewObjectIdentifier: " + str(self) + ">"
def __str__(self):
if not self.has_address:
@@ -79,8 +58,18 @@ class LinearViewObjectIdentifier(object):
return "%s 0x%x-0x%x" % (self._name, self._start, self._end)
return "%s 0x%x" % (self._name, self._start)
- def __repr__(self):
- return "<LinearViewObjectIdentifier: " + str(self) + ">"
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return (self._name, self._start, self._end) == (other._name, other._start, other._end)
+
+ def __ne__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return not (self == other)
+
+ def __hash__(self):
+ return hash((self._name, self._start, self._end))
def _to_api_object(self, obj = None):
if obj is None:
@@ -102,6 +91,30 @@ class LinearViewObjectIdentifier(object):
result.end = 0
return result
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def address(self):
+ return self._start
+
+ @property
+ def start(self):
+ return self._start
+
+ @property
+ def end(self):
+ return self._end
+
+ @property
+ def has_address(self):
+ return self._start is not None
+
+ @property
+ def has_range(self):
+ return self._start is not None and self._end is not None
+
@classmethod
def _from_api_object(cls, obj):
if obj.type == LinearViewObjectIdentifierType.AddressLinearViewObject:
@@ -121,6 +134,18 @@ class LinearViewObject(object):
def __del__(self):
core.BNFreeLinearViewObject(self.handle)
+ def __repr__(self):
+ return "<LinearViewObject: " + str(self) + ">"
+
+ def __len__(self):
+ return self.end - self.start
+
+ def __str__(self):
+ result = str(self.identifier)
+ if self._parent is not None:
+ result = str(self._parent) + "/" + result
+ return result
+
@property
def first_child(self):
result = core.BNGetFirstLinearViewObjectChild(self.handle)
@@ -189,18 +214,6 @@ class LinearViewObject(object):
def ordering_index_total(self):
return core.BNGetLinearViewObjectOrderingIndexTotal(self.handle)
- def __len__(self):
- return self.end - self.start
-
- def __str__(self):
- result = str(self.identifier)
- if self._parent is not None:
- result = str(self._parent) + "/" + result
- return result
-
- def __repr__(self):
- return "<LinearViewObject: " + str(self) + ">"
-
def child_for_address(self, addr):
result = core.BNGetLinearViewObjectChildForAddress(self.handle, addr)
if not result:
@@ -323,6 +336,47 @@ class LinearViewCursor(object):
def __del__(self):
core.BNFreeLinearViewCursor(self.handle)
+ def __repr__(self):
+ return "<LinearViewCursor: " + str(self.current_object) + ">"
+
+ def __str__(self):
+ return str(self.current_object)
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) == 0
+
+ def __ne__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) != 0
+
+ def __lt__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) < 0
+
+ def __le__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) <= 0
+
+ def __gt__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) > 0
+
+ def __ge__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other) >= 0
+
+ def __cmp__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return LinearViewCursor.compare(self, other)
+
@property
def before_begin(self):
return core.BNIsLinearViewCursorBeforeBegin(self.handle)
@@ -431,47 +485,6 @@ class LinearViewCursor(object):
def duplicate(self):
return LinearViewCursor(None, handle = core.BNDuplicateLinearViewCursor(self.handle))
- def __str__(self):
- return str(self.current_object)
-
- def __repr__(self):
- return "<LinearViewCursor: " + str(self.current_object) + ">"
-
- def __eq__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) == 0
- return False
-
- def __ne__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) != 0
- return True
-
- def __lt__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) < 0
- return False
-
- def __le__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) <= 0
- return False
-
- def __gt__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) > 0
- return False
-
- def __ge__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other) >= 0
- return False
-
- def __cmp__(self, other):
- if isinstance(other, LinearViewCursor):
- return LinearViewCursor.compare(self, other)
- return 0
-
@classmethod
def compare(cls, a, b):
return core.BNCompareLinearViewCursors(a.handle, b.handle)