summaryrefslogtreecommitdiff
path: root/python/platform.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-08-29 15:26:00 -0400
committerPeter LaFosse <peter@vector35.com>2018-08-31 14:21:07 -0400
commitf0ccb75e7d80a6c0ae8b01d794b929f03bc6ea6d (patch)
tree7569fe7689062b265329ad0f649705aa8caab922 /python/platform.py
parenta6b801afadada75afd2b1779edee8d203f3b3140 (diff)
parent426bb3d8b47b93658bf969c429a8b98adae13c30 (diff)
Merging with dev
Diffstat (limited to 'python/platform.py')
-rw-r--r--python/platform.py78
1 files changed, 40 insertions, 38 deletions
diff --git a/python/platform.py b/python/platform.py
index dd756178..9a5f70df 100644
--- a/python/platform.py
+++ b/python/platform.py
@@ -21,42 +21,45 @@
import ctypes
# Binary Ninja components
-import _binaryninjacore as core
-import startup
-import architecture
-import callingconvention
-import types
+import binaryninja
+from binaryninja import _binaryninjacore as core
+from binaryninja import types
+
+# 2-3 compatibility
+from binaryninja import range
+from binaryninja import with_metaclass
class _PlatformMetaClass(type):
+
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Platform(None, core.BNNewPlatformReference(platforms[i])))
core.BNFreePlatformList(platforms, count.value)
return result
@property
def os_list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformOSList(count)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(str(platforms[i]))
core.BNFreePlatformOSList(platforms, count.value)
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
platforms = core.BNGetPlatformList(count)
try:
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
yield Platform(None, core.BNNewPlatformReference(platforms[i]))
finally:
core.BNFreePlatformList(platforms, count.value)
@@ -68,14 +71,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)
@@ -84,18 +87,17 @@ class _PlatformMetaClass(type):
else:
platforms = core.BNGetPlatformListByArchitecture(os, arch.handle)
result = []
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
result.append(Platform(None, core.BNNewPlatformReference(platforms[i])))
core.BNFreePlatformList(platforms, count.value)
return result
-class Platform(object):
+class Platform(with_metaclass(_PlatformMetaClass, object)):
"""
``class Platform`` contains all information releated to the execution environment of the binary, mainly the
calling conventions used.
"""
- __metaclass__ = _PlatformMetaClass
name = None
def __init__(self, arch, handle = None):
@@ -105,7 +107,7 @@ class Platform(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)
@@ -137,7 +139,7 @@ class Platform(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):
@@ -155,7 +157,7 @@ class Platform(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):
@@ -173,7 +175,7 @@ class Platform(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):
@@ -191,7 +193,7 @@ class Platform(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):
@@ -209,7 +211,7 @@ class Platform(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):
@@ -226,8 +228,8 @@ class Platform(object):
count = ctypes.c_ulonglong()
cc = core.BNGetPlatformCallingConventions(self.handle, count)
result = []
- for i in xrange(0, count.value):
- result.append(callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i])))
+ for i in range(0, count.value):
+ result.append(binaryninja.callingconvention.CallingConvention(handle=core.BNNewCallingConventionReference(cc[i])))
core.BNFreeCallingConventionList(cc, count.value)
return result
@@ -237,7 +239,7 @@ class Platform(object):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformTypes(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(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)
core.BNFreeTypeList(type_list, count.value)
@@ -249,7 +251,7 @@ class Platform(object):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformVariables(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(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)
core.BNFreeTypeList(type_list, count.value)
@@ -261,7 +263,7 @@ class Platform(object):
count = ctypes.c_ulonglong(0)
type_list = core.BNGetPlatformFunctions(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(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)
core.BNFreeTypeList(type_list, count.value)
@@ -273,7 +275,7 @@ class Platform(object):
count = ctypes.c_ulonglong(0)
call_list = core.BNGetPlatformSystemCalls(self.handle, count)
result = {}
- for i in xrange(0, count.value):
+ for i in range(0, count.value):
name = types.QualifiedName._from_core_struct(call_list[i].name)
t = types.Type(core.BNNewTypeReference(call_list[i].type), platform = self)
result[call_list[i].number] = (name, t)
@@ -388,8 +390,8 @@ class Platform(object):
if filename is None:
filename = "input"
dir_buf = (ctypes.c_char_p * len(include_dirs))()
- for i in xrange(0, len(include_dirs)):
- dir_buf[i] = str(include_dirs[i])
+ for i in range(0, len(include_dirs)):
+ dir_buf[i] = include_dirs[i].encode('charmap')
parse = core.BNTypeParserResult()
errors = ctypes.c_char_p()
result = core.BNParseTypesFromSource(self.handle, source, filename, parse, errors, dir_buf,
@@ -401,13 +403,13 @@ class Platform(object):
type_dict = {}
variables = {}
functions = {}
- for i in xrange(0, parse.typeCount):
+ for i in range(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)
- for i in xrange(0, parse.variableCount):
+ for i in range(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)
- for i in xrange(0, parse.functionCount):
+ for i in range(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)
core.BNFreeTypeParserResult(parse)
@@ -434,8 +436,8 @@ class Platform(object):
>>>
"""
dir_buf = (ctypes.c_char_p * len(include_dirs))()
- for i in xrange(0, len(include_dirs)):
- dir_buf[i] = str(include_dirs[i])
+ for i in range(0, len(include_dirs)):
+ dir_buf[i] = include_dirs[i].encode('charmap')
parse = core.BNTypeParserResult()
errors = ctypes.c_char_p()
result = core.BNParseTypesFromSourceFile(self.handle, filename, parse, errors, dir_buf,
@@ -447,13 +449,13 @@ class Platform(object):
type_dict = {}
variables = {}
functions = {}
- for i in xrange(0, parse.typeCount):
+ for i in range(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)
- for i in xrange(0, parse.variableCount):
+ for i in range(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)
- for i in xrange(0, parse.functionCount):
+ for i in range(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)
core.BNFreeTypeParserResult(parse)