From: Christoph Egger Date: Wed, 26 Nov 2014 19:28:59 +0000 (+0100) Subject: Add guile scripting X-Git-Tag: v0.1~168 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=9f0c6d8fbed0f25248f28acced4c7372dd259d7a;p=frida%2Ffrida.git Add guile scripting --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5969d9c..bd078ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index ace89f3..c00c8f8 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -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); diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index a0ba231..032cabd 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -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; diff --git a/src/gui/qt.hxx b/src/gui/qt.hxx index 493e7b2..f0e326e 100644 --- a/src/gui/qt.hxx +++ b/src/gui/qt.hxx @@ -14,3 +14,7 @@ #include #include #include +#include +#include +#include +#include diff --git a/src/gui/widgets/ScriptingDock.cxx b/src/gui/widgets/ScriptingDock.cxx new file mode 100644 index 0000000..b354570 --- /dev/null +++ b/src/gui/widgets/ScriptingDock.cxx @@ -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 index 0000000..d60158b --- /dev/null +++ b/src/gui/widgets/ScriptingDock.hxx @@ -0,0 +1,39 @@ +#ifndef INCLUDE__ScriptingDock_hxx +#define INCLUDE__ScriptingDock_hxx +#include "gui/qt.hxx" +#include +#include + +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