]> git.siccegge.de Git - frida/frida.git/commitdiff
Allow addition of new functions
authorChristoph Egger <Christoph.Egger@fau.de>
Thu, 22 Jan 2015 18:53:27 +0000 (19:53 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Thu, 22 Jan 2015 18:56:13 +0000 (19:56 +0100)
The ListWidget now displays a ContextMenu where the user can add a new
function by typing the address

CMakeLists.txt
src/disassembler/Disassembler.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx
src/gui/dialogs/NewFunctionDialog.cxx [new file with mode: 0644]
src/gui/dialogs/NewFunctionDialog.hxx [new file with mode: 0644]
src/gui/qt.hxx

index 3a14e989234ba2cb53d7f7fbb20f100588d4947b..dfcd8859c880487c93664ac75d63621f009e473f 100644 (file)
@@ -48,6 +48,7 @@ SET(frida_SOURCES
   src/gui/widgets/BasicBlockWidget.cxx
   src/gui/widgets/CFGScene.cxx
   src/gui/widgets/ScriptingDock.cxx
+  src/gui/dialogs/NewFunctionDialog.cxx
   src/disassembler/Disassembler.cxx
   src/disassembler/llvm/LLVMDisassembler.cxx
   )
@@ -59,6 +60,7 @@ SET(frida_HEADERS
   src/gui/widgets/BasicBlockWidget.hxx
   src/gui/widgets/CFGScene.hxx
   src/gui/widgets/ScriptingDock.hxx
+  src/gui/dialogs/NewFunctionDialog.hxx
   src/disassembler/llvm/LLVMDisassembler.hxx
   src/disassembler/Disassembler.hxx
   )
index 5af2eac9d96f84bcbbbaebd16b2b84ce3ee0149a..dbc140ef021451daa37659697dda64bc73d2fe3b 100644 (file)
@@ -22,6 +22,7 @@ public:
        virtual void printEachInstruction(uint64_t start, uint64_t end,
                                          std::function<void (uint8_t*, size_t, const std::string&,
                                                              const std::string&)> fun) = 0;
+       virtual Function * disassembleFunctionAt(uint64_t address, const std::string& name = "") = 0;
 protected:
        virtual bool isFunctionCall(uint64_t address) = 0;
        virtual bool isJump(uint64_t address) = 0;
index 46ce2e98562a24cca3b63c460a935529a979de48..764eb0376d1ca4acb12f56fb0faa7b37c27c98d1 100644 (file)
@@ -3,7 +3,7 @@
 #include "disassembler/llvm/LLVMDisassembler.hxx"
 
 #include "widgets/CFGScene.hxx"
-
+#include "dialogs/NewFunctionDialog.hxx"
 #include <iostream>
 #include <sstream>
 #include <map>
@@ -41,6 +41,10 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        addDockWidget(Qt::BottomDockWidgetArea, scripting);
 
        listWidget = new QListWidget();
+       listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
+       connect(listWidget, SIGNAL(customContextMenuRequested(const QPoint&)),
+               this, SLOT(showListContextMenu(const QPoint&)));
+
        stackedWidget = new QStackedWidget();
        dockWidget = new QDockWidget(tr("Functions"), this);
        dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
@@ -64,7 +68,7 @@ Mainwindow::Mainwindow(InformationManager* mgr)
 void Mainwindow::quit()
 {
        QMessageBox messageBox;
-       messageBox.setWindowTitle(tr("Notepad"));
+       messageBox.setWindowTitle(tr("Frida"));
        messageBox.setText(tr("Do you really want to quit?"));
        messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        messageBox.setDefaultButton(QMessageBox::No);
@@ -79,6 +83,30 @@ void Mainwindow::open() {
        manager->reset(fileName.toStdString());
 }
 
+void Mainwindow::showListContextMenu(const QPoint& point) {
+       QListWidgetItem * item = listWidget->itemAt(point);
+       if (item) {
+               LOG4CXX_DEBUG(logger, "WOHO " << item->text().toStdString());
+       } else {
+               QMenu menu(this);
+               QAction * act = menu.addAction("AddFunction");
+               connect(act, SIGNAL(triggered()), this, SLOT(requestNewFunction()));
+
+               menu.exec(listWidget->mapToGlobal(point));
+       }
+}
+
+void Mainwindow::requestNewFunction() {
+       NewFunctionDialog dialog;
+       int result = dialog.exec();
+       if (QDialog::Accepted == result) {
+               LOG4CXX_DEBUG(logger, "requesting Function at " << std::hex << dialog.result());
+               manager->getDisassembler()->disassembleFunctionAt(dialog.result());
+       } else {
+               LOG4CXX_DEBUG(logger, "requestNewFunction aborted");
+       }
+}
+
 void Mainwindow::addFunction(Function* fun) {
        if (functions.find(fun) != functions.end())
                return;
index bb2a90e2a4fd15e19933d7b48f0f6b9606242e6e..953b3152b4b48221bb6f376a2ca56ae3d02f4a05 100644 (file)
@@ -22,6 +22,7 @@ class Mainwindow : public QMainWindow {
        Q_OBJECT
 public:
        Mainwindow(InformationManager* mgr);
+
 private:
        void addFunction(Function* fun);
 
@@ -46,6 +47,8 @@ private:
 private Q_SLOTS:
        void quit();
        void open();
+       void showListContextMenu(const QPoint&);
+       void requestNewFunction();
 };
 
 #endif /* INCLUDE__Mainwindow_hxx_ */
diff --git a/src/gui/dialogs/NewFunctionDialog.cxx b/src/gui/dialogs/NewFunctionDialog.cxx
new file mode 100644 (file)
index 0000000..3c605d1
--- /dev/null
@@ -0,0 +1,27 @@
+#include "NewFunctionDialog.hxx"
+
+NewFunctionDialog::NewFunctionDialog() {
+       QGridLayout * layout = new QGridLayout;
+
+       edit = new QLineEdit;
+       layout->addWidget(edit, 0, 0, 1, 2);
+       edit->setInputMask("\\0\\xhhhhhhhhhhhhhhhH");
+       
+       QPushButton * cancelButton = new QPushButton("Cancel");
+       QPushButton * okButton = new QPushButton("OK");
+       layout->addWidget(okButton, 1, 1, 1, 1);
+       connect(okButton, SIGNAL(clicked()),
+               this, SLOT(accept()));
+       layout->addWidget(cancelButton, 1, 0, 1, 1);
+       connect(cancelButton, SIGNAL(clicked()),
+               this, SLOT(reject()));
+       
+       setLayout(layout);
+       setWindowTitle("Add function");
+}
+
+uint64_t NewFunctionDialog::result() {
+       bool ok;
+       uint64_t result = edit->text().toLongLong(&ok, 16);
+       return result;
+}
diff --git a/src/gui/dialogs/NewFunctionDialog.hxx b/src/gui/dialogs/NewFunctionDialog.hxx
new file mode 100644 (file)
index 0000000..9f04ed1
--- /dev/null
@@ -0,0 +1,11 @@
+#include "gui/qt.hxx"
+
+class NewFunctionDialog : public QDialog {
+       Q_OBJECT
+public:
+       NewFunctionDialog();
+
+       uint64_t result();
+private:
+       QLineEdit * edit;
+};
index 7397b23db338e769e76a11fca6bc2565e562f6ce..64ca4c11c26a889a78b0dae740ecd11ea97a4625 100644 (file)
@@ -22,5 +22,7 @@
 #include <QPushButton>
 #include <QLineEdit>
 #include <QLabel>
+#include <QtGui>
+#include <QMenu>
 
 #endif /* INCLUDE__qt_hxx_ */