]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/Mainwindow.cxx
Pass NewFunctionEvents as objects, not pointers
[frida/frida.git] / src / gui / Mainwindow.cxx
index 47c78858e46314efbe448a1d185b1f7377e8e3d2..1add669e55c6f32c3174f74e45123f71e746aa4c 100644 (file)
@@ -6,6 +6,10 @@
 #include "core/BasicBlock.hxx"
 #include "core/InformationManager.hxx"
 #include "core/events/RenameFunctionEvent.hxx"
+#include "core/events/NewFunctionEvent.hxx"
+
+#include "widgets/FridaDock.hxx"
+#include "widgets/LogDock.hxx"
 #include "widgets/ScriptingDock.hxx"
 #include "widgets/CFGScene.hxx"
 #include "widgets/FunctionWidget.hxx"
@@ -16,7 +20,7 @@
 
 Mainwindow::Mainwindow(InformationManager* mgr)
        : manager(mgr)
-       , logger(log4cxx::Logger::getLogger("Mainwindow")) {
+       , logger(log4cxx::Logger::getLogger("gui.Mainwindow")) {
        openAction = new QAction(tr("&Open"), this);
        loadAction = new QAction(tr("&Load"), this);
        saveAction = new QAction(tr("&Save"), this);
@@ -40,20 +44,25 @@ Mainwindow::Mainwindow(InformationManager* mgr)
 
        QMenu* interpretermenu = menuBar()->addMenu(tr("&Interpreter"));
 
-       interpreter["GUILE"] = new GuileInterpreter;
-       scripting = new ScriptingDock(interpreter["GUILE"], tr("Scripting"), this);
-       scripting->setAllowedAreas(Qt::BottomDockWidgetArea);
-       addDockWidget(Qt::BottomDockWidgetArea, scripting);
+       fdock = new FridaDock(tr("Frida Dock"), this);
+
+       fdock->addTab(new LogDock(fdock), "Log");
+
+       fdock->addTab(new ScriptingDock(manager->getInterpreter("GUILE"), fdock), "guile");
+       fdock->setAllowedAreas(Qt::BottomDockWidgetArea);
+       addDockWidget(Qt::BottomDockWidgetArea, fdock);
        QAction* guileLoad = new QAction(tr("&GUILE"), this);
        interpretermenu->addAction(guileLoad);
        connect(guileLoad, &QAction::triggered,
                [&]() {
                        QString fileName = QFileDialog::getOpenFileName(this, tr("Open Script"), "",
-                                                                       tr("Binaries") + " (*." +
-                                                                       interpreter["GUILE"]->fileExtension().c_str() + ")");
-                       std::stringstream a, b;
-                       std::string c;
-                       interpreter["GUILE"]->loadFile(fileName.toStdString(), a, b, c);
+                                                                       tr("Scripts") + " (*." +
+                                                                       manager->getInterpreter("GUILE")->fileExtension().c_str() + ")");
+                       if(! fileName.isNull()) {
+                               std::stringstream a, b;
+                               std::string c;
+                               manager->getInterpreter("GUILE")->loadFile(fileName.toStdString(), a, b, c);
+                       }
                });
 
        listWidget = new QTreeWidget();
@@ -78,20 +87,23 @@ Mainwindow::Mainwindow(InformationManager* mgr)
 
        setWindowTitle(tr("FRIDA"));
 
-       QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList("External Functions"));
+       external = new QTreeWidgetItem(listWidget, QStringList("External Functions"));
        external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
        external->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
-       mgr->connect_new_function_signal([&] (Function* fun) {addFunction(fun);});
-       mgr->connect_new_dyn_symbol_signal([=] (const std::string& name) {
-                       auto item = new QTreeWidgetItem(external, QStringList(name.c_str()));
-                       item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
-               });
-       mgr->connect_rename_function_signal([&](RenameFunctionEvent* event) {
-                       if (objects_list_by_address.find(event->address) == objects_list_by_address.end())
-                               return;
-                       auto item = objects_list_by_address[event->address];
-                       if (item) item->setText(0, event->new_name.c_str());
-               });
+       connect(mgr, &InformationManager::resetEvent,
+               [this,mgr]() {
+                       connect(this, SIGNAL(requestNewFunctionByAddress(uint64_t)),
+                               mgr->getDisassembler(), SLOT(disassembleFunctionAt(uint64_t)));
+               });
+       connect(mgr, &InformationManager::newFunctionEvent,
+               this, &Mainwindow::handleNewFunctionEvent);
+       connect(mgr, &InformationManager::renameFunctionEvent,
+               [&](RenameFunctionEvent* event) {
+                       if (objects_list_by_address.find(event->address) == objects_list_by_address.end())
+                               return;
+                       auto item = objects_list_by_address[event->address];
+                       if (item) item->setText(0, event->new_name.c_str());
+               });
        setGlobalHotkeys();
 }
 
@@ -106,6 +118,16 @@ void Mainwindow::setGlobalHotkeys() {
                });
 }
 
+void Mainwindow::handleNewFunctionEvent(NewFunctionEvent event) {
+       std::string name = event.function->getName();
+       if (event.function->isDynamic()) {
+               auto item = new QTreeWidgetItem(external, QStringList(name.c_str()));
+               item->setBackground(0, QBrush(QColor(0xff, 0xdd, 0xdd)));
+       } else {
+               addFunction(event.function);
+       }
+}
+
 void Mainwindow::quit()
 {
        QMessageBox messageBox;
@@ -118,15 +140,29 @@ void Mainwindow::quit()
 }
 
 void Mainwindow::open() {
-       QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
-                                                       tr("Binaries (*)"));
-       manager->reset(fileName.toStdString());
+       QFileDialog dialog(this, tr("Open bianry"), "", tr("Binaries (*)"));
+
+       if (dialog.exec()) {
+               QStringList files = dialog.selectedFiles();
+               if(1 != files.size()) {
+                       LOG4CXX_ERROR(logger, "Needs exactly one file name")
+               } else {
+                       manager->reset(files[0].toStdString());
+               }
+       }
 }
 
 void Mainwindow::load() {
-       QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
-                                                       tr("Frida Archives (*.frida)"));
-       manager->load(fileName.toStdString());
+       QFileDialog dialog(this, tr("Open saved FrIDa file"), "", tr("Frida Archives (*.frida)"));
+
+       if (dialog.exec()) {
+               QStringList files = dialog.selectedFiles();
+               if(1 != files.size()) {
+                       LOG4CXX_ERROR(logger, "Needs exactly one file name")
+               } else {
+                       manager->load(files[0].toStdString());
+               }
+       }
 }
 
 void Mainwindow::save() {
@@ -191,7 +227,7 @@ void Mainwindow::requestNewFunction() {
        NewFunctionDialog dialog;
        int result = dialog.exec();
        if (QDialog::Accepted == result) {
-               requestNewFunctionByAddress(dialog.result());
+               emit requestNewFunctionByAddress(dialog.result());
        } else {
                LOG4CXX_DEBUG(logger, "requestNewFunction aborted");
        }
@@ -209,12 +245,6 @@ void Mainwindow::requestNewGroup() {
        }
 }
 
-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();