summaryrefslogtreecommitdiff
path: root/python/__init__.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2021-02-09 20:39:28 -0500
committerPeter LaFosse <peter@vector35.com>2021-03-02 07:50:56 -0500
commit1eafe9eeb83962071ecffaebb0bc98dc79f2f5c6 (patch)
treef242857ceffdf76576bb87745cf096ffefc71b93 /python/__init__.py
parentc07fe0fea819f681621ff60e336f079494f6bfef (diff)
Add ability to install python dependencies
Refactor plugin repo loading into scripting provider. Find python binary for given python library
Diffstat (limited to 'python/__init__.py')
-rw-r--r--python/__init__.py49
1 files changed, 0 insertions, 49 deletions
diff --git a/python/__init__.py b/python/__init__.py
index 8855a395..4c4c412c 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -26,7 +26,6 @@ import ctypes
from time import gmtime
import os
-
from binaryninja.compatibility import *
@@ -90,54 +89,6 @@ def get_install_directory():
return core.BNGetInstallDirectory()
-_plugin_api_name = "python{}".format(sys.version_info.major)
-
-
-class PluginManagerLoadPluginCallback(object):
- """Callback for BNLoadPluginForApi("python{version}", ...), dynamically loads python plugins."""
- def __init__(self):
- self.cb = ctypes.CFUNCTYPE(
- ctypes.c_bool,
- ctypes.c_char_p,
- ctypes.c_char_p,
- ctypes.c_bool,
- ctypes.c_void_p)(self._load_plugin)
-
- def _load_plugin(self, repo_path, plugin_path, force, ctx):
- try:
- repo_path = repo_path.decode("utf-8")
- plugin_path = plugin_path.decode("utf-8")
- repo = RepositoryManager()[repo_path]
- plugin = repo[plugin_path]
-
- if not force and _plugin_api_name not in plugin.api:
- raise ValueError("Plugin API name is not " + _plugin_api_name)
-
- if not force and core.core_platform not in plugin.install_platforms:
- raise ValueError("Current platform {} isn't in list of valid platforms for this plugin {}".format(
- core.core_platform, plugin.install_platforms))
- if not plugin.installed:
- plugin.installed = True
-
- plugin_full_path = os.path.join(repo.full_path, plugin.path)
- if repo.full_path not in sys.path:
- sys.path.append(repo.full_path)
- if plugin_full_path not in sys.path:
- sys.path.append(plugin_full_path)
-
- __import__(plugin_path)
- return True
- except KeyError:
- log_error("Failed to find python plugin: {}/{}".format(repo_path, plugin_path))
- except ImportError as ie:
- log_error("Failed to import python plugin: {}/{}: {}".format(repo_path, plugin_path, ie))
- return False
-
-
-load_plugin = PluginManagerLoadPluginCallback()
-core.BNRegisterForPluginLoading(_plugin_api_name, load_plugin.cb, 0)
-
-
class _DestructionCallbackHandler(object):
def __init__(self):
self._cb = core.BNObjectDestructionCallbacks()