]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/Mainwindow.cxx
Properly HTML Escape function names
[frida/frida.git] / src / gui / Mainwindow.cxx
index 55bc86dd4fca2576bb9fa168ec82e2f8754f87c8..b2f5b4da2b1e273e1e3a0ed7065bb1e9b2ba3996 100644 (file)
@@ -1,10 +1,14 @@
 #include "Mainwindow.hxx"
 #include "qt.hxx"
 #include "disassembler/llvm/LLVMDisassembler.hxx"
-
+#include "core/Function.hxx"
+#include "core/BasicBlock.hxx"
+#include "core/InformationManager.hxx"
+#include "widgets/ScriptingDock.hxx"
 #include "widgets/CFGScene.hxx"
+#include "widgets/FunctionWidget.hxx"
 #include "dialogs/NewFunctionDialog.hxx"
-#include "dialogs/RenameFunctionDialog.hxx"
+#include "dialogs/SimpleStringDialog.hxx"
 
 #include <sstream>
 
@@ -20,18 +24,19 @@ Mainwindow::Mainwindow(InformationManager* mgr)
        : manager(mgr)
        , logger(log4cxx::Logger::getLogger("Mainwindow")) {
        openAction = new QAction(tr("&Open"), this);
-       // saveAction = new QAction(tr("&Save"), this);
+       saveAction = new QAction(tr("&Save"), this);
        exitAction = new QAction(tr("E&xit"), this);
 
        connect(openAction, SIGNAL(triggered()),
                this, SLOT(open()));
-       // connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
+       connect(saveAction, SIGNAL(triggered()),
+               this, SLOT(save()));
        connect(exitAction, SIGNAL(triggered()),
                qApp, SLOT(quit()));
 
        fileMenu = menuBar()->addMenu(tr("&File"));
        fileMenu->addAction(openAction);
-       // fileMenu->addAction(saveAction);
+       fileMenu->addAction(saveAction);
        fileMenu->addSeparator();
        fileMenu->addAction(exitAction);
 
@@ -72,7 +77,7 @@ void Mainwindow::setGlobalHotkeys() {
        shortcut = new QShortcut(QKeySequence("r"), listWidget);
        connect(shortcut, &QShortcut::activated, [=]() {
                        QListWidgetItem * item = listWidget->currentItem();
-                       if (item) renameFunction(item);
+                       if (item) renameFunction(objects_list[item]->getFunction());
                });
 }
 
@@ -94,6 +99,11 @@ void Mainwindow::open() {
        manager->reset(fileName.toStdString());
 }
 
+void Mainwindow::save() {
+       QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Frida Archives (*.frida)"));
+       manager->save(filename);
+}
+
 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);
@@ -115,7 +125,7 @@ void Mainwindow::showListContextMenu(const QPoint& point) {
        QMenu menu(this);
        if (item) {
                QAction * act = menu.addAction("Rename Function");
-               connect(act, &QAction::triggered, [=]() {this->renameFunction(item);});
+               connect(act, &QAction::triggered, [=]() {this->renameFunction(objects_list[item]->getFunction());});
        } else {
                QAction * act = menu.addAction("AddFunction");
                connect(act, SIGNAL(triggered()), this, SLOT(requestNewFunction()));
@@ -127,32 +137,38 @@ 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());
+               requestNewFunctionByAddress(dialog.result());
        } else {
                LOG4CXX_DEBUG(logger, "requestNewFunction aborted");
        }
 }
 
-void Mainwindow::renameFunction(QListWidgetItem * item) {
-       RenameFunctionDialog dialog;
+void Mainwindow::requestNewFunctionByAddress(uint64_t address) {
+       LOG4CXX_DEBUG(logger, "requesting Function at " << std::hex << address);
+       manager->getDisassembler()->disassembleFunctionAt(address);
+       switchMainPlaneToAddress(address);
+}
+
+void Mainwindow::renameFunction(Function* function) {
+       SimpleStringDialog dialog("New name");
        int result = dialog.exec();
        if (QDialog::Accepted == result) {
-               LOG4CXX_DEBUG(logger, "renaming Function " << item->text().toStdString()
+               LOG4CXX_DEBUG(logger, "renaming Function " << function->getName()
                              << " to " << dialog.result().toStdString());
-               item->setText(dialog.result());
+               function->setName(dialog.result().toStdString());
+               objects_list_by_address[function->getStartAddress()]->setText(dialog.result());
        } else {
                LOG4CXX_DEBUG(logger, "renameFunction aborted");
        }
 }
 
 void Mainwindow::addFunction(Function* fun) {
-       if (functions.find(fun) != functions.end())
+       if (functions.find(fun->getStartAddress()) != functions.end())
                return;
 
-       functions.insert(fun);
+       functions.insert(std::make_pair(fun->getStartAddress(), fun));
 
-       QTabWidget * w = new QTabWidget();
+       FunctionWidget * w = new FunctionWidget(fun);
 
        // CFG
        CFGScene * scene = new CFGScene;