Source code for binaryninja

# Copyright (c) 2015-2019 Vector 35 Inc## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to# deal in the Software without restriction, including without limitation the# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or# sell copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS# IN THE SOFTWARE.from__future__importabsolute_importimportatexitimportsysimportctypesfromtimeimportgmtime# 2-3 compatibilitytry:importbuiltins# __builtins__ for python2exceptImportError:pass

[docs]defwith_metaclass(meta,*bases):"""Create a base class with a metaclass."""classmetaclass(type):def__new__(cls,name,this_bases,d):returnmeta(name,bases,d)@classmethoddef__prepare__(cls,name,this_bases):returnmeta.__prepare__(name,bases)returntype.__new__(metaclass,'temporary_class',(),{})

[docs]defget_install_directory():""" ``get_install_directory`` returns a string pointing to the installed binary currently running ..warning:: ONLY for use within the Binary Ninja UI, behavior is undefined and unreliable if run headlessly """returncore.BNGetInstallDirectory()

load_plugin=PluginManagerLoadPluginCallback()core.BNRegisterForPluginLoading(_plugin_api_name,load_plugin.cb,0)class_DestructionCallbackHandler(object):def__init__(self):self._cb=core.BNObjectDestructionCallbacks()self._cb.context=0self._cb.destructBinaryView=self._cb.destructBinaryView.__class__(self.destruct_binary_view)self._cb.destructFileMetadata=self._cb.destructFileMetadata.__class__(self.destruct_file_metadata)self._cb.destructFunction=self._cb.destructFunction.__class__(self.destruct_function)core.BNRegisterObjectDestructionCallbacks(self._cb)defdestruct_binary_view(self,ctxt,view):BinaryView._unregister(view)defdestruct_file_metadata(self,ctxt,f):FileMetadata._unregister(f)defdestruct_function(self,ctxt,func):Function._unregister(func)_plugin_init=Falsedef_init_plugins():global_plugin_initifnot_plugin_init:_plugin_init=Truecore.BNInitCorePlugins()core.BNInitUserPlugins()core.BNInitRepoPlugins()ifnotcore.BNIsLicenseValidated():raiseRuntimeError("License is not valid. Please supply a valid license.")_destruct_callbacks=_DestructionCallbackHandler()