]> git.siccegge.de Git - frida/frida.git/commitdiff
Add guile scripting
authorChristoph Egger <christoph@anonymous.siccegge.de>
Wed, 26 Nov 2014 19:28:59 +0000 (20:28 +0100)
committerChristoph Egger <christoph@anonymous.siccegge.de>
Wed, 26 Nov 2014 19:28:59 +0000 (20:28 +0100)
CMakeLists.txt
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx
src/gui/qt.hxx
src/gui/widgets/ScriptingDock.cxx [new file with mode: 0644]
src/gui/widgets/ScriptingDock.hxx [new file with mode: 0644]

index 5969d9cdebdab389aa3ce033662b35742bfe65f5..bd078ad0ee6a38138d500338222f261f7068fe01 100644 (file)
@@ -10,9 +10,11 @@ find_package(Qt5Widgets)
 find_package(Qt5 CONFIG REQUIRED Widgets Gui)
 find_package(PkgConfig)
 pkg_check_modules(LOG4CXX REQUIRED liblog4cxx)
+pkg_check_modules(GUILE REQUIRED guile-2.0)
 
 #add_compile_options(${LOG4CXX_CFLAGS})
 add_definitions(${LOG4CXX_CFLAGS})
+add_definitions(${GUILE_CFLAGS})
 
 find_program(LLVM_CONFIG llvm-config-3.5)
 
@@ -39,6 +41,7 @@ SET(frida_SOURCES
   src/main.cxx
   src/gui/Mainwindow.cxx
   src/gui/widgets/BasicBlockWidget.cxx
+  src/gui/widgets/ScriptingDock.cxx
   src/disassembler/Disassembler.cxx
   src/disassembler/llvm/LLVMDisassembler.cxx
   )
@@ -47,6 +50,7 @@ SET(frida_HEADERS
   src/gui/qt.hxx
   src/gui/Mainwindow.hxx
   src/gui/widgets/BasicBlockWidget.hxx
+  src/gui/widgets/ScriptingDock.hxx
   src/disassembler/llvm/LLVMDisassembler.hxx
   src/disassembler/Disassembler.hxx
   )
@@ -59,4 +63,4 @@ ADD_DEFINITIONS(${QT_DEFINITIONS})
 qt5_use_modules(frida Widgets)
 INCLUDE_DIRECTORIES("src")
 
-TARGET_LINK_LIBRARIES(frida ${QT_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_LIBS} ${LOG4CXX_LDFLAGS} -ltinfo -lpthread -ldl)
+TARGET_LINK_LIBRARIES(frida ${QT_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} -ltinfo -lpthread -ldl)
index ace89f34523d629da3bf7c1e8963c0073df03b62..c00c8f83637950f55cdf8009eb4c633a460b8999 100644 (file)
@@ -24,6 +24,10 @@ Mainwindow::Mainwindow(const std::string& filename)
     fileMenu->addSeparator();
     fileMenu->addAction(exitAction);
 
+    scripting = new ScriptingDock(tr("Scripting"), this);
+    scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
+    addDockWidget(Qt::BottomDockWidgetArea, scripting);
+
     listWidget = new QListWidget();
     stackedWidget = new QStackedWidget();
     dockWidget = new QDockWidget(tr("Functions"), this);
index a0ba231884b485ab53319196d050eab385009451..032cabd8e0cfdb354fa59f58142635ec74c95351 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "disassembler/Disassembler.hxx"
 #include "widgets/BasicBlockWidget.hxx"
+#include "widgets/ScriptingDock.hxx"
 
 class Mainwindow : public QMainWindow {
     Q_OBJECT
@@ -26,6 +27,7 @@ private:
     QListWidget * listWidget;
     QStackedWidget * stackedWidget;
     QDockWidget * dockWidget;
+    ScriptingDock * scripting;
 
     QAction *exitAction;
     QAction *openAction;
index 493e7b273545d78edf9d14901bf25452b380e9cc..f0e326eb990ee21ab1546350212171304e3b2edb 100644 (file)
@@ -14,3 +14,7 @@
 #include <QPainter>
 #include <QTableWidget>
 #include <QVBoxLayout>
+#include <QGraphicsSceneMouseEvent>
+#include <QTextBrowser>
+#include <QPushButton>
+#include <QLineEdit>
diff --git a/src/gui/widgets/ScriptingDock.cxx b/src/gui/widgets/ScriptingDock.cxx
new file mode 100644 (file)
index 0000000..b354570
--- /dev/null
@@ -0,0 +1,15 @@
+#include "ScriptingDock.hxx"
+
+void ScriptingDock::doEvaluate() {
+    QString text = line->text();
+    line->clear();
+    LOG4CXX_INFO(logger, "Evaluating String \"" << text.toStdString() << "\"");
+    browser->append(QString("> ") + text);
+    
+    SCM result_obj = scm_c_eval_string(text.toStdString().c_str());
+    SCM result_str = scm_object_to_string(result_obj, SCM_UNDEFINED);
+
+    SCM output = scm_get_output_string(guile_output_port);
+    browser->append(scm_to_locale_string(output));
+    browser->append(scm_to_locale_string(result_str));
+}
diff --git a/src/gui/widgets/ScriptingDock.hxx b/src/gui/widgets/ScriptingDock.hxx
new file mode 100644 (file)
index 0000000..d60158b
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef INCLUDE__ScriptingDock_hxx
+#define INCLUDE__ScriptingDock_hxx
+#include "gui/qt.hxx"
+#include <libguile.h>
+#include <log4cxx/logger.h>
+
+class ScriptingDock : public QDockWidget {
+    Q_OBJECT
+
+public:
+    ScriptingDock(const QString& title, QWidget * parent = 0)
+        : logger(log4cxx::Logger::getLogger("ScriptingDock")) {
+        QDockWidget(title, parent);
+        QWidget * widget = new QWidget;
+        widget->setLayout(layout = new QGridLayout(this));
+        layout->addWidget(browser = new QTextBrowser, 0, 0, 1, 0);
+        layout->addWidget(line = new QLineEdit, 1, 0);
+        layout->addWidget(button = new QPushButton(tr("Evaluate")), 1, 1);
+        setWidget(widget);
+        connect(button, SIGNAL(released()), this, SLOT(doEvaluate()));
+        connect(line, SIGNAL(returnPressed()), this, SLOT(doEvaluate()));
+        scm_init_guile();
+        guile_output_port = scm_open_output_string();
+        scm_set_current_output_port(guile_output_port);
+    }
+private:
+    log4cxx::LoggerPtr logger;
+    
+    QTextBrowser * browser;
+    QGridLayout * layout;
+    QPushButton * button;
+    QLineEdit * line;
+
+    SCM guile_output_port;
+private slots:
+    void doEvaluate();
+};
+
+#endif