summaryrefslogtreecommitdiff
path: root/python/platform.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/platform.py
parent5b84fdea8abcb4abba61d07e0d12b4115b516c52 (diff)
Fix up equality operators and had hash operators
Diffstat (limited to 'python/platform.py')
-rw-r--r--python/platform.py74
1 files changed, 31 insertions, 43 deletions
diff --git a/python/platform.py b/python/platform.py
index b4163892..9059e1c4 100644
--- a/python/platform.py
+++ b/python/platform.py
@@ -32,6 +32,23 @@ from binaryninja import with_metaclass
class _PlatformMetaClass(type):
+ def __iter__(self):
+ binaryninja._init_plugins()
+ count = ctypes.c_ulonglong()
+ platforms = core.BNGetPlatformList(count)
+ try:
+ for i in range(0, count.value):
+ yield Platform(handle = core.BNNewPlatformReference(platforms[i]))
+ finally:
+ core.BNFreePlatformList(platforms, count.value)
+
+ def __getitem__(cls, value):
+ binaryninja._init_plugins()
+ platform = core.BNGetPlatformByName(str(value))
+ if platform is None:
+ raise KeyError("'%s' is not a valid platform" % str(value))
+ return Platform(handle = platform)
+
@property
def list(self):
binaryninja._init_plugins()
@@ -54,29 +71,6 @@ class _PlatformMetaClass(type):
core.BNFreePlatformOSList(platforms, count.value)
return result
- def __iter__(self):
- binaryninja._init_plugins()
- count = ctypes.c_ulonglong()
- platforms = core.BNGetPlatformList(count)
- try:
- for i in range(0, count.value):
- yield Platform(handle = core.BNNewPlatformReference(platforms[i]))
- finally:
- core.BNFreePlatformList(platforms, count.value)
-
- def __setattr__(self, name, value):
- try:
- type.__setattr__(self, name, value)
- except AttributeError:
- raise AttributeError("attribute '%s' is read only" % name)
-
- def __getitem__(cls, value):
- binaryninja._init_plugins()
- platform = core.BNGetPlatformByName(str(value))
- if platform is None:
- raise KeyError("'%s' is not a valid platform" % str(value))
- return Platform(handle = platform)
-
def get_list(cls, os = None, arch = None):
binaryninja._init_plugins()
count = ctypes.c_ulonglong()
@@ -116,15 +110,21 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
if self.handle is not None:
core.BNFreePlatform(self.handle)
- def __eq__(self, value):
- if not isinstance(value, Platform):
- return False
- return ctypes.addressof(self.handle.contents) == ctypes.addressof(value.handle.contents)
+ def __repr__(self):
+ return "<platform: %s>" % self.name
- def __ne__(self, value):
- if not isinstance(value, Platform):
- return True
- return ctypes.addressof(self.handle.contents) != ctypes.addressof(value.handle.contents)
+ def __str__(self):
+ return self.name
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return ctypes.addressof(self.handle.contents) == ctypes.addressof(other.handle.contents)
+
+ def __ne__(self, other):
+ if not isinstance(other, self.__class__):
+ return NotImplemented
+ return not (self == other)
@property
def list(self):
@@ -305,18 +305,6 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
core.BNFreeTypeLibraryList(libs, count.value)
return result
- def __setattr__(self, name, value):
- try:
- object.__setattr__(self, name, value)
- except AttributeError:
- raise AttributeError("attribute '%s' is read only" % name)
-
- def __repr__(self):
- return "<platform: %s>" % self.name
-
- def __str__(self):
- return self.name
-
def register(self, os):
"""
``register`` registers the platform for given OS name.