]> git.siccegge.de Git - frida/frida.git/commitdiff
PoC: Add menu item to load script
authorChristoph Egger <Christoph.Egger@fau.de>
Tue, 10 Mar 2015 16:45:50 +0000 (17:45 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Tue, 10 Mar 2015 16:45:50 +0000 (17:45 +0100)
src/bindings/Guile.cxx
src/bindings/Guile.hxx
src/bindings/Interpreter.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx

index 57d32bdd8009d02cd8fe2fad1762cf08bb5cfbbc..fcc108349b55fa1afda71ad142f9e8bf15e79a72 100644 (file)
@@ -54,3 +54,11 @@ int GuileInterpreter::evaluate(const std::string& command,
 
        return 0;
 }
+
+int GuileInterpreter::loadFile(const std::string& filename,
+                               std::ostream& stdout,
+                               std::ostream& stderr,
+                               std::string& result) {
+       return evaluate("(load \"" + filename + "\")",
+                       stdout, stderr, result);
+}
index 5de69080be4e464229e627e4b314f78ef19f9c6c..7c45a9549c56fa52b822db552223ba47a2e1d88d 100644 (file)
@@ -13,6 +13,13 @@ public:
                     std::ostream& stdout,
                     std::ostream& stderr,
                     std::string& result);
+
+       int loadFile(const std::string& filename,
+                    std::ostream& stdout,
+                    std::ostream& stderr,
+                    std::string& result);
+
+       std::string fileExtension() const {return "scm";}
 private:
        SCM guile_output_port;
        SCM guile_error_port;
index a8d9ad90c9364a52fbacaedd7d99e74cd7da2eee..648301b926c1905229b1eb303d5edacca853d24f 100644 (file)
@@ -10,6 +10,13 @@ public:
                             std::ostream& stdout,
                             std::ostream& stderr,
                             std::string& result) = 0;
+
+       virtual int loadFile(const std::string& filename,
+                            std::ostream& stdout,
+                            std::ostream& stderr,
+                            std::string& result) = 0;
+
+       virtual std::string fileExtension() const = 0;
 private:
 };
 
index a42d3f4e9ef67d588b4922b71ac110ce913da40c..9d8e45f66e5f69749e06223d96e620e6be761bec 100644 (file)
@@ -46,9 +46,23 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        fileMenu->addSeparator();
        fileMenu->addAction(exitAction);
 
-       scripting = new ScriptingDock(new GuileInterpreter, tr("Scripting"), this);
+       QMenu* interpretermenu = menuBar()->addMenu(tr("&Interpreter"));
+
+       interpreter["GUILE"] = new GuileInterpreter;
+       scripting = new ScriptingDock(interpreter["GUILE"], tr("Scripting"), this);
        scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
        addDockWidget(Qt::BottomDockWidgetArea, scripting);
+       QAction* guileLoad = new QAction(tr("&GUILE"), this);
+       interpretermenu->addAction(guileLoad);
+       connect(guileLoad, &QAction::triggered,
+               [&]() {
+                       QString fileName = QFileDialog::getOpenFileName(this, tr("Open Script"), "",
+                                                                       tr("Binaries") + " (*." +
+                                                                       interpreter["GUILE"]->fileExtension().c_str() + ")");
+                       std::stringstream a, b;
+                       std::string c;
+                       interpreter["GUILE"]->loadFile(fileName.toStdString(), a, b, c);
+               });
 
        listWidget = new QTreeWidget();
        listWidget->setColumnCount(1);
index f89f3ce140dfb02cba3269eccf47f82954f89ce2..8b46404b3a8331330177795188dbfb3205fb74b3 100644 (file)
@@ -4,6 +4,7 @@
 #include <memory>
 #include <map>
 #include <vector>
+#include <string>
 
 #include <QTextEdit>
 #include <QPushButton>
@@ -19,6 +20,7 @@ class InformationManager;
 class FunctionWidget;
 class BasicBlockWidget;
 class ScriptingDock;
+class Interpreter;
 
 class Mainwindow : public QMainWindow {
        Q_OBJECT
@@ -53,6 +55,7 @@ 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;