]> git.siccegge.de Git - frida/frida.git/commitdiff
Move the interpreters to the core InformationManager
authorChristoph Egger <Christoph.Egger@cs.fau.de>
Thu, 12 Mar 2015 12:54:15 +0000 (13:54 +0100)
committerChristoph Egger <Christoph.Egger@cs.fau.de>
Thu, 12 Mar 2015 12:54:15 +0000 (13:54 +0100)
src/core/InformationManager.cxx
src/core/InformationManager.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx

index 61daa3d269d094dc130ae80e82d51f3ac9871a89..5a70dee6a54041951a4461723a85f40714caf518 100644 (file)
@@ -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<Interpreter*>(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<uint64_t, BasicBlock*>::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<std::string, Interpreter*>::const_iterator InformationManager::beginInterpreters() {
+       return interpreters.begin();
+}
+std::map<std::string, Interpreter*>::const_iterator InformationManager::endInterpreters() {
+       return interpreters.end();
+}
+
 
 /* ********************************
  * Factory methods for data classes
index 555070abefd624cf6e19a5b84218a58ab3b73097..610ece50da253f51820e9af3679ed934008808cb 100644 (file)
@@ -6,9 +6,12 @@
 #include <functional>
 #include <string>
 #include <map>
+#include <vector>
 
 #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<uint64_t, BasicBlock*>::const_iterator endBasicBlocks();
 
 
+       Interpreter* getInterpreter(const std::string& name);
+       bool hasInterpreters() const {return interpreters.size() != 0;}
+       std::map<std::string, Interpreter*>::const_iterator beginInterpreters();
+       std::map<std::string, Interpreter*>::const_iterator endInterpreters();
+
+
        /* Protocoll:
         *
         * Users may allocate new Data containers with the new*()
@@ -101,10 +111,12 @@ private:
        boost::signals2::signal<void (const std::string& name)> new_dyn_symbol_signal;
        boost::signals2::signal<void (RenameFunctionEvent*)> rename_function_signal;
        std::unique_ptr<Disassembler> disassembler;
+       std::map<std::string, Interpreter*> interpreters;
        std::map<uint64_t, Function*> functions;
        std::map<uint64_t, BasicBlock*> blocks;
        std::string filename;
        std::unique_ptr<QTemporaryFile> tmpfile;
+       std::vector<QPluginLoader*> plugins;
 
        log4cxx::LoggerPtr logger;
 };
index f28f1e25a23161630c985e52319ab13d74582660..859311032c79c45a49e1721d97ab32b1c67e61a6 100644 (file)
@@ -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<Interpreter*>(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();
index cfdbaaa152e21ccb124d261e477db4604c30c70c..a89179598a095c71e16b32d432b40f5bd9d5855d 100644 (file)
@@ -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<QTreeWidgetItem*, FunctionWidget*> objects_list;
        std::map<uint64_t, QTreeWidgetItem*> objects_list_by_address;
        std::vector<QTreeWidgetItem*> group_list;
-       std::map<std::string, Interpreter*> interpreter;
 
        InformationManager* manager;
        log4cxx::LoggerPtr logger;