From 8f1bc5944b849f3ad0cbbd5972d5ab9948ed4d57 Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sat, 2 May 2020 11:01:35 -0400 Subject: Fix up equality operators and had hash operators --- python/platform.py | 74 +++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 43 deletions(-) (limited to 'python/platform.py') 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 "" % 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 "" % self.name - - def __str__(self): - return self.name - def register(self, os): """ ``register`` registers the platform for given OS name. -- cgit v1.3.1