From 1a4a0f56dc17e68e5743fa3a550b46992ec461e1 Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 15 Jul 2021 03:39:25 -0400 Subject: support for repository plugins loaded from a subdirectory --- binaryninjaapi.h | 1 + binaryninjacore.h | 1 + pluginmanager.cpp | 5 +++++ python/pluginmanager.py | 5 +++++ python/scriptingprovider.py | 5 ++++- 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index f415f82c..1d731218 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5391,6 +5391,7 @@ __attribute__ ((format (printf, 1, 2))) std::vector GetApis() const; std::vector GetInstallPlatforms() const; std::string GetPath() const; + std::string GetSubdir() const; std::string GetDependencies() const; std::string GetPluginDirectory() const; std::string GetAuthor() const; diff --git a/binaryninjacore.h b/binaryninjacore.h index 1037114d..d4e85e47 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5092,6 +5092,7 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNRepoPlugin* BNNewPluginReference(BNRepoPlugin* r); BINARYNINJACOREAPI void BNFreePlugin(BNRepoPlugin* plugin); BINARYNINJACOREAPI const char* BNPluginGetPath(BNRepoPlugin* p); + BINARYNINJACOREAPI const char* BNPluginGetSubdir(BNRepoPlugin* p); BINARYNINJACOREAPI const char* BNPluginGetDependencies(BNRepoPlugin* p); BINARYNINJACOREAPI bool BNPluginIsInstalled(BNRepoPlugin* p); BINARYNINJACOREAPI bool BNPluginIsEnabled(BNRepoPlugin* p); diff --git a/pluginmanager.cpp b/pluginmanager.cpp index 1500c78e..d3108907 100644 --- a/pluginmanager.cpp +++ b/pluginmanager.cpp @@ -20,6 +20,11 @@ string RepoPlugin::GetPath() const RETURN_STRING(BNPluginGetPath(m_object)); } +string RepoPlugin::GetSubdir() const +{ + RETURN_STRING(BNPluginGetSubdir(m_object)); +} + string RepoPlugin::GetDependencies() const { RETURN_STRING(BNPluginGetDependencies(m_object)); diff --git a/python/pluginmanager.py b/python/pluginmanager.py index 15b98b55..31e63620 100644 --- a/python/pluginmanager.py +++ b/python/pluginmanager.py @@ -49,6 +49,11 @@ class RepoPlugin(object): """Relative path from the base of the repository to the actual plugin""" return core.BNPluginGetPath(self.handle) + @property + def subdir(self): + """Optional sub-directory the plugin code lives in as a relative path from the plugin root""" + return core.BNPluginGetSubdir(self.handle) + @property def dependencies(self): """Dependencies required for installing this plugin""" diff --git a/python/scriptingprovider.py b/python/scriptingprovider.py index 51972ae9..473cd36f 100644 --- a/python/scriptingprovider.py +++ b/python/scriptingprovider.py @@ -831,7 +831,10 @@ class PythonScriptingProvider(ScriptingProvider): if plugin_full_path not in sys.path: sys.path.append(plugin_full_path) - __import__(module) + if plugin.subdir: + __import__(module + "." + plugin.subdir.replace("/", ".")) + else: + __import__(module) return True except KeyError: log.log_error(f"Failed to find python plugin: {repo_path}/{module}") -- cgit v1.3.1