summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py49
-rw-r--r--python/architecture.py50
-rw-r--r--python/basicblock.py17
-rw-r--r--python/binaryview.py120
-rw-r--r--python/callingconvention.py44
-rw-r--r--python/fileaccessor.py2
-rw-r--r--python/filemetadata.py15
-rw-r--r--python/function.py55
-rw-r--r--python/functionrecognizer.py6
-rw-r--r--python/interaction.py2
-rw-r--r--python/lowlevelil.py47
-rw-r--r--python/mediumlevelil.py48
-rw-r--r--python/platform.py92
-rw-r--r--python/plugin.py60
-rw-r--r--python/pluginmanager.py4
-rw-r--r--python/scriptingprovider.py52
-rw-r--r--python/startup.py22
-rw-r--r--python/transform.py15
-rw-r--r--python/types.py13
-rw-r--r--python/undoaction.py6
-rw-r--r--python/update.py10
21 files changed, 363 insertions, 366 deletions
diff --git a/python/__init__.py b/python/__init__.py
index 66f4bfe8..d88703cc 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -22,10 +22,41 @@
from __future__ import absolute_import
import atexit
import sys
+import ctypes
from time import gmtime
# Binary Ninja components
-from binaryninja import _binaryninjacore as core
+import binaryninja._binaryninjacore as core
+# __all__ = [
+# "enums",
+# "databuffer",
+# "filemetadata",
+# "fileaccessor",
+# "binaryview",
+# "transform",
+# "architecture",
+# "basicblock",
+# "function",
+# "log",
+# "lowlevelil",
+# "mediumlevelil",
+# "types",
+# "functionrecognizer",
+# "update",
+# "plugin",
+# "callingconvention",
+# "platform",
+# "demangle",
+# "mainthread",
+# "interaction",
+# "lineardisassembly",
+# "undoaction",
+# "highlight",
+# "scriptingprovider",
+# "pluginmanager",
+# "setting",
+# "metadata",
+# ]
from binaryninja.enums import *
from binaryninja.databuffer import *
from binaryninja.filemetadata import *
@@ -116,7 +147,7 @@ class PluginManagerLoadPluginCallback(object):
load_plugin = PluginManagerLoadPluginCallback()
-core.BNRegisterForPluginLoading(_plugin_api_name, load_plugin.cb, 0)
+core.BNRegisterForPluginLoading(_plugin_api_name.encode("utf8"), load_plugin.cb, 0)
class _DestructionCallbackHandler(object):
@@ -138,6 +169,20 @@ class _DestructionCallbackHandler(object):
Function._unregister(func)
+_plugin_init = False
+
+
+def _init_plugins():
+ global _plugin_init
+ if not _plugin_init:
+ _plugin_init = True
+ core.BNInitCorePlugins()
+ core.BNInitUserPlugins()
+ core.BNInitRepoPlugins()
+ if not core.BNIsLicenseValidated():
+ raise RuntimeError("License is not valid. Please supply a valid license.")
+
+
_destruct_callbacks = _DestructionCallbackHandler()
bundled_plugin_path = core.BNGetBundledPluginDirectory()
diff --git a/python/architecture.py b/python/architecture.py
index 360ce6bf..a705f2d9 100644
--- a/python/architecture.py
+++ b/python/architecture.py
@@ -27,16 +27,24 @@ import abc
from binaryninja import _binaryninjacore as core
from binaryninja.enums import (Endianness, ImplicitRegisterExtend, BranchType,
InstructionTextTokenType, LowLevelILFlagCondition, FlagRole)
+import binaryninja
+from binaryninja import log
-#2-3 compatibility
+from binaryninja import lowlevelil
+from binaryninja import types
+from binaryninja import databuffer
+from binaryninja import platform
+from binaryninja import callingconvention
+
+# 2-3 compatibility
from six import with_metaclass
class _ArchitectureMetaClass(type):
- from binaryninja import startup
+
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
archs = core.BNGetArchitectureList(count)
result = []
@@ -46,7 +54,7 @@ class _ArchitectureMetaClass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
archs = core.BNGetArchitectureList(count)
try:
@@ -56,14 +64,14 @@ class _ArchitectureMetaClass(type):
core.BNFreeArchitectureList(archs)
def __getitem__(cls, name):
- startup._init_plugins()
+ binaryninja._init_plugins()
arch = core.BNGetArchitectureByName(name)
if arch is None:
raise KeyError("'%s' is not a valid architecture" % str(name))
return CoreArchitecture._from_cache(arch)
def register(cls):
- startup._init_plugins()
+ binaryninja._init_plugins()
if cls.name is None:
raise ValueError("architecture 'name' is not defined")
arch = cls()
@@ -130,15 +138,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
next_address = 0
def __init__(self):
- from binaryninja import function
- from binaryninja import startup
- from binaryninja import lowlevelil
- from binaryninja import types
- from binaryninja import databuffer
- from binaryninja import log
- from binaryninja import platform
- from binaryninja import callingconvention
- startup._init_plugins()
+ binaryninja._init_plugins()
if self.__class__.opcode_display_length > self.__class__.max_instr_length:
self.__class__.opcode_display_length = self.__class__.max_instr_length
@@ -371,9 +371,9 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
info = self.__class__.intrinsics[intrinsic]
for i in xrange(0, len(info.inputs)):
if isinstance(info.inputs[i], types.Type):
- info.inputs[i] = function.IntrinsicInput(info.inputs[i])
+ info.inputs[i] = binaryninja.function.IntrinsicInput(info.inputs[i])
elif isinstance(info.inputs[i], tuple):
- info.inputs[i] = function.IntrinsicInput(info.inputs[i][0], info.inputs[i][1])
+ info.inputs[i] = binaryninja.function.IntrinsicInput(info.inputs[i][0], info.inputs[i][1])
info.index = intrinsic_index
self._intrinsics[intrinsic] = intrinsic_index
self._intrinsics_by_index[intrinsic_index] = (intrinsic, info)
@@ -2049,10 +2049,6 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)):
_architecture_cache = {}
class CoreArchitecture(Architecture):
def __init__(self, handle):
- from binaryninja import function
- from binaryninja import types
- from binaryninja import databuffer
- from binaryninja import lowlevelil
super(CoreArchitecture, self).__init__()
self.handle = core.handle_of_type(handle, core.BNArchitecture)
@@ -2082,7 +2078,7 @@ class CoreArchitecture(Architecture):
name = core.BNGetArchitectureRegisterName(self.handle, regs[i])
info = core.BNGetArchitectureRegisterInfo(self.handle, regs[i])
full_width_reg = core.BNGetArchitectureRegisterName(self.handle, info.fullWidthRegister)
- self.regs[name] = function.RegisterInfo(full_width_reg, info.size, info.offset,
+ self.regs[name] = binaryninja.function.RegisterInfo(full_width_reg, info.size, info.offset,
ImplicitRegisterExtend(info.extend), regs[i])
self._all_regs[name] = regs[i]
self._regs_by_index[regs[i]] = name
@@ -2240,7 +2236,7 @@ class CoreArchitecture(Architecture):
for j in xrange(0, info.topRelativeCount):
top_rel.append(core.BNGetArchitectureRegisterName(self.handle, info.firstTopRelativeReg + j))
top = core.BNGetArchitectureRegisterName(self.handle, info.stackTopReg)
- self.reg_stacks[name] = function.RegisterStackInfo(storage, top_rel, top, regs[i])
+ self.reg_stacks[name] = binaryninja.function.RegisterStackInfo(storage, top_rel, top, regs[i])
self._all_reg_stacks[name] = regs[i]
self._reg_stacks_by_index[regs[i]] = name
core.BNFreeRegisterList(regs)
@@ -2258,7 +2254,7 @@ class CoreArchitecture(Architecture):
for j in xrange(0, input_count.value):
input_name = inputs[j].name
type_obj = types.Type(core.BNNewTypeReference(inputs[j].type), confidence = inputs[j].typeConfidence)
- input_list.append(function.IntrinsicInput(type_obj, input_name))
+ input_list.append(binaryninja.function.IntrinsicInput(type_obj, input_name))
core.BNFreeNameAndTypeList(inputs, input_count.value)
output_count = ctypes.c_ulonglong()
outputs = core.BNGetArchitectureIntrinsicOutputs(self.handle, intrinsics[i], output_count)
@@ -2266,7 +2262,7 @@ class CoreArchitecture(Architecture):
for j in xrange(0, output_count.value):
output_list.append(types.Type(core.BNNewTypeReference(outputs[j].type), confidence = outputs[j].confidence))
core.BNFreeOutputTypeList(outputs, output_count.value)
- self.intrinsics[name] = function.IntrinsicInfo(input_list, output_list)
+ self.intrinsics[name] = binaryninja.function.IntrinsicInfo(input_list, output_list)
self._intrinsics[name] = intrinsics[i]
self._intrinsics_by_index[intrinsics[i]] = (name, self.intrinsics[name])
core.BNFreeRegisterList(intrinsics)
@@ -2303,7 +2299,7 @@ class CoreArchitecture(Architecture):
ctypes.memmove(buf, data, len(data))
if not core.BNGetInstructionInfo(self.handle, buf, addr, len(data), info):
return None
- result = function.InstructionInfo()
+ result = binaryninja.function.InstructionInfo()
result.length = info.length
result.arch_transition_by_target_addr = info.archTransitionByTargetAddr
result.branch_delay = info.branchDelay
@@ -2345,7 +2341,7 @@ class CoreArchitecture(Architecture):
context = tokens[i].context
confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeInstructionText(tokens, count.value)
return result, length.value
diff --git a/python/basicblock.py b/python/basicblock.py
index 907b4065..ee754863 100644
--- a/python/basicblock.py
+++ b/python/basicblock.py
@@ -21,6 +21,8 @@
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
+from binaryninja import highlight
from binaryninja import _binaryninjacore as core
from binaryninja.enums import BranchType, HighlightColorStyle, HighlightStandardColor, InstructionTextTokenType
@@ -51,9 +53,6 @@ class BasicBlockEdge(object):
class BasicBlock(object):
def __init__(self, view, handle):
- from binaryninja import architecture
- from binaryninja import function
- from binaryninja import highlight
self.view = view
self.handle = core.handle_of_type(handle, core.BNBasicBlock)
self._arch = None
@@ -87,7 +86,7 @@ class BasicBlock(object):
func = core.BNGetBasicBlockFunction(self.handle)
if func is None:
return None
- self._func = function.Function(self.view, func)
+ self._func =binaryninja.function.Function(self.view, func)
return self._func
@property
@@ -100,7 +99,7 @@ class BasicBlock(object):
arch = core.BNGetBasicBlockArchitecture(self.handle)
if arch is None:
return None
- self._arch = architecture.CoreArchitecture._from_cache(arch)
+ self._arch = binaryninja.architecture.CoreArchitecture._from_cache(arch)
return self._arch
@property
@@ -225,7 +224,7 @@ class BasicBlock(object):
@property
def disassembly_text(self):
"""
- ``disassembly_text`` property which returns a list of function.DisassemblyTextLine objects for the current basic block.
+ ``disassembly_text`` property which returns a list of binaryninja.function.DisassemblyTextLine objects for the current basic block.
:Example:
>>> current_basic_block.disassembly_text
@@ -322,7 +321,7 @@ class BasicBlock(object):
def get_disassembly_text(self, settings=None):
"""
- ``get_disassembly_text`` returns a list of function.DisassemblyTextLine objects for the current basic block.
+ ``get_disassembly_text`` returns a list of binaryninja.function.DisassemblyTextLine objects for the current basic block.
:param DisassemblySettings settings: (optional) DisassemblySettings object
:Example:
@@ -353,8 +352,8 @@ class BasicBlock(object):
context = lines[i].tokens[j].context
confidence = lines[i].tokens[j].confidence
address = lines[i].tokens[j].address
- tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
- result.append(function.DisassemblyTextLine(addr, tokens, il_instr))
+ tokens.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.DisassemblyTextLine(addr, tokens, il_instr))
core.BNFreeDisassemblyTextLines(lines, count.value)
return result
diff --git a/python/binaryview.py b/python/binaryview.py
index f6a1bc83..b3314c5c 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -22,15 +22,22 @@ import struct
import traceback
import ctypes
import abc
-import threading
# Binary Ninja components -- additional imports belong in the appropriate class
from binaryninja import _binaryninjacore as core
from binaryninja.enums import (AnalysisState, SymbolType, InstructionTextTokenType,
Endianness, ModificationStatus, StringType, SegmentFlag, SectionSemantics)
+import binaryninja
from binaryninja import associateddatastore # required for _BinaryViewAssociatedDataStore
+from binaryninja import log
+from binaryninja import types
+from binaryninja import fileaccessor
+from binaryninja import databuffer
+from binaryninja import basicblock
+from binaryninja import lineardisassembly
+from binaryninja import metadata
-#2-3 compatibility
+# 2-3 compatibility
from six import with_metaclass
@@ -110,7 +117,6 @@ class AnalysisCompletionEvent(object):
>>>
"""
def __init__(self, view, callback):
- from binaryninja import log
self.view = view
self.callback = callback
self._cb = ctypes.CFUNCTYPE(None, ctypes.c_void_p)(self._notify)
@@ -189,9 +195,6 @@ class DataVariable(object):
class BinaryDataNotificationCallbacks(object):
def __init__(self, view, notify):
- from binaryninja import function
- from binaryninja import types
- from binaryninja import log
self.view = view
self.notify = notify
self._cb = core.BNBinaryDataNotification()
@@ -237,19 +240,19 @@ class BinaryDataNotificationCallbacks(object):
def _function_added(self, ctxt, view, func):
try:
- self.notify.function_added(self.view, function.Function(self.view, core.BNNewFunctionReference(func)))
+ self.notify.function_added(self.view, binaryninja.function.Function(self.view, core.BNNewFunctionReference(func)))
except:
log.log_error(traceback.format_exc())
def _function_removed(self, ctxt, view, func):
try:
- self.notify.function_removed(self.view, function.Function(self.view, core.BNNewFunctionReference(func)))
+ self.notify.function_removed(self.view, binaryninja.function.Function(self.view, core.BNNewFunctionReference(func)))
except:
log.log_error(traceback.format_exc())
def _function_updated(self, ctxt, view, func):
try:
- self.notify.function_updated(self.view, function.Function(self.view, core.BNNewFunctionReference(func)))
+ self.notify.function_updated(self.view, binaryninja.function.Function(self.view, core.BNNewFunctionReference(func)))
except:
log.log_error(traceback.format_exc())
@@ -314,11 +317,11 @@ class BinaryDataNotificationCallbacks(object):
class _BinaryViewTypeMetaclass(type):
- from binaryninja import startup
+
@property
def list(self):
"""List all BinaryView types (read-only)"""
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
types = core.BNGetBinaryViewTypes(count)
result = []
@@ -328,7 +331,7 @@ class _BinaryViewTypeMetaclass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
types = core.BNGetBinaryViewTypes(count)
try:
@@ -338,7 +341,7 @@ class _BinaryViewTypeMetaclass(type):
core.BNFreeBinaryViewTypeList(types)
def __getitem__(self, value):
- startup._init_plugins()
+ binaryninja._init_plugins()
view_type = core.BNGetBinaryViewTypeByName(str(value))
if view_type is None:
raise KeyError("'%s' is not a valid view type" % str(value))
@@ -348,9 +351,6 @@ class _BinaryViewTypeMetaclass(type):
class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
def __init__(self, handle):
- from binaryninja import architecture
- from binaryninja import filemetadata
- from binaryninja import platform
self.handle = core.handle_of_type(handle, core.BNBinaryViewType)
def __eq__(self, value):
@@ -409,7 +409,7 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
if f is None or f.read(len(sqlite)) != sqlite:
return None
f.close()
- view = filemetadata.FileMetadata().open_existing_database(filename)
+ view = binaryninja.filemetadata.FileMetadata().open_existing_database(filename)
else:
view = BinaryView.open(filename)
@@ -437,7 +437,7 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
arch = core.BNGetArchitectureForViewType(self.handle, ident, endian)
if arch is None:
return None
- return architecture.CoreArchitecture._from_cache(arch)
+ return binaryninja.architecture.CoreArchitecture._from_cache(arch)
def register_platform(self, ident, arch, plat):
core.BNRegisterPlatformForViewType(self.handle, ident, arch.handle, plat.handle)
@@ -449,7 +449,7 @@ class BinaryViewType(with_metaclass(_BinaryViewTypeMetaclass, object)):
plat = core.BNGetPlatformForViewType(self.handle, ident, arch.handle)
if plat is None:
return None
- return platform.Platform(None, plat)
+ return binaryninja.platform.Platform(None, plat)
class Segment(object):
@@ -579,18 +579,6 @@ class BinaryView(object):
database (e.g. ``remove_user_function()`` rather than ``remove_function()``). Thus use ``_user_`` methods if saving \
to the database is desired.
"""
- import binaryninja.function
- import binaryninja.architecture
- import binaryninja.platform
- import binaryninja.fileaccessor
- import binaryninja.filemetadata
- import binaryninja.databuffer
- import binaryninja.basicblock
- import binaryninja.types
- import binaryninja.log
- import binaryninja.startup
- import binaryninja.lineardisassembly
- import binaryninja.metadata
name = None
long_name = None
_registered = False
@@ -600,32 +588,20 @@ class BinaryView(object):
_associated_data = {}
def __init__(self, file_metadata=None, parent_view=None, handle=None):
- function = binaryninja.function
- architecture = binaryninja.architecture
- platform = binaryninja.platform
- fileaccessor = binaryninja.fileaccessor
- filemetadata = binaryninja.filemetadata
- databuffer = binaryninja.databuffer
- basicblock = binaryninja.basicblock
- types = binaryninja.types
- log = binaryninja.log
- startup = binaryninja.startup
- lineardisassembly = binaryninja.lineardisassembly
- metadata = binaryninja.metadata
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNBinaryView)
if file_metadata is None:
- self.file = filemetadata.FileMetadata(handle=core.BNGetFileForView(handle))
+ self.file = binaryninja.filemetadata.FileMetadata(handle=core.BNGetFileForView(handle))
else:
self.file = file_metadata
elif self.__class__ is BinaryView:
- startup._init_plugins()
+ binaryninja._init_plugins()
if file_metadata is None:
- file_metadata = filemetadata.FileMetadata()
+ file_metadata = binaryninja.filemetadata.FileMetadata()
self.handle = core.BNCreateBinaryDataView(file_metadata.handle)
- self.file = filemetadata.FileMetadata(handle=core.BNNewFileReference(file_metadata.handle))
+ self.file = binaryninja.filemetadata.FileMetadata(handle=core.BNNewFileReference(file_metadata.handle))
else:
- startup._init_plugins()
+ binaryninja._init_plugins()
if not self.__class__._registered:
raise TypeError("view type not registered")
self._cb = core.BNCustomBinaryView()
@@ -668,7 +644,7 @@ class BinaryView(object):
@classmethod
def register(cls):
- startup._init_plugins()
+ binaryninja._init_plugins()
if cls.name is None:
raise ValueError("view 'name' not defined")
if cls.long_name is None:
@@ -683,7 +659,7 @@ class BinaryView(object):
@classmethod
def _create(cls, ctxt, data):
try:
- file_metadata = filemetadata.FileMetadata(handle=core.BNGetFileForView(data))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle=core.BNGetFileForView(data))
view = cls(BinaryView(file_metadata=file_metadata, handle=core.BNNewViewReference(data)))
if view is None:
return None
@@ -702,14 +678,14 @@ class BinaryView(object):
@classmethod
def open(cls, src, file_metadata=None):
- binaryninja.startup._init_plugins()
+ binaryninja._init_plugins()
if isinstance(src, fileaccessor.FileAccessor):
if file_metadata is None:
- file_metadata = filemetadata.FileMetadata()
+ file_metadata = binaryninja.filemetadata.FileMetadata()
view = core.BNCreateBinaryDataViewFromFile(file_metadata.handle, src._cb)
else:
if file_metadata is None:
- file_metadata = filemetadata.FileMetadata(str(src))
+ file_metadata = binaryninja.filemetadata.FileMetadata(str(src))
view = core.BNCreateBinaryDataViewFromFilename(file_metadata.handle, str(src))
if view is None:
return None
@@ -718,9 +694,9 @@ class BinaryView(object):
@classmethod
def new(cls, data=None, file_metadata=None):
- startup._init_plugins()
+ binaryninja._init_plugins()
if file_metadata is None:
- file_metadata = filemetadata.FileMetadata()
+ file_metadata = binaryninja.filemetadata.FileMetadata()
if data is None:
view = core.BNCreateBinaryDataView(file_metadata.handle)
else:
@@ -805,7 +781,7 @@ class BinaryView(object):
funcs = core.BNGetAnalysisFunctionList(self.handle, count)
try:
for i in xrange(0, count.value):
- yield function.Function(self, core.BNNewFunctionReference(funcs[i]))
+ yield binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i]))
finally:
core.BNFreeFunctionList(funcs, count.value)
@@ -873,7 +849,7 @@ class BinaryView(object):
arch = core.BNGetDefaultArchitecture(self.handle)
if arch is None:
return None
- return architecture.CoreArchitecture._from_cache(handle=arch)
+ return binaryninja.architecture.CoreArchitecture._from_cache(handle=arch)
@arch.setter
def arch(self, value):
@@ -888,7 +864,7 @@ class BinaryView(object):
plat = core.BNGetDefaultPlatform(self.handle)
if plat is None:
return None
- return platform.Platform(self.arch, handle=plat)
+ return binaryninja.platform.Platform(self.arch, handle=plat)
@platform.setter
def platform(self, value):
@@ -924,7 +900,7 @@ class BinaryView(object):
funcs = core.BNGetAnalysisFunctionList(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(function.Function(self, core.BNNewFunctionReference(funcs[i])))
+ result.append(binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i])))
core.BNFreeFunctionList(funcs, count.value)
return result
@@ -939,7 +915,7 @@ class BinaryView(object):
func = core.BNGetAnalysisEntryPoint(self.handle)
if func is None:
return None
- return function.Function(self, func)
+ return binaryninja.function.Function(self, func)
@property
def symbols(self):
@@ -1086,7 +1062,7 @@ class BinaryView(object):
def global_pointer_value(self):
"""Discovered value of the global pointer register, if the binary uses one (read-only)"""
result = core.BNGetGlobalPointerValue(self.handle)
- return function.RegisterValue(self.arch, result.value, confidence = result.confidence)
+ return binaryninja.function.RegisterValue(self.arch, result.value, confidence = result.confidence)
@property
def parameters_for_analysis(self):
@@ -2192,7 +2168,7 @@ class BinaryView(object):
func = core.BNGetAnalysisFunction(self.handle, plat.handle, addr)
if func is None:
return None
- return function.Function(self, func)
+ return binaryninja.function.Function(self, func)
def get_functions_at(self, addr):
"""
@@ -2209,7 +2185,7 @@ class BinaryView(object):
funcs = core.BNGetAnalysisFunctionsForAddress(self.handle, addr, count)
result = []
for i in xrange(0, count.value):
- result.append(function.Function(self, core.BNNewFunctionReference(funcs[i])))
+ result.append(binaryninja.function.Function(self, core.BNNewFunctionReference(funcs[i])))
core.BNFreeFunctionList(funcs, count.value)
return result
@@ -2217,7 +2193,7 @@ class BinaryView(object):
func = core.BNGetRecentAnalysisFunctionForAddress(self.handle, addr)
if func is None:
return None
- return function.Function(self, func)
+ return binaryninja.function.Function(self, func)
def get_basic_blocks_at(self, addr):
"""
@@ -2279,15 +2255,15 @@ class BinaryView(object):
result = []
for i in xrange(0, count.value):
if refs[i].func:
- func = function.Function(self, core.BNNewFunctionReference(refs[i].func))
+ func = binaryninja.function.Function(self, core.BNNewFunctionReference(refs[i].func))
else:
func = None
if refs[i].arch:
- arch = architecture.CoreArchitecture._from_cache(refs[i].arch)
+ arch = binaryninja.architecture.CoreArchitecture._from_cache(refs[i].arch)
else:
arch = None
addr = refs[i].addr
- result.append(architecture.ReferenceSource(func, arch, addr))
+ result.append(binaryninja.architecture.ReferenceSource(func, arch, addr))
core.BNFreeCodeReferences(refs, count.value)
return result
@@ -3006,7 +2982,7 @@ class BinaryView(object):
func = None
block = None
if pos.function:
- func = function.Function(self, pos.function)
+ func = binaryninja.function.Function(self, pos.function)
if pos.block:
block = basicblock.BasicBlock(self, pos.block)
return lineardisassembly.LinearDisassemblyPosition(func, block, pos.address)
@@ -3032,7 +3008,7 @@ class BinaryView(object):
func = None
block = None
if lines[i].function:
- func = function.Function(self, core.BNNewFunctionReference(lines[i].function))
+ func = binaryninja.function.Function(self, core.BNNewFunctionReference(lines[i].function))
if lines[i].block:
block = basicblock.BasicBlock(self, core.BNNewBasicBlockReference(lines[i].block))
addr = lines[i].contents.addr
@@ -3046,14 +3022,14 @@ class BinaryView(object):
context = lines[i].contents.tokens[j].context
confidence = lines[i].contents.tokens[j].confidence
address = lines[i].contents.tokens[j].address
- tokens.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
- contents = function.DisassemblyTextLine(addr, tokens)
+ tokens.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ contents = binaryninja.function.DisassemblyTextLine(addr, tokens)
result.append(lineardisassembly.LinearDisassemblyLine(lines[i].type, func, block, lines[i].lineOffset, contents))
func = None
block = None
if pos_obj.function:
- func = function.Function(self, pos_obj.function)
+ func = binaryninja.function.Function(self, pos_obj.function)
if pos_obj.block:
block = basicblock.BasicBlock(self, pos_obj.block)
pos.function = func
diff --git a/python/callingconvention.py b/python/callingconvention.py
index ab8058fc..268d914f 100644
--- a/python/callingconvention.py
+++ b/python/callingconvention.py
@@ -22,7 +22,10 @@ import traceback
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
+from binaryninja import log
+from binaryninja.enums import VariableSourceType
class CallingConvention(object):
from binaryninja import types
@@ -42,11 +45,6 @@ class CallingConvention(object):
_registered_calling_conventions = []
def __init__(self, arch=None, name=None, handle=None, confidence=types.max_confidence):
- from binaryninja import architecture
- from binaryninja import log
- from binaryninja import function
- from binaryninja import binaryview
- from binaryninja.enums import VariableSourceType
if handle is None:
if arch is None or name is None:
raise ValueError("Must specify either handle or architecture and name")
@@ -74,7 +72,7 @@ class CallingConvention(object):
self.__class__._registered_calling_conventions.append(self)
else:
self.handle = handle
- self.arch = architecture.CoreArchitecture._from_cache(core.BNGetCallingConventionArchitecture(self.handle))
+ self.arch = binaryninja.architecture.CoreArchitecture._from_cache(core.BNGetCallingConventionArchitecture(self.handle))
self.__dict__["name"] = core.BNGetCallingConventionName(self.handle)
self.__dict__["arg_regs_share_index"] = core.BNAreArgumentRegistersSharedIndex(self.handle)
self.__dict__["stack_reserved_for_arg_regs"] = core.BNIsStackReservedForArgumentRegisters(self.handle)
@@ -281,25 +279,25 @@ class CallingConvention(object):
def _get_incoming_reg_value(self, ctxt, reg, func, result):
try:
- func_obj = function.Function(binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
+ func_obj = binaryninja.function.Function(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
core.BNNewFunctionReference(func))
reg_name = self.arch.get_reg_name(reg)
api_obj = self.perform_get_incoming_reg_value(reg_name, func_obj)._to_api_object()
except:
log.log_error(traceback.format_exc())
- api_obj = function.RegisterValue()._to_api_object()
+ api_obj = binaryninja.function.RegisterValue()._to_api_object()
result[0].state = api_obj.state
result[0].value = api_obj.value
def _get_incoming_flag_value(self, ctxt, reg, func, result):
try:
- func_obj = function.Function(binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
+ func_obj = binaryninja.function.Function(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
core.BNNewFunctionReference(func))
reg_name = self.arch.get_reg_name(reg)
api_obj = self.perform_get_incoming_flag_value(reg_name, func_obj)._to_api_object()
except:
log.log_error(traceback.format_exc())
- api_obj = function.RegisterValue()._to_api_object()
+ api_obj = binaryninja.function.RegisterValue()._to_api_object()
result[0].state = api_obj.state
result[0].value = api_obj.value
@@ -308,9 +306,9 @@ class CallingConvention(object):
if func is None:
func_obj = None
else:
- func_obj = function.Function(binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
+ func_obj = binaryninja.function.Function(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
core.BNNewFunctionReference(func))
- in_var_obj = function.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage)
+ in_var_obj = binaryninja.function.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage)
out_var = self.perform_get_incoming_var_for_parameter_var(in_var_obj, func_obj)
result[0].type = out_var.source_type
result[0].index = out_var.index
@@ -326,9 +324,9 @@ class CallingConvention(object):
if func is None:
func_obj = None
else:
- func_obj = function.Function(binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
+ func_obj = binaryninja.function.Function(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
core.BNNewFunctionReference(func))
- in_var_obj = function.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage)
+ in_var_obj = binaryninja.function.Variable(func_obj, in_var[0].type, in_var[0].index, in_var[0].storage)
out_var = self.perform_get_parameter_var_for_incoming_var(in_var_obj, func_obj)
result[0].type = out_var.source_type
result[0].index = out_var.index
@@ -349,11 +347,11 @@ class CallingConvention(object):
reg_stack = self.arch.get_reg_stack_for_reg(reg)
if reg_stack is not None:
if reg == self.arch.reg_stacks[reg_stack].stack_top_reg:
- return function.RegisterValue.constant(0)
- return function.RegisterValue()
+ return binaryninja.function.RegisterValue.constant(0)
+ return binaryninja.function.RegisterValue()
def perform_get_incoming_flag_value(self, reg, func):
- return function.RegisterValue()
+ return binaryninja.function.RegisterValue()
def perform_get_incoming_var_for_parameter_var(self, in_var, func):
in_buf = core.BNVariable()
@@ -364,7 +362,7 @@ class CallingConvention(object):
name = None
if (func is not None) and (out_var.type == VariableSourceType.RegisterVariableSourceType):
name = func.arch.get_reg_name(out_var.storage)
- return function.Variable(func, out_var.type, out_var.index, out_var.storage, name)
+ return binaryninja.function.Variable(func, out_var.type, out_var.index, out_var.storage, name)
def perform_get_parameter_var_for_incoming_var(self, in_var, func):
in_buf = core.BNVariable()
@@ -372,7 +370,7 @@ class CallingConvention(object):
in_buf.index = in_var.index
in_buf.storage = in_var.storage
out_var = core.BNGetDefaultParameterVariableForIncomingVariable(self.handle, in_buf)
- return function.Variable(func, out_var.type, out_var.index, out_var.storage)
+ return binaryninja.function.Variable(func, out_var.type, out_var.index, out_var.storage)
def with_confidence(self, confidence):
return CallingConvention(self.arch, handle = core.BNNewCallingConventionReference(self.handle),
@@ -383,14 +381,14 @@ class CallingConvention(object):
func_handle = None
if func is not None:
func_handle = func.handle
- return function.RegisterValue(self.arch, core.BNGetIncomingRegisterValue(self.handle, reg_num, func_handle))
+ return binaryninja.function.RegisterValue(self.arch, core.BNGetIncomingRegisterValue(self.handle, reg_num, func_handle))
def get_incoming_flag_value(self, flag, func):
reg_num = self.arch.get_flag_index(flag)
func_handle = None
if func is not None:
func_handle = func.handle
- return function.RegisterValue(self.arch, core.BNGetIncomingFlagValue(self.handle, reg_num, func_handle))
+ return binaryninja.function.RegisterValue(self.arch, core.BNGetIncomingFlagValue(self.handle, reg_num, func_handle))
def get_incoming_var_for_parameter_var(self, in_var, func):
in_buf = core.BNVariable()
@@ -405,7 +403,7 @@ class CallingConvention(object):
name = None
if (func is not None) and (out_var.type == VariableSourceType.RegisterVariableSourceType):
name = func.arch.get_reg_name(out_var.storage)
- return function.Variable(func, out_var.type, out_var.index, out_var.storage, name)
+ return binaryninja.function.Variable(func, out_var.type, out_var.index, out_var.storage, name)
def get_parameter_var_for_incoming_var(self, in_var, func):
in_buf = core.BNVariable()
@@ -417,4 +415,4 @@ class CallingConvention(object):
else:
func_obj = func.handle
out_var = core.BNGetParameterVariableForIncomingVariable(self.handle, in_buf, func_obj)
- return function.Variable(func, out_var.type, out_var.index, out_var.storage)
+ return binaryninja.function.Variable(func, out_var.type, out_var.index, out_var.storage)
diff --git a/python/fileaccessor.py b/python/fileaccessor.py
index 5a602b89..3c7c5e45 100644
--- a/python/fileaccessor.py
+++ b/python/fileaccessor.py
@@ -25,7 +25,7 @@ import ctypes
from binaryninja import _binaryninjacore as core
class FileAccessor(object):
- from binaryninja import log
+
def __init__(self):
self._cb = core.BNFileAccessor()
self._cb.context = 0
diff --git a/python/filemetadata.py b/python/filemetadata.py
index 695b95f3..ee69dce8 100644
--- a/python/filemetadata.py
+++ b/python/filemetadata.py
@@ -23,12 +23,12 @@ import traceback
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja import associateddatastore #required for _FileMetadataAssociatedDataStore
-
+from binaryninja import log
class NavigationHandler(object):
- from binaryninja import log
def _register(self, handle):
self._cb = core.BNNavigationHandler()
self._cb.context = 0
@@ -69,8 +69,7 @@ class FileMetadata(object):
``class FileMetadata`` represents the file being analyzed by Binary Ninja. It is responsible for opening,
closing, creating the database (.bndb) files, and is used to keep track of undoable actions.
"""
- from binaryninja import startup
- from binaryninja import binaryview
+
_associated_data = {}
def __init__(self, filename = None, handle = None):
@@ -83,7 +82,7 @@ class FileMetadata(object):
if handle is not None:
self.handle = core.handle_of_type(handle, core.BNFileMetadata)
else:
- startup._init_plugins()
+ binaryninja._init_plugins()
self.handle = core.BNCreateFileMetadata()
if filename is not None:
core.BNSetFilename(self.handle, str(filename))
@@ -168,7 +167,7 @@ class FileMetadata(object):
view = core.BNGetFileViewOfType(self.handle, "Raw")
if view is None:
return None
- return binaryview.BinaryView(file_metadata = self, handle = view)
+ return binaryninja.binaryview.BinaryView(file_metadata = self, handle = view)
@property
def saved(self):
@@ -323,7 +322,7 @@ class FileMetadata(object):
lambda ctxt, cur, total: progress_func(cur, total)))
if view is None:
return None
- return binaryview.BinaryView(file_metadata = self, handle = view)
+ return binaryninja.binaryview.BinaryView(file_metadata = self, handle = view)
def save_auto_snapshot(self, progress_func = None):
if progress_func is None:
@@ -342,7 +341,7 @@ class FileMetadata(object):
view = core.BNCreateBinaryViewOfType(view_type, self.raw.handle)
if view is None:
return None
- return binaryview.BinaryView(file_metadata = self, handle = view)
+ return binaryninja.binaryview.BinaryView(file_metadata = self, handle = view)
def __setattr__(self, name, value):
try:
diff --git a/python/function.py b/python/function.py
index 2ee9b20d..a0269e75 100644
--- a/python/function.py
+++ b/python/function.py
@@ -24,13 +24,16 @@ import traceback
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja.enums import (AnalysisSkipReason, FunctionGraphType, BranchType, SymbolType, InstructionTextTokenType,
HighlightStandardColor, HighlightColorStyle, RegisterValueType, ImplicitRegisterExtend,
DisassemblyOption, IntegerDisplayType, InstructionTextTokenContext, VariableSourceType,
FunctionAnalysisSkipOverride)
from binaryninja import associateddatastore #required in the main scope due to being an argument for _FunctionAssociatedDataStore
-
+from binaryninja import types
+from binaryninja import highlight
+from binaryninja import log
class LookupTableEntry(object):
def __init__(self, from_values, to_value):
@@ -42,8 +45,7 @@ class LookupTableEntry(object):
class RegisterValue(object):
- from binaryninja import types
- def __init__(self, arch = None, value = None, confidence = types.max_confidence):
+ def __init__(self, arch = None, value = None, confidence = binaryninja.types.max_confidence):
self.is_constant = False
if value is None:
self.type = RegisterValueType.UndeterminedValue
@@ -321,7 +323,6 @@ class IndirectBranchInfo(object):
class ParameterVariables(object):
- from binaryninja import types
def __init__(self, var_list, confidence = types.max_confidence):
self.vars = var_list
self.confidence = confidence
@@ -348,14 +349,6 @@ class _FunctionAssociatedDataStore(associateddatastore._AssociatedDataStore):
class Function(object):
- from binaryninja import callingconvention
- from binaryninja import mediumlevelil
- from binaryninja import lowlevelil
- from binaryninja import basicblock
- from binaryninja import types
- from binaryninja import highlight
- from binaryninja import platform
- from binaryninja import architecture
_associated_data = {}
def __init__(self, view, handle):
@@ -421,7 +414,7 @@ class Function(object):
arch = core.BNGetFunctionArchitecture(self.handle)
if arch is None:
return None
- self._arch = architecture.CoreArchitecture._from_cache(arch)
+ self._arch = binaryninja.architecture.CoreArchitecture._from_cache(arch)
return self._arch
@property
@@ -433,7 +426,7 @@ class Function(object):
plat = core.BNGetFunctionPlatform(self.handle)
if plat is None:
return None
- self._platform = platform.Platform(None, handle = plat)
+ self._platform = binaryninja.platform.Platform(None, handle = plat)
return self._platform
@property
@@ -487,7 +480,7 @@ class Function(object):
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
+ result.append(binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i])))
core.BNFreeBasicBlockList(blocks, count.value)
return result
@@ -505,17 +498,17 @@ class Function(object):
@property
def low_level_il(self):
"""returns LowLevelILFunction used to represent Function low level IL (read-only)"""
- return lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelIL(self.handle), self)
+ return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLowLevelIL(self.handle), self)
@property
def lifted_il(self):
"""returns LowLevelILFunction used to represent lifted IL (read-only)"""
- return lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedIL(self.handle), self)
+ return binaryninja.lowlevelil.LowLevelILFunction(self.arch, core.BNGetFunctionLiftedIL(self.handle), self)
@property
def medium_level_il(self):
"""Function medium level IL (read-only)"""
- return mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, core.BNGetFunctionMediumLevelIL(self.handle), self)
@property
def function_type(self):
@@ -559,7 +552,7 @@ class Function(object):
branches = core.BNGetIndirectBranches(self.handle, count)
result = []
for i in xrange(0, count.value):
- result.append(IndirectBranchInfo(architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined))
+ result.append(IndirectBranchInfo(binaryninja.architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, binaryninja.architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined))
core.BNFreeIndirectBranchList(branches)
return result
@@ -638,7 +631,7 @@ class Function(object):
result = core.BNGetFunctionCallingConvention(self.handle)
if not result.convention:
return None
- return callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence)
+ return binaryninja.callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence)
@calling_convention.setter
def calling_convention(self, value):
@@ -855,7 +848,7 @@ class Function(object):
blocks = core.BNGetFunctionBasicBlockList(self.handle, count)
try:
for i in xrange(0, count.value):
- yield basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))
+ yield binaryninja.basicblock.BasicBlock(self._view, core.BNNewBasicBlockReference(blocks[i]))
finally:
core.BNFreeBasicBlockList(blocks, count.value)
@@ -937,7 +930,7 @@ class Function(object):
:param int addr: virtual address of the instruction to query
:param str reg: string value of native register to query
:param Architecture arch: (optional) Architecture for the given function
- :rtype: function.RegisterValue
+ :rtype: binaryninja.function.RegisterValue
:Example:
>>> func.get_reg_value_at(0x400dbe, 'rdi')
@@ -957,7 +950,7 @@ class Function(object):
:param int addr: virtual address of the instruction to query
:param str reg: string value of native register to query
:param Architecture arch: (optional) Architecture for the given function
- :rtype: function.RegisterValue
+ :rtype: binaryninja.function.RegisterValue
:Example:
>>> func.get_reg_value_after(0x400dbe, 'rdi')
@@ -979,7 +972,7 @@ class Function(object):
:param int offset: stack offset base of stack
:param int size: size of memory to query
:param Architecture arch: (optional) Architecture for the given function
- :rtype: function.RegisterValue
+ :rtype: binaryninja.function.RegisterValue
.. note:: Stack base is zero on entry into the function unless the architecture places the return address on the
stack as in (x86/x86_64) where the stack base will start at address_size
@@ -1148,7 +1141,7 @@ class Function(object):
branches = core.BNGetIndirectBranchesAt(self.handle, arch.handle, addr, count)
result = []
for i in xrange(0, count.value):
- result.append(IndirectBranchInfo(architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined))
+ result.append(IndirectBranchInfo(binaryninja.architecture.CoreArchitecture._from_cache(branches[i].sourceArch), branches[i].sourceAddr, binaryninja.architecture.CoreArchitecture._from_cache(branches[i].destArch), branches[i].destAddr, branches[i].autoDefined))
core.BNFreeIndirectBranchList(branches)
return result
@@ -1337,7 +1330,7 @@ class Function(object):
block = core.BNGetFunctionBasicBlockAtAddress(self.handle, arch.handle, addr)
if not block:
return None
- return basicblock.BasicBlock(self._view, handle = block)
+ return binaryninja.basicblock.BasicBlock(self._view, handle = block)
def get_instr_highlight(self, addr, arch=None):
"""
@@ -1633,7 +1626,6 @@ class FunctionGraphEdge(object):
class FunctionGraphBlock(object):
def __init__(self, handle):
- from binaryninja import binaryview
self.handle = handle
self.graph = graph
@@ -1669,7 +1661,7 @@ class FunctionGraphBlock(object):
block = mediumlevelil.MediumLevelILBasicBlock(view, block,
mediumlevelil.MediumLevelILFunction(func.arch, core.BNGetBasicBlockMediumLevelILFunction(block), func))
else:
- block = basicblock.BasicBlock(view, block)
+ block = binaryninja.basicblock.BasicBlock(view, block)
return block
@property
@@ -1678,7 +1670,7 @@ class FunctionGraphBlock(object):
arch = core.BNGetFunctionGraphBlockArchitecture(self.handle)
if arch is None:
return None
- return architecture.CoreArchitecture._from_cache(arch)
+ return binaryninja.architecture.CoreArchitecture._from_cache(arch)
@property
def start(self):
@@ -1753,7 +1745,7 @@ class FunctionGraphBlock(object):
core.BNFreeBasicBlock(target)
target = None
else:
- target = basicblock.BasicBlock(binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
+ target = binaryninja.basicblock.BasicBlock(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)),
core.BNNewBasicBlockReference(target))
core.BNFreeFunction(func)
points = []
@@ -1841,8 +1833,6 @@ class DisassemblySettings(object):
class FunctionGraph(object):
- from binaryninja import log
- from binaryninja import types
def __init__(self, view, handle):
self.view = view
self.handle = handle
@@ -2144,7 +2134,6 @@ class InstructionTextToken(object):
========================== ============================================
"""
- from binaryninja import types
def __init__(self, token_type, text, value = 0, size = 0, operand = 0xffffffff,
context = InstructionTextTokenContext.NoTokenContext, address = 0, confidence = types.max_confidence):
self.type = InstructionTextTokenType(token_type)
diff --git a/python/functionrecognizer.py b/python/functionrecognizer.py
index 158a0700..e390a3c8 100644
--- a/python/functionrecognizer.py
+++ b/python/functionrecognizer.py
@@ -29,7 +29,7 @@ class FunctionRecognizer(object):
from binaryninja import filemetadata
from binaryninja import binaryview
from binaryninja import lowlevelil
- from binaryninja import log
+
_instance = None
def __init__(self):
@@ -54,7 +54,7 @@ class FunctionRecognizer(object):
try:
file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(data))
view = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(data))
- func = function.Function(view, handle = core.BNNewFunctionReference(func))
+ func = binaryninja.function.Function(view, handle = core.BNNewFunctionReference(func))
il = lowlevelil.LowLevelILFunction(func.arch, handle = core.BNNewLowLevelILFunctionReference(il))
return self.recognize_low_level_il(view, func, il)
except:
@@ -68,7 +68,7 @@ class FunctionRecognizer(object):
try:
file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(data))
view = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(data))
- func = function.Function(view, handle = core.BNNewFunctionReference(func))
+ func = binaryninja.function.Function(view, handle = core.BNNewFunctionReference(func))
il = mediumlevelil.MediumLevelILFunction(func.arch, handle = core.BNNewMediumLevelILFunctionReference(il))
return self.recognize_medium_level_il(view, func, il)
except:
diff --git a/python/interaction.py b/python/interaction.py
index 8507682c..da6f792a 100644
--- a/python/interaction.py
+++ b/python/interaction.py
@@ -239,7 +239,7 @@ class DirectoryNameField(object):
class InteractionHandler(object):
- from binaryninja import log
+
from binaryninja import binaryview
_interaction_handler = None
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index 3b12c118..9c1db4cc 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -22,6 +22,7 @@ import ctypes
import struct
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja.enums import LowLevelILOperation, LowLevelILFlagCondition, InstructionTextTokenType
from binaryninja import basicblock #required for LowLevelILBasicBlock
@@ -340,8 +341,6 @@ class LowLevelILInstruction(object):
}
def __init__(self, func, expr_index, instr_index=None):
- from binaryninja import function
- from binaryninja import mediumlevelil
instr = core.BNGetLowLevelILByIndex(func.handle, expr_index)
self.function = func
self.expr_index = expr_index
@@ -530,7 +529,7 @@ class LowLevelILInstruction(object):
context = tokens[i].context
confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeInstructionText(tokens, count.value)
return result
@@ -552,7 +551,7 @@ class LowLevelILInstruction(object):
expr = self.function.get_medium_level_il_expr_index(self.expr_index)
if expr is None:
return None
- return mediumlevelil.MediumLevelILInstruction(self.function.medium_level_il, expr)
+ return binaryninja.mediumlevelil.MediumLevelILInstruction(self.function.medium_level_il, expr)
@property
def mapped_medium_level_il(self):
@@ -560,20 +559,20 @@ class LowLevelILInstruction(object):
expr = self.function.get_mapped_medium_level_il_expr_index(self.expr_index)
if expr is None:
return None
- return mediumlevelil.MediumLevelILInstruction(self.function.mapped_medium_level_il, expr)
+ return binaryninja.mediumlevelil.MediumLevelILInstruction(self.function.mapped_medium_level_il, expr)
@property
def value(self):
"""Value of expression if constant or a known value (read-only)"""
value = core.BNGetLowLevelILExprValue(self.function.handle, self.expr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
value = core.BNGetLowLevelILPossibleExprValues(self.function.handle, self.expr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -603,74 +602,74 @@ class LowLevelILInstruction(object):
def get_reg_value(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetLowLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_reg_value_after(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetLowLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_reg_values(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetLowLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_reg_values_after(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetLowLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_flag_value(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetLowLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_flag_value_after(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetLowLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_flag_values(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetLowLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_flag_values_after(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetLowLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_stack_contents(self, offset, size):
value = core.BNGetLowLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_stack_contents_after(self, offset, size):
value = core.BNGetLowLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_stack_contents(self, offset, size):
value = core.BNGetLowLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_stack_contents_after(self, offset, size):
value = core.BNGetLowLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -694,7 +693,7 @@ class LowLevelILExpr(object):
class LowLevelILFunction(object):
"""
- ``class LowLevelILFunction`` contains the list of LowLevelILExpr objects that make up a function. LowLevelILExpr
+ ``class LowLevelILFunction`` contains the list of LowLevelILExpr objects that make up a binaryninja.function. LowLevelILExpr
objects can be added to the LowLevelILFunction by calling ``append`` and passing the result of the various class
methods which return LowLevelILExpr objects.
@@ -805,7 +804,7 @@ class LowLevelILFunction(object):
result = core.BNGetMediumLevelILForLowLevelIL(self.handle)
if not result:
return None
- return mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
@property
def mapped_medium_level_il(self):
@@ -815,7 +814,7 @@ class LowLevelILFunction(object):
result = core.BNGetMappedMediumLevelIL(self.handle)
if not result:
return None
- return mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
+ return binaryninja.mediumlevelil.MediumLevelILFunction(self.arch, result, self.source_function)
def __setattr__(self, name, value):
try:
@@ -2302,13 +2301,13 @@ class LowLevelILFunction(object):
def get_ssa_reg_value(self, reg_ssa):
reg = self.arch.get_reg_index(reg_ssa.reg)
value = core.BNGetLowLevelILSSARegisterValue(self.handle, reg, reg_ssa.version)
- result = function.RegisterValue(self.arch, value)
+ result = binaryninja.function.RegisterValue(self.arch, value)
return result
def get_ssa_flag_value(self, flag_ssa):
flag = self.arch.get_flag_index(flag_ssa.flag)
value = core.BNGetLowLevelILSSAFlagValue(self.handle, flag, flag_ssa.version)
- result = function.RegisterValue(self.arch, value)
+ result = binaryninja.function.RegisterValue(self.arch, value)
return result
def get_medium_level_il_instruction_index(self, instr):
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 9a21bb23..a62c5c04 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -238,14 +238,14 @@ class MediumLevelILInstruction(object):
elif operand_type == "intrinsic":
value = lowlevelil.ILIntrinsic(func.arch, instr.operands[i])
elif operand_type == "var":
- value = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ value = binaryninja.function.Variable.from_identifier(self.function.source_function, instr.operands[i])
elif operand_type == "var_ssa":
- var = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ var = binaryninja.function.Variable.from_identifier(self.function.source_function, instr.operands[i])
version = instr.operands[i + 1]
i += 1
value = SSAVariable(var, version)
elif operand_type == "var_ssa_dest_and_src":
- var = function.Variable.from_identifier(self.function.source_function, instr.operands[i])
+ var = binaryninja.function.Variable.from_identifier(self.function.source_function, instr.operands[i])
dest_version = instr.operands[i + 1]
src_version = instr.operands[i + 2]
i += 2
@@ -346,14 +346,14 @@ class MediumLevelILInstruction(object):
def value(self):
"""Value of expression if constant or a known value (read-only)"""
value = core.BNGetMediumLevelILExprValue(self.function.handle, self.expr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
@property
def possible_values(self):
"""Possible values of expression using path-sensitive static data flow analysis (read-only)"""
value = core.BNGetMediumLevelILPossibleExprValues(self.function.handle, self.expr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -451,7 +451,7 @@ class MediumLevelILInstruction(object):
return []
result = []
for operand in self.operands:
- if (isinstance(operand, function.Variable)) or (isinstance(operand, SSAVariable)):
+ if (isinstance(operand, binaryninja.function.Variable)) or (isinstance(operand, SSAVariable)):
result.append(operand)
elif isinstance(operand, MediumLevelILInstruction):
result += operand.vars_read
@@ -474,7 +474,7 @@ class MediumLevelILInstruction(object):
var_data.index = ssa_var.var.index
var_data.storage = ssa_var.var.storage
value = core.BNGetMediumLevelILPossibleSSAVarValues(self.function.handle, var_data, ssa_var.version, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -488,88 +488,88 @@ class MediumLevelILInstruction(object):
def get_var_for_reg(self, reg):
reg = self.function.arch.get_reg_index(reg)
result = core.BNGetMediumLevelILVariableForRegisterAtInstruction(self.function.handle, reg, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ return binaryninja.function.Variable(self.function.source_function, result.type, result.index, result.storage)
def get_var_for_flag(self, flag):
flag = self.function.arch.get_flag_index(flag)
result = core.BNGetMediumLevelILVariableForFlagAtInstruction(self.function.handle, flag, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ return binaryninja.function.Variable(self.function.source_function, result.type, result.index, result.storage)
def get_var_for_stack_location(self, offset):
result = core.BNGetMediumLevelILVariableForStackLocationAtInstruction(self.function.handle, offset, self.instr_index)
- return function.Variable(self.function.source_function, result.type, result.index, result.storage)
+ return binaryninja.function.Variable(self.function.source_function, result.type, result.index, result.storage)
def get_reg_value(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetMediumLevelILRegisterValueAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_reg_value_after(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetMediumLevelILRegisterValueAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_reg_values(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetMediumLevelILPossibleRegisterValuesAtInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_reg_values_after(self, reg):
reg = self.function.arch.get_reg_index(reg)
value = core.BNGetMediumLevelILPossibleRegisterValuesAfterInstruction(self.function.handle, reg, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_flag_value(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetMediumLevelILFlagValueAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_flag_value_after(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetMediumLevelILFlagValueAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_flag_values(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetMediumLevelILPossibleFlagValuesAtInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_flag_values_after(self, flag):
flag = self.function.arch.get_flag_index(flag)
value = core.BNGetMediumLevelILPossibleFlagValuesAfterInstruction(self.function.handle, flag, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_stack_contents(self, offset, size):
value = core.BNGetMediumLevelILStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_stack_contents_after(self, offset, size):
value = core.BNGetMediumLevelILStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.RegisterValue(self.function.arch, value)
+ result = binaryninja.function.RegisterValue(self.function.arch, value)
return result
def get_possible_stack_contents(self, offset, size):
value = core.BNGetMediumLevelILPossibleStackContentsAtInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
def get_possible_stack_contents_after(self, offset, size):
value = core.BNGetMediumLevelILPossibleStackContentsAfterInstruction(self.function.handle, offset, size, self.instr_index)
- result = function.PossibleValueSet(self.function.arch, value)
+ result = binaryninja.function.PossibleValueSet(self.function.arch, value)
core.BNFreePossibleValueSet(value)
return result
@@ -596,7 +596,7 @@ class MediumLevelILExpr(object):
class MediumLevelILFunction(object):
"""
- ``class MediumLevelILFunction`` contains the list of MediumLevelILExpr objects that make up a function. MediumLevelILExpr
+ ``class MediumLevelILFunction`` contains the list of MediumLevelILExpr objects that make up a binaryninja.function. MediumLevelILExpr
objects can be added to the MediumLevelILFunction by calling ``append`` and passing the result of the various class
methods which return MediumLevelILExpr objects.
"""
@@ -902,7 +902,7 @@ class MediumLevelILFunction(object):
var_data.index = ssa_var.var.index
var_data.storage = ssa_var.var.storage
value = core.BNGetMediumLevelILSSAVarValue(self.handle, var_data, ssa_var.version)
- result = function.RegisterValue(self.arch, value)
+ result = binaryninja.function.RegisterValue(self.arch, value)
return result
def get_low_level_il_instruction_index(self, instr):
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)
diff --git a/python/plugin.py b/python/plugin.py
index 5dad9fb6..4cf6fb77 100644
--- a/python/plugin.py
+++ b/python/plugin.py
@@ -23,6 +23,8 @@ import ctypes
import threading
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
+from binaryninja import log
from binaryninja import _binaryninjacore as core
from binaryninja.enums import PluginCommandType
@@ -40,10 +42,10 @@ class PluginCommandContext(object):
class _PluginCommandMetaClass(type):
- from binaryninja import startup
+
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
commands = core.BNGetAllPluginCommands(count)
result = []
@@ -53,7 +55,7 @@ class _PluginCommandMetaClass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
commands = core.BNGetAllPluginCommands(count)
try:
@@ -70,11 +72,11 @@ class _PluginCommandMetaClass(type):
class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
- from binaryninja import startup
+
from binaryninja import filemetadata
from binaryninja import binaryview
from binaryninja import function
- from binaryninja import log
+
_registered_commands = []
def __init__(self, cmd):
@@ -92,8 +94,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
@classmethod
def _default_action(cls, view, action):
try:
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj)
except:
log.log_error(traceback.format_exc())
@@ -101,8 +103,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
@classmethod
def _address_action(cls, view, addr, action):
try:
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj, addr)
except:
log.log_error(traceback.format_exc())
@@ -110,8 +112,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
@classmethod
def _range_action(cls, view, addr, length, action):
try:
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
action(view_obj, addr, length)
except:
log.log_error(traceback.format_exc())
@@ -119,9 +121,9 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
@classmethod
def _function_action(cls, view, func, action):
try:
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
- func_obj = function.Function(view_obj, core.BNNewFunctionReference(func))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ func_obj = binaryninja.function.Function(view_obj, core.BNNewFunctionReference(func))
action(view_obj, func_obj)
except:
log.log_error(traceback.format_exc())
@@ -175,8 +177,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
try:
if is_valid is None:
return True
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj)
except:
log.log_error(traceback.format_exc())
@@ -187,8 +189,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
try:
if is_valid is None:
return True
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj, addr)
except:
log.log_error(traceback.format_exc())
@@ -199,8 +201,8 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
try:
if is_valid is None:
return True
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
return is_valid(view_obj, addr, length)
except:
log.log_error(traceback.format_exc())
@@ -211,9 +213,9 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
try:
if is_valid is None:
return True
- file_metadata = filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
- view_obj = binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
- func_obj = function.Function(view_obj, core.BNNewFunctionReference(func))
+ file_metadata = binaryninja.filemetadata.FileMetadata(handle = core.BNGetFileForView(view))
+ view_obj = binaryninja.binaryview.BinaryView(file_metadata = file_metadata, handle = core.BNNewViewReference(view))
+ func_obj = binaryninja.function.Function(view_obj, core.BNNewFunctionReference(func))
return is_valid(view_obj, func_obj)
except:
log.log_error(traceback.format_exc())
@@ -288,7 +290,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
.. warning:: Calling ``register`` with the same function name will replace the existing function but will leak the memory of the original plugin.
"""
- startup._init_plugins()
+ binaryninja._init_plugins()
action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_action(view, action))
is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView))(lambda ctxt, view: cls._default_is_valid(view, is_valid))
cls._registered_commands.append((action_obj, is_valid_obj))
@@ -307,7 +309,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
.. warning:: Calling ``register_for_address`` with the same function name will replace the existing function but will leak the memory of the original plugin.
"""
- startup._init_plugins()
+ binaryninja._init_plugins()
action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_action(view, addr, action))
is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong)(lambda ctxt, view, addr: cls._address_is_valid(view, addr, is_valid))
cls._registered_commands.append((action_obj, is_valid_obj))
@@ -326,7 +328,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
.. warning:: Calling ``register_for_range`` with the same function name will replace the existing function but will leak the memory of the original plugin.
"""
- startup._init_plugins()
+ binaryninja._init_plugins()
action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_action(view, addr, length, action))
is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.c_ulonglong, ctypes.c_ulonglong)(lambda ctxt, view, addr, length: cls._range_is_valid(view, addr, length, is_valid))
cls._registered_commands.append((action_obj, is_valid_obj))
@@ -345,7 +347,7 @@ class PluginCommand(with_metaclass(_PluginCommandMetaClass, object)):
.. warning:: Calling ``register_for_function`` with the same function name will replace the existing function but will leak the memory of the original plugin.
"""
- startup._init_plugins()
+ binaryninja._init_plugins()
action_obj = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_action(view, func, action))
is_valid_obj = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.POINTER(core.BNBinaryView), ctypes.POINTER(core.BNFunction))(lambda ctxt, view, func: cls._function_is_valid(view, func, is_valid))
cls._registered_commands.append((action_obj, is_valid_obj))
@@ -537,7 +539,7 @@ class MainThreadAction(object):
class MainThreadActionHandler(object):
- from binaryninja import log
+
_main_thread = None
def __init__(self):
@@ -572,7 +574,7 @@ class _BackgroundTaskMetaclass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
tasks = core.BNGetRunningBackgroundTasks(count)
try:
diff --git a/python/pluginmanager.py b/python/pluginmanager.py
index 66f642c3..002db573 100644
--- a/python/pluginmanager.py
+++ b/python/pluginmanager.py
@@ -199,7 +199,7 @@ class RepositoryManager(object):
``RepositoryManager`` Keeps track of all the repositories and keeps the enabled_plugins.json file coherent with
the plugins that are installed/unstalled enabled/disabled
"""
- from binaryninja import startup
+
def __init__(self, handle=None):
raise Exception("RepositoryManager temporarily disabled!")
self.handle = core.BNGetRepositoryManager()
@@ -236,7 +236,7 @@ class RepositoryManager(object):
@property
def default_repository(self):
"""Gets the default Repository"""
- startup._init_plugins()
+ binaryninja._init_plugins()
return Repository(handle=core.BNRepositoryManagerGetDefaultRepository(self.handle))
def enable_plugin(self, plugin, install=True, repo=None):
diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py
index ac0ffd4c..0b15ee18 100644
--- a/python/scriptingprovider.py
+++ b/python/scriptingprovider.py
@@ -29,6 +29,7 @@ import sys
# Binary Ninja components -- additional imports belong in the appropriate class
from binaryninja import _binaryninjacore as core
from binaryninja.enums import ScriptingProviderExecuteResult, ScriptingProviderInputReadyState
+import binaryninja.log
#2-3 compatibility
from six import with_metaclass
@@ -58,7 +59,6 @@ class _ThreadActionContext(object):
class ScriptingOutputListener(object):
- from binaryninja import log
def _register(self, handle):
self._cb = core.BNScriptingOutputListener()
self._cb.context = 0
@@ -74,19 +74,19 @@ class ScriptingOutputListener(object):
try:
self.notify_output(text)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _error(self, ctxt, text):
try:
self.notify_error(text)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _input_ready_state_changed(self, ctxt, state):
try:
self.notify_input_ready_state_changed(state)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def notify_output(self, text):
pass
@@ -99,10 +99,6 @@ class ScriptingOutputListener(object):
class ScriptingInstance(object):
- from binaryninja import binaryview
- from binaryninja import basicblock
- from binaryninja import log
- from binaryninja import function
def __init__(self, provider, handle = None):
if handle is None:
self._cb = core.BNScriptingInstanceCallbacks()
@@ -126,34 +122,34 @@ class ScriptingInstance(object):
try:
self.perform_destroy_instance()
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _execute_script_input(self, ctxt, text):
try:
return self.perform_execute_script_input(text)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return ScriptingProviderExecuteResult.InvalidScriptInput
def _set_current_binary_view(self, ctxt, view):
try:
if view:
- view = binaryview.BinaryView(handle = core.BNNewViewReference(view))
+ view = binaryninja.binaryview.BinaryView(handle = core.BNNewViewReference(view))
else:
view = None
self.perform_set_current_binary_view(view)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _set_current_function(self, ctxt, func):
try:
if func:
- func = function.Function(binaryview.BinaryView(handle = core.BNGetFunctionData(func)), core.BNNewFunctionReference(func))
+ func = binaryninja.function.Function(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)), core.BNNewFunctionReference(func))
else:
func = None
self.perform_set_current_function(func)
except:
- log.log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _set_current_basic_block(self, ctxt, block):
try:
@@ -162,25 +158,25 @@ class ScriptingInstance(object):
if func is None:
block = None
else:
- block = basicblock.BasicBlock(binaryview.BinaryView(handle = core.BNGetFunctionData(func)), core.BNNewBasicBlockReference(block))
+ block = binaryninja.basicblock.BasicBlock(binaryninja.binaryview.BinaryView(handle = core.BNGetFunctionData(func)), core.BNNewBasicBlockReference(block))
core.BNFreeFunction(func)
else:
block = None
self.perform_set_current_basic_block(block)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _set_current_address(self, ctxt, addr):
try:
self.perform_set_current_address(addr)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
def _set_current_selection(self, ctxt, begin, end):
try:
self.perform_set_current_selection(begin, end)
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
@abc.abstractmethod
def perform_destroy_instance(self):
@@ -259,11 +255,11 @@ class ScriptingInstance(object):
class _ScriptingProviderMetaclass(type):
- from binaryninja import startup
+
@property
def list(self):
"""List all ScriptingProvider types (read-only)"""
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
types = core.BNGetScriptingProviderList(count)
result = []
@@ -273,7 +269,7 @@ class _ScriptingProviderMetaclass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
types = core.BNGetScriptingProviderList(count)
try:
@@ -283,7 +279,7 @@ class _ScriptingProviderMetaclass(type):
core.BNFreeScriptingProviderList(types)
def __getitem__(self, value):
- startup._init_plugins()
+ binaryninja._init_plugins()
provider = core.BNGetScriptingProviderByName(str(value))
if provider is None:
raise KeyError("'%s' is not a valid scripting provider" % str(value))
@@ -297,7 +293,6 @@ class _ScriptingProviderMetaclass(type):
class ScriptingProvider(with_metaclass(_ScriptingProviderMetaclass, object)):
- from binaryninja import log
name = None
instance_class = None
@@ -318,7 +313,7 @@ class ScriptingProvider(with_metaclass(_ScriptingProviderMetaclass, object)):
self._cb = core.BNScriptingProviderCallbacks()
self._cb.context = 0
self._cb.createInstance = self._cb.createInstance.__class__(self._create_instance)
- self.handle = core.BNRegisterScriptingProvider(self.__class__.name, self._cb)
+ self.handle = core.BNRegisterScriptingProvider(self.__class__.name.encode('utf8'), self._cb)
self.__class__._registered_providers.append(self)
def _create_instance(self, ctxt):
@@ -328,7 +323,7 @@ class ScriptingProvider(with_metaclass(_ScriptingProviderMetaclass, object)):
return None
return ctypes.cast(core.BNNewScriptingInstanceReference(result.handle), ctypes.c_void_p).value
except:
- log.log_error(traceback.format_exc())
+ binaryninja.log.log_error(traceback.format_exc())
return None
def create_instance(self):
@@ -339,7 +334,6 @@ class ScriptingProvider(with_metaclass(_ScriptingProviderMetaclass, object)):
class _PythonScriptingInstanceOutput(object):
- from binaryninja import log
def __init__(self, orig, is_error):
self.orig = orig
self.is_error = is_error
@@ -395,7 +389,7 @@ class _PythonScriptingInstanceOutput(object):
interpreter = PythonScriptingInstance._interpreter.value
if interpreter is None:
- if log.is_output_redirected_to_log():
+ if binaryninja.log.is_output_redirected_to_log():
self.buffer += data
while True:
i = self.buffer.find('\n')
@@ -405,9 +399,9 @@ class _PythonScriptingInstanceOutput(object):
self.buffer = self.buffer[i + 1:]
if self.is_error:
- log.log_error(line)
+ binaryninja.log.log_error(line)
else:
- log.log_info(line)
+ binaryninja.log.log_info(line)
else:
self.orig.write(data)
else:
diff --git a/python/startup.py b/python/startup.py
index 919a8fbe..04e7b980 100644
--- a/python/startup.py
+++ b/python/startup.py
@@ -18,18 +18,18 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
-from binaryninja import _binaryninjacore as core
+#from binaryninja import _binaryninjacore as core
-_plugin_init = False
+#_plugin_init = False
-def _init_plugins():
- global _plugin_init
- if not _plugin_init:
- _plugin_init = True
- core.BNInitCorePlugins()
- core.BNInitUserPlugins()
- core.BNInitRepoPlugins()
- if not core.BNIsLicenseValidated():
- raise RuntimeError("License is not valid. Please supply a valid license.")
+# def _init_plugins():
+# global _plugin_init
+# if not _plugin_init:
+# _plugin_init = True
+# core.BNInitCorePlugins()
+# core.BNInitUserPlugins()
+# core.BNInitRepoPlugins()
+# if not core.BNIsLicenseValidated():
+# raise RuntimeError("License is not valid. Please supply a valid license.")
diff --git a/python/transform.py b/python/transform.py
index f04bfdca..fd68a987 100644
--- a/python/transform.py
+++ b/python/transform.py
@@ -23,6 +23,9 @@ import ctypes
import abc
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
+from binaryninja import log
+from binaryninja import databuffer
from binaryninja import _binaryninjacore as core
from binaryninja.enums import TransformType
@@ -31,10 +34,10 @@ from six import with_metaclass
class _TransformMetaClass(type):
- from binaryninja import startup
+
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
xforms = core.BNGetTransformTypeList(count)
result = []
@@ -44,7 +47,7 @@ class _TransformMetaClass(type):
return result
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
xforms = core.BNGetTransformTypeList(count)
try:
@@ -60,14 +63,14 @@ class _TransformMetaClass(type):
raise AttributeError("attribute '%s' is read only" % name)
def __getitem__(cls, name):
- startup._init_plugins()
+ binaryninja._init_plugins()
xform = core.BNGetTransformByName(name)
if xform is None:
raise KeyError("'%s' is not a valid transform" % str(name))
return Transform(xform)
def register(cls):
- startup._init_plugins()
+ binaryninja._init_plugins()
if cls.name is None:
raise ValueError("transform 'name' is not defined")
if cls.long_name is None:
@@ -92,7 +95,7 @@ class TransformParameter(object):
class Transform(with_metaclass(_TransformMetaClass, object)):
- from binaryninja import log
+
from binaryninja import databuffer
transform_type = None
name = None
diff --git a/python/types.py b/python/types.py
index cbe5a7bc..adb9e03a 100644
--- a/python/types.py
+++ b/python/types.py
@@ -24,6 +24,7 @@ max_confidence = 255
import ctypes
# Binary Ninja components -- additional imports belong in the appropriate class
+import binaryninja
from binaryninja import _binaryninjacore as core
from binaryninja.enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType, StructureType, ReferenceType, VariableSourceType
@@ -212,8 +213,6 @@ class FunctionParameter(object):
class Type(object):
def __init__(self, handle, platform = None, confidence = max_confidence):
- from binaryninja import callingconvention
- from binaryninja import function
self.handle = handle
self.confidence = confidence
self.platform = platform
@@ -293,7 +292,7 @@ class Type(object):
result = core.BNGetTypeCallingConvention(self.handle)
if not result.convention:
return None
- return callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence)
+ return binaryninja.callingconvention.CallingConvention(None, handle = result.convention, confidence = result.confidence)
@property
def parameters(self):
@@ -311,7 +310,7 @@ class Type(object):
name = self.platform.arch.get_reg_name(params[i].location.storage)
elif params[i].location.type == VariableSourceType.StackVariableSourceType:
name = "arg_%x" % params[i].location.storage
- param_location = function.Variable(None, params[i].location.type, params[i].location.index,
+ param_location = binaryninja.function.Variable(None, params[i].location.type, params[i].location.index,
params[i].location.storage, name, param_type)
result.append(FunctionParameter(param_type, params[i].name, param_location))
core.BNFreeTypeParameterList(params, count.value)
@@ -413,7 +412,7 @@ class Type(object):
context = tokens[i].context
confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
@@ -433,7 +432,7 @@ class Type(object):
context = tokens[i].context
confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
@@ -453,7 +452,7 @@ class Type(object):
context = tokens[i].context
confidence = tokens[i].confidence
address = tokens[i].address
- result.append(function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
+ result.append(binaryninja.function.InstructionTextToken(token_type, text, value, size, operand, context, address, confidence))
core.BNFreeTokenList(tokens, count.value)
return result
diff --git a/python/undoaction.py b/python/undoaction.py
index 9771df38..732d559a 100644
--- a/python/undoaction.py
+++ b/python/undoaction.py
@@ -28,8 +28,8 @@ from binaryninja.enums import ActionType
class UndoAction(object):
- from binaryninja import startup
- from binaryninja import log
+
+
name = None
action_type = None
_registered = False
@@ -52,7 +52,7 @@ class UndoAction(object):
@classmethod
def register(cls):
- startup._init_plugins()
+ binaryninja._init_plugins()
if cls.name is None:
raise ValueError("undo action 'name' not defined")
if cls.action_type is None:
diff --git a/python/update.py b/python/update.py
index 1fda149b..560f05ec 100644
--- a/python/update.py
+++ b/python/update.py
@@ -31,10 +31,10 @@ from six import with_metaclass
class _UpdateChannelMetaClass(type):
- from binaryninja import startup
+
@property
def list(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
errors = ctypes.c_char_p()
channels = core.BNGetUpdateChannels(count, errors)
@@ -57,7 +57,7 @@ class _UpdateChannelMetaClass(type):
return core.BNSetActiveUpdateChannel(value)
def __iter__(self):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
errors = ctypes.c_char_p()
channels = core.BNGetUpdateChannels(count, errors)
@@ -78,7 +78,7 @@ class _UpdateChannelMetaClass(type):
raise AttributeError("attribute '%s' is read only" % name)
def __getitem__(cls, name):
- startup._init_plugins()
+ binaryninja._init_plugins()
count = ctypes.c_ulonglong()
errors = ctypes.c_char_p()
channels = core.BNGetUpdateChannels(count, errors)
@@ -98,7 +98,7 @@ class _UpdateChannelMetaClass(type):
class UpdateProgressCallback(object):
- from binaryninja import log
+
def __init__(self, func):
self.cb = ctypes.CFUNCTYPE(ctypes.c_bool, ctypes.c_void_p, ctypes.c_ulonglong, ctypes.c_ulonglong)(self.callback)
self.func = func