summaryrefslogtreecommitdiff
path: root/python/__init__.py
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2019-05-14 21:34:57 -0700
committerPeter LaFosse <peter@vector35.com>2019-07-08 23:14:30 -0400
commitad37832dd4ffa112b10b523a151d3fa9b86b6c9d (patch)
tree364641f60f878150bb010c4b51f088e49c8ba058 /python/__init__.py
parent7e7f0b41548057093fb48f1d8985712b619e9438 (diff)
PluginManager refactor for supporting plugin installation ui
Expose additional PluginManager APIs and update documentation
Diffstat (limited to 'python/__init__.py')
-rw-r--r--python/__init__.py60
1 files changed, 19 insertions, 41 deletions
diff --git a/python/__init__.py b/python/__init__.py
index bdc6bdd7..f572bdef 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -24,7 +24,7 @@ import atexit
import sys
import ctypes
from time import gmtime
-
+import os
# 2-3 compatibility
PY2 = sys.version_info[0] == 2
@@ -92,37 +92,7 @@ def pyNativeStr(arg):
# Binary Ninja components
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",
-# "flowgraph",
-# ]
+
from binaryninja.enums import *
from binaryninja.databuffer import *
from binaryninja.filemetadata import *
@@ -179,34 +149,42 @@ def get_install_directory():
return core.BNGetInstallDirectory()
-_plugin_api_name = "python2"
+_plugin_api_name = "python{}".format(sys.version_info.major)
class PluginManagerLoadPluginCallback(object):
- """Callback for BNLoadPluginForApi("python2", ...), dynamically loads python plugins."""
+ """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, ctx):
+ 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 plugin.api != _plugin_api_name:
+ 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 {} ins'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)
- log_info("Successfully loaded plugin: {}/{}: ".format(repo_path, plugin_path))
+ __import__(plugin_path)
return True
except KeyError:
log_error("Failed to find python plugin: {}/{}".format(repo_path, plugin_path))
@@ -284,12 +262,12 @@ def core_version():
def core_build_id():
"""
- ``core_build_id`` returns a string containing the current build id
+ ``core_build_id`` returns a integer containing the current build id
:return: current build id
- :rtype: str, or None on failure
+ :rtype: int
"""
- core.BNGetBuildId()
+ return core.BNGetBuildId()
def core_serial():
"""