summaryrefslogtreecommitdiff
path: root/python/platform.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-03-05 16:09:30 -0500
committerRyan Snyder <ryan@vector35.com>2018-07-10 18:11:08 -0400
commitd4d1fbb390c9a31045cea8e612c02e242d11c438 (patch)
tree11a1fcd229d1efc81440080ae0a26dda67b584f6 /python/platform.py
parent8849fb2b2b8dc824bd3f17ce1026a04856477a94 (diff)
Additional changes for python 2/3 compatibility
Diffstat (limited to 'python/platform.py')
-rw-r--r--python/platform.py92
1 files changed, 45 insertions, 47 deletions
diff --git a/python/platform.py b/python/platform.py
index ff59be50..083ebf06 100644
--- a/python/platform.py
+++ b/python/platform.py
@@ -21,6 +21,7 @@
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
#2-3 compatibility
@@ -28,11 +29,11 @@ from six import with_metaclass
class _PlatformMetaClass(type):
- from binaryninja import startup
+
from binaryninja import types
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
result = []
@@ -43,7 +44,7 @@ class _PlatformMetaClass(type):
@property
def os_list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformOSList(count)
result = []
@@ -53,7 +54,7 @@ class _PlatformMetaClass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
try:
@@ -69,14 +70,14 @@ class _PlatformMetaClass(type):
raise AttributeError("attribute '%s' is read only" % name)
def __getitem__(cls, value):
- startup._init_plugins()
+ binaryninja._init_plugins()
platform = core.BNGetPlatformByName(str(value))
if platform is None:
raise KeyError("'%s' is not a valid platform" % str(value))
return Platform(None, platform)
def get_list(cls, os = None, arch = None):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
if os is None:
platforms = core.BNGetPlatformList(count)
@@ -96,9 +97,6 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
``class Platform`` contains all information releated to the execution environment of the binary, mainly the
calling conventions used.
"""
- from binaryninja import architecture
- from binaryninja import callingconvention
- from binaryninja import types
name = None
def __init__(self, arch, handle = None):
@@ -108,7 +106,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
else:
self.handle = handle
self.__dict__["name"] = core.BNGetPlatformName(self.handle)
- self.arch = architecture.CoreArchitecture._from_cache(core.BNGetPlatformArchitecture(self.handle))
+ self.arch = binaryninja.architecture.CoreArchitecture._from_cache(core.BNGetPlatformArchitecture(self.handle))
def __del__(self):
core.BNFreePlatform(self.handle)
@@ -140,7 +138,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
result = core.BNGetPlatformDefaultCallingConvention(self.handle)
if result is None:
return None
- return callingconvention.CallingConvention(handle=result)
+ return binaryninja.callingconvention.CallingConvention(handle=result)
@default_calling_convention.setter
def default_calling_convention(self, value):
@@ -158,7 +156,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
result = core.BNGetPlatformCdeclCallingConvention(self.handle)
if result is None:
return None
- return callingconvention.CallingConvention(handle=result)
+ return binaryninja.callingconvention.CallingConvention(handle=result)
@cdecl_calling_convention.setter
def cdecl_calling_convention(self, value):
@@ -176,7 +174,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
result = core.BNGetPlatformStdcallCallingConvention(self.handle)
if result is None:
return None
- return callingconvention.CallingConvention(handle=result)
+ return binaryninja.callingconvention.CallingConvention(handle=result)
@stdcall_calling_convention.setter
def stdcall_calling_convention(self, value):
@@ -194,7 +192,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
result = core.BNGetPlatformFastcallCallingConvention(self.handle)
if result is None:
return None
- return callingconvention.CallingConvention(handle=result)
+ return binaryninja.callingconvention.CallingConvention(handle=result)
@fastcall_calling_convention.setter
def fastcall_calling_convention(self, value):
@@ -212,7 +210,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
result = core.BNGetPlatformSystemCallConvention(self.handle)
if result is None:
return None
- return callingconvention.CallingConvention(handle=result)
+ return binaryninja.callingconvention.CallingConvention(handle=result)
@system_call_convention.setter
def system_call_convention(self, value):
@@ -230,7 +228,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
cc = core.BNGetPlatformCallingConventions(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i])))
+ result.append(binaryninja.callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i])))
core.BNFreeCallingConventionList(cc, count.value)
return result
@@ -241,8 +239,8 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
type_list = core.BNGetPlatformTypes(self.handle, count)
result = {}
for i in xrange(0, count.value):
- name = types.QualifiedName._from_core_struct(type_list[i].name)
- result[name] = types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
+ result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
return result
@@ -253,8 +251,8 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
type_list = core.BNGetPlatformVariables(self.handle, count)
result = {}
for i in xrange(0, count.value):
- name = types.QualifiedName._from_core_struct(type_list[i].name)
- result[name] = types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
+ result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
return result
@@ -265,8 +263,8 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
type_list = core.BNGetPlatformFunctions(self.handle, count)
result = {}
for i in xrange(0, count.value):
- name = types.QualifiedName._from_core_struct(type_list[i].name)
- result[name] = types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(type_list[i].name)
+ result[name] = binaryninja.types.Type(core.BNNewTypeReference(type_list[i].type), platform = self)
core.BNFreeTypeList(type_list, count.value)
return result
@@ -277,8 +275,8 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
call_list = core.BNGetPlatformSystemCalls(self.handle, count)
result = {}
for i in xrange(0, count.value):
- name = types.QualifiedName._from_core_struct(call_list[i].name)
- t = types.Type(core.BNNewTypeReference(call_list[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(call_list[i].name)
+ t = binaryninja.types.Type(core.BNNewTypeReference(call_list[i].type), platform = self)
result[call_list[i].number] = (name, t)
core.BNFreeSystemCallList(call_list, count.value)
return result
@@ -329,25 +327,25 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
return Platform(None, handle = result), new_addr.value
def get_type_by_name(self, name):
- name = types.QualifiedName(name)._get_core_struct()
+ name = binaryninja.types.QualifiedName(name)._get_core_struct()
obj = core.BNGetPlatformTypeByName(self.handle, name)
if not obj:
return None
- return types.Type(obj, platform = self)
+ return binaryninja.types.Type(obj, platform = self)
def get_variable_by_name(self, name):
- name = types.QualifiedName(name)._get_core_struct()
+ name = binaryninja.types.QualifiedName(name)._get_core_struct()
obj = core.BNGetPlatformVariableByName(self.handle, name)
if not obj:
return None
- return types.Type(obj, platform = self)
+ return binaryninja.types.Type(obj, platform = self)
def get_function_by_name(self, name):
- name = types.QualifiedName(name)._get_core_struct()
+ name = binaryninja.types.QualifiedName(name)._get_core_struct()
obj = core.BNGetPlatformFunctionByName(self.handle, name)
if not obj:
return None
- return types.Type(obj, platform = self)
+ return binaryninja.types.Type(obj, platform = self)
def get_system_call_name(self, number):
return core.BNGetPlatformSystemCallName(self.handle, number)
@@ -356,15 +354,15 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
obj = core.BNGetPlatformSystemCallType(self.handle, number)
if not obj:
return None
- return types.Type(obj, platform = self)
+ return binaryninja.types.Type(obj, platform = self)
def generate_auto_platform_type_id(self, name):
- name = types.QualifiedName(name)._get_core_struct()
+ name = binaryninja.types.QualifiedName(name)._get_core_struct()
return core.BNGenerateAutoPlatformTypeId(self.handle, name)
def generate_auto_platform_type_ref(self, type_class, name):
type_id = self.generate_auto_platform_type_id(name)
- return types.NamedTypeReference(type_class, type_id, name)
+ return binaryninja.types.NamedTypeReference(type_class, type_id, name)
def get_auto_platform_type_id_source(self):
return core.BNGetAutoPlatformTypeIdSource(self.handle)
@@ -405,16 +403,16 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
variables = {}
functions = {}
for i in xrange(0, parse.typeCount):
- name = types.QualifiedName._from_core_struct(parse.types[i].name)
- type_dict[name] = types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.types[i].name)
+ type_dict[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
for i in xrange(0, parse.variableCount):
- name = types.QualifiedName._from_core_struct(parse.variables[i].name)
- variables[name] = types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.variables[i].name)
+ variables[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
for i in xrange(0, parse.functionCount):
- name = types.QualifiedName._from_core_struct(parse.functions[i].name)
- functions[name] = types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.functions[i].name)
+ functions[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
core.BNFreeTypeParserResult(parse)
- return types.TypeParserResult(type_dict, variables, functions)
+ return binaryninja.types.TypeParserResult(type_dict, variables, functions)
def parse_types_from_source_file(self, filename, include_dirs=[], auto_type_source=None):
"""
@@ -451,13 +449,13 @@ class Platform(with_metaclass(_PlatformMetaClass, object)):
variables = {}
functions = {}
for i in xrange(0, parse.typeCount):
- name = types.QualifiedName._from_core_struct(parse.types[i].name)
- type_dict[name] = types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.types[i].name)
+ type_dict[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.types[i].type), platform = self)
for i in xrange(0, parse.variableCount):
- name = types.QualifiedName._from_core_struct(parse.variables[i].name)
- variables[name] = types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.variables[i].name)
+ variables[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.variables[i].type), platform = self)
for i in xrange(0, parse.functionCount):
- name = types.QualifiedName._from_core_struct(parse.functions[i].name)
- functions[name] = types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
+ name = binaryninja.types.QualifiedName._from_core_struct(parse.functions[i].name)
+ functions[name] = binaryninja.types.Type(core.BNNewTypeReference(parse.functions[i].type), platform = self)
core.BNFreeTypeParserResult(parse)
- return types.TypeParserResult(type_dict, variables, functions)
+ return binaryninja.types.TypeParserResult(type_dict, variables, functions)