From 4d020014c07555b1cee687a301b450c455d8a0b8 Mon Sep 17 00:00:00 2001 From: Tim Blume Date: Sat, 9 Jan 2021 11:17:50 +0100 Subject: [PATCH] plugin wip --- CMakeLists.txt | 2 ++ include/proxyinterface.h | 12 ++++++------ pluginhandler.cpp | 28 +++++++++++++++++++++++++++ pluginhandler.h | 18 +++++++++++++++++ plugins/mitmproxy/mitmproxy_network.h | 9 +++++++++ proxyhandler.cpp | 15 ++++++++------ proxyhandler.h | 11 ++++++++--- 7 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 pluginhandler.cpp create mode 100644 pluginhandler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d6057c..0ad12c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ add_executable(bigsnitch networkthread.cpp session.cpp httpflow.cpp + pluginhandler.cpp proxyhandler.cpp historymodel.cpp editandresend.cpp @@ -41,6 +42,7 @@ add_executable(bigsnitch session.h includes.h proxyhandler.h + pluginhandler.h historymodel.h editandresend.h settings.h diff --git a/include/proxyinterface.h b/include/proxyinterface.h index c8f4cfd..2858f42 100644 --- a/include/proxyinterface.h +++ b/include/proxyinterface.h @@ -1,6 +1,6 @@ #pragma once -#include "include/api.h" +#include "api.h" #include namespace http { @@ -11,8 +11,8 @@ namespace http { /*! Interface for implementing proxies */ -class ProxyInterface { - +class ProxyInterface : public QObject { + Q_OBJECT public: virtual ~ProxyInterface() = default; //! called in a custom thread, may block. @@ -23,9 +23,9 @@ public: virtual void disconnect() = 0; // options/settings signals: - void finished(); - void error(QString err); - void message(http::Flow flow); + virtual void finished(); + virtual void error(QString err); + virtual void message(http::Flow flow); }; } diff --git a/pluginhandler.cpp b/pluginhandler.cpp new file mode 100644 index 0000000..4b2cc34 --- /dev/null +++ b/pluginhandler.cpp @@ -0,0 +1,28 @@ +#include "pluginhandler.h" + +/* + const auto staticInstances = QPluginLoader::staticInstances(); + for (QObject *plugin : staticInstances) + populateMenus(plugin); +*/ + + +bool PluginHandler::load(QString path) +{ + QPluginLoader loader(path); + QObject *plugin = loader.instance(); + if (plugin) { + proxyhandler.loadPlugin(plugin); + loaded_plugins += path; + return true; + } + return false; +} + +void PluginHandler::loadPlugins(QDir path) +{ + const auto entryList = path.entryList(QDir::Files); + for (const QString &fileName : entryList) { + load(path.absoluteFilePath(fileName)); + } +} diff --git a/pluginhandler.h b/pluginhandler.h new file mode 100644 index 0000000..a87eef8 --- /dev/null +++ b/pluginhandler.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +class PluginHandler +{ +private: + QStringList loaded_plugins; + ProxyHandler proxyhandler; +public: + bool load(QString path); + void loadPlugins(QDir path); +}; diff --git a/plugins/mitmproxy/mitmproxy_network.h b/plugins/mitmproxy/mitmproxy_network.h index 7624b4d..2834a46 100644 --- a/plugins/mitmproxy/mitmproxy_network.h +++ b/plugins/mitmproxy/mitmproxy_network.h @@ -1,6 +1,15 @@ #pragma once #include "api.h" +#include "proxyinterface.h" #include +class mitmproxyPlugin : public QObject, + public http::ProxyInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "bigsnitch.api.HTTPProxyInterface/100" FILE "mitmproxy.json") + Q_INTERFACES(http::ProxyInterface) +public: +}; diff --git a/proxyhandler.cpp b/proxyhandler.cpp index 149a2e3..ed37291 100644 --- a/proxyhandler.cpp +++ b/proxyhandler.cpp @@ -1,11 +1,14 @@ #include "proxyhandler.h" -bool PluginHandler::load(std::string path) -{ - -} - -void PluginHandler::loadPlugins(std::string path) +bool http::ProxyHandler::loadPlugin(QObject *proxy) { + auto inst = qobject_cast(proxy); + if(!inst) { + return false; + } + + + + return true; } diff --git a/proxyhandler.h b/proxyhandler.h index f5cc65a..09007f7 100644 --- a/proxyhandler.h +++ b/proxyhandler.h @@ -2,10 +2,15 @@ #include #include +#include -class PluginHandler +namespace http { + +class ProxyHandler { +private: public: - bool load(std::string path); - void loadPlugins(std::string path); + bool loadPlugin(QObject *proxy); }; + +}