From 9b99fc5856d5fe88bb1d2aad4d2ee7cd86b5be57 Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Thu, 12 Mar 2015 13:54:15 +0100 Subject: [PATCH] Move the interpreters to the core InformationManager --- src/core/InformationManager.cxx | 29 +++++++++++++++++++++++++++++ src/core/InformationManager.hxx | 12 ++++++++++++ src/gui/Mainwindow.cxx | 10 +++------- src/gui/Mainwindow.hxx | 2 -- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/core/InformationManager.cxx b/src/core/InformationManager.cxx index 61daa3d..5a70dee 100644 --- a/src/core/InformationManager.cxx +++ b/src/core/InformationManager.cxx @@ -1,4 +1,5 @@ #include "InformationManager.hxx" +#include "bindings/Interpreter.hxx" #include "disassembler/llvm/LLVMDisassembler.hxx" #include "core/Function.hxx" #include "core/BasicBlock.hxx" @@ -16,6 +17,12 @@ InformationManager::InformationManager() : logger(log4cxx::Logger::getLogger("core.InformationManager")) { current_information_manager = this; + + QPluginLoader* loader = new QPluginLoader("libguilePlugin", NULL); + if (!loader->load()) + LOG4CXX_ERROR(logger, "Loading plugin failed: " << loader->errorString().toStdString()); + interpreters["GUILE"] = qobject_cast(loader->instance()); + plugins.push_back(loader); } InformationManager::~InformationManager() { @@ -24,6 +31,9 @@ InformationManager::~InformationManager() { for (auto f : functions) delete f.second; + + for (auto i : plugins) + delete i; } void InformationManager::reset(const std::string& filename) { @@ -154,6 +164,25 @@ std::map::const_iterator InformationManager::endBasicBloc } +/* ********************************* + * Accessors for the Interpreter map + */ + +Interpreter* InformationManager::getInterpreter(const std::string& name) { + auto it = interpreters.find(name); + if (it != interpreters.end()) + return it->second; + else + return NULL; +} + +std::map::const_iterator InformationManager::beginInterpreters() { + return interpreters.begin(); +} +std::map::const_iterator InformationManager::endInterpreters() { + return interpreters.end(); +} + /* ******************************** * Factory methods for data classes diff --git a/src/core/InformationManager.hxx b/src/core/InformationManager.hxx index 555070a..610ece5 100644 --- a/src/core/InformationManager.hxx +++ b/src/core/InformationManager.hxx @@ -6,9 +6,12 @@ #include #include #include +#include #include "disassembler/Disassembler.hxx" +class Interpreter; + class Function; class BasicBlock; class Comment; @@ -17,6 +20,7 @@ class RenameFunctionEvent; class QString; class QTemporaryFile; +class QPluginLoader; class InformationManager { public: @@ -65,6 +69,12 @@ public: std::map::const_iterator endBasicBlocks(); + Interpreter* getInterpreter(const std::string& name); + bool hasInterpreters() const {return interpreters.size() != 0;} + std::map::const_iterator beginInterpreters(); + std::map::const_iterator endInterpreters(); + + /* Protocoll: * * Users may allocate new Data containers with the new*() @@ -101,10 +111,12 @@ private: boost::signals2::signal new_dyn_symbol_signal; boost::signals2::signal rename_function_signal; std::unique_ptr disassembler; + std::map interpreters; std::map functions; std::map blocks; std::string filename; std::unique_ptr tmpfile; + std::vector plugins; log4cxx::LoggerPtr logger; }; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index f28f1e2..8593110 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -43,15 +43,11 @@ Mainwindow::Mainwindow(InformationManager* mgr) QMenu* interpretermenu = menuBar()->addMenu(tr("&Interpreter")); - QPluginLoader* loader = new QPluginLoader("libguilePlugin", this); - if (!loader->load()) - LOG4CXX_ERROR(logger, "Loading plugin failed: " << loader->errorString().toStdString()); - interpreter["GUILE"] = qobject_cast(loader->instance()); fdock = new FridaDock(tr("Frida Dock"), this); fdock->addTab(new LogDock(fdock), "Log"); - fdock->addTab(new ScriptingDock(interpreter["GUILE"], fdock), "guile"); + fdock->addTab(new ScriptingDock(manager->getInterpreter("GUILE"), fdock), "guile"); fdock->setAllowedAreas(Qt::BottomDockWidgetArea); addDockWidget(Qt::BottomDockWidgetArea, fdock); QAction* guileLoad = new QAction(tr("&GUILE"), this); @@ -60,10 +56,10 @@ Mainwindow::Mainwindow(InformationManager* mgr) [&]() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Script"), "", tr("Binaries") + " (*." + - interpreter["GUILE"]->fileExtension().c_str() + ")"); + manager->getInterpreter("GUILE")->fileExtension().c_str() + ")"); std::stringstream a, b; std::string c; - interpreter["GUILE"]->loadFile(fileName.toStdString(), a, b, c); + manager->getInterpreter("GUILE")->loadFile(fileName.toStdString(), a, b, c); }); listWidget = new QTreeWidget(); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index cfdbaaa..a891795 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -20,7 +20,6 @@ class InformationManager; class FunctionWidget; class BasicBlockWidget; class FridaDock; -class Interpreter; class Mainwindow : public QMainWindow { Q_OBJECT @@ -55,7 +54,6 @@ private: std::map objects_list; std::map objects_list_by_address; std::vector group_list; - std::map interpreter; InformationManager* manager; log4cxx::LoggerPtr logger; -- 2.39.2