X-Git-Url: https://git.siccegge.de//index.cgi?p=frida%2Ffrida.git;a=blobdiff_plain;f=src%2Fgui%2FMainwindow.cxx;h=754d5b2b0f1ab244b7932e77f571b14f1abc4d85;hp=764eb0376d1ca4acb12f56fb0faa7b37c27c98d1;hb=26ff0a6f5b4ea19657f851a82a8d679f10d19edb;hpb=21463b5c215974f253a0100231890ed909cd19e3 diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 764eb03..754d5b2 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -4,15 +4,14 @@ #include "widgets/CFGScene.hxx" #include "dialogs/NewFunctionDialog.hxx" -#include -#include -#include +#include "dialogs/RenameFunctionDialog.hxx" -#include +#include namespace { BasicBlockWidget * local__add_basic_block(BasicBlock * block, Disassembler * dis, + Mainwindow * mainwindow, std::map& 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& 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;