]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/Mainwindow.cxx
Add missing space to log message
[frida/frida.git] / src / gui / Mainwindow.cxx
index 764eb0376d1ca4acb12f56fb0faa7b37c27c98d1..55bc86dd4fca2576bb9fa168ec82e2f8754f87c8 100644 (file)
@@ -4,15 +4,14 @@
 
 #include "widgets/CFGScene.hxx"
 #include "dialogs/NewFunctionDialog.hxx"
-#include <iostream>
-#include <sstream>
-#include <map>
+#include "dialogs/RenameFunctionDialog.hxx"
 
-#include <QtGui>
+#include <sstream>
 
 namespace {
        BasicBlockWidget *
        local__add_basic_block(BasicBlock * block, Disassembler * dis,
+                              Mainwindow * mainwindow,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx);
 }
@@ -54,7 +53,7 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        setCentralWidget(stackedWidget);
 
        connect(listWidget, SIGNAL(currentRowChanged(int)),
-               stackedWidget, SLOT(setCurrentIndex(int)));
+               this, SLOT(switchMainPlane(int)));
 
        setWindowTitle(tr("FRIDA"));
 
@@ -63,6 +62,18 @@ Mainwindow::Mainwindow(InformationManager* mgr)
                        auto item = new QListWidgetItem(name.c_str(), listWidget);
                        item->setBackground(QBrush(QColor(0xff, 0xdd, 0xdd)));
                });
+       setGlobalHotkeys();
+}
+
+void Mainwindow::setGlobalHotkeys() {
+       QShortcut *shortcut = new QShortcut(QKeySequence("f"), this);
+       connect(shortcut, &QShortcut::activated, this, &Mainwindow::requestNewFunction);
+
+       shortcut = new QShortcut(QKeySequence("r"), listWidget);
+       connect(shortcut, &QShortcut::activated, [=]() {
+                       QListWidgetItem * item = listWidget->currentItem();
+                       if (item) renameFunction(item);
+               });
 }
 
 void Mainwindow::quit()
@@ -83,17 +94,33 @@ void Mainwindow::open() {
        manager->reset(fileName.toStdString());
 }
 
+void Mainwindow::switchMainPlaneToAddress(uint64_t address) {
+       if (objects_list_by_address.find(address) != objects_list_by_address.end()) {
+               LOG4CXX_DEBUG(logger, "Switching to function " << std::hex << address);
+               QListWidgetItem * item = objects_list_by_address[address];
+               listWidget->setCurrentItem(item);
+               stackedWidget->setCurrentWidget(objects_list[item]);
+       } else {
+               LOG4CXX_DEBUG(logger, "No function at " << std::hex << address
+                             << " -- it's probably an imported Symbol");
+       }
+}
+
+void Mainwindow::switchMainPlane(int index) {
+       stackedWidget->setCurrentWidget(objects_list[listWidget->currentItem()]);
+}
+
 void Mainwindow::showListContextMenu(const QPoint& point) {
        QListWidgetItem * item = listWidget->itemAt(point);
+       QMenu menu(this);
        if (item) {
-               LOG4CXX_DEBUG(logger, "WOHO " << item->text().toStdString());
+               QAction * act = menu.addAction("Rename Function");
+               connect(act, &QAction::triggered, [=]() {this->renameFunction(item);});
        } else {
-               QMenu menu(this);
                QAction * act = menu.addAction("AddFunction");
                connect(act, SIGNAL(triggered()), this, SLOT(requestNewFunction()));
-
-               menu.exec(listWidget->mapToGlobal(point));
        }
+       menu.exec(listWidget->mapToGlobal(point));
 }
 
 void Mainwindow::requestNewFunction() {
@@ -107,6 +134,18 @@ void Mainwindow::requestNewFunction() {
        }
 }
 
+void Mainwindow::renameFunction(QListWidgetItem * item) {
+       RenameFunctionDialog dialog;
+       int result = dialog.exec();
+       if (QDialog::Accepted == result) {
+               LOG4CXX_DEBUG(logger, "renaming Function " << item->text().toStdString()
+                             << " to " << dialog.result().toStdString());
+               item->setText(dialog.result());
+       } else {
+               LOG4CXX_DEBUG(logger, "renameFunction aborted");
+       }
+}
+
 void Mainwindow::addFunction(Function* fun) {
        if (functions.find(fun) != functions.end())
                return;
@@ -127,8 +166,8 @@ void Mainwindow::addFunction(Function* fun) {
                        start_address = b.first;
        }
 
-       local__add_basic_block(block, manager->getDisassembler(), blocks, scene,
-                              start_address, 100);
+       local__add_basic_block(block, manager->getDisassembler(), this,
+                              blocks, scene, start_address, 100);
 
        QGraphicsView * view = new QGraphicsView(scene);
        w->addTab(view, "CFG");
@@ -140,13 +179,18 @@ void Mainwindow::addFunction(Function* fun) {
 
        w->addTab(t, "Listing");
 
-       listWidget->addItem(fun->getName().c_str());
+       QListWidgetItem * item = new QListWidgetItem(fun->getName().c_str(), listWidget);
        stackedWidget->addWidget(w);
+       objects_list.insert(std::make_pair(item, w));
+       LOG4CXX_DEBUG(logger, "Adding function widget at " << std::hex
+                     << fun->getStartAddress());
+       objects_list_by_address.insert(std::make_pair(fun->getStartAddress(), item));
 }
 
 namespace {
        BasicBlockWidget *
        local__add_basic_block(BasicBlock * block, Disassembler * dis,
+                              Mainwindow * mainwindow,
                               std::map<uint64_t, BasicBlockWidget*>& known_blocks,
                               CFGScene * scene, uint64_t starty, uint64_t startx) {
 
@@ -157,7 +201,8 @@ namespace {
                std::stringstream s;
                s << "BLOCK_" << std::hex << block->getStartAddress()
                  << "_" << block->getEndAddress();
-               BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(), block);
+               BasicBlockWidget * widget = new BasicBlockWidget(s.str().c_str(),
+                                                                block, mainwindow);
 
                known_blocks.insert(std::make_pair(block->getStartAddress(), widget));
 
@@ -184,6 +229,7 @@ namespace {
                                xshift = 1;
                        tmpblock = dis->getBasicBlock(block->getNextBlock(0));
                        tmp = local__add_basic_block(tmpblock, dis,
+                                                    mainwindow,
                                                     known_blocks,
                                                     scene, starty, startx+xshift);
                        nextl = tmp;
@@ -192,6 +238,7 @@ namespace {
                if (block->getNextBlock(1) != 0) {
                        tmpblock = dis->getBasicBlock(block->getNextBlock(1));
                        tmp = local__add_basic_block(tmpblock, dis,
+                                                    mainwindow,
                                                     known_blocks,
                                                     scene, starty, startx-1);
                        nextr = tmp;