From bb5959013f2daeff2c0639e868d6406500dc17fb Mon Sep 17 00:00:00 2001 From: Christoph Egger Date: Fri, 20 Feb 2015 18:25:54 +0100 Subject: [PATCH] Properly rename function Renaming a function now also changes the Function object and therefor is represented in the saved data (and available for forther processing) --- CMakeLists.txt | 2 ++ src/core/Function.hxx | 7 ++++--- src/gui/Mainwindow.cxx | 18 ++++++++++-------- src/gui/Mainwindow.hxx | 10 +++++----- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ee8b0e..629d7e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ SET(frida_SOURCES src/gui/widgets/BasicBlockWidget.cxx src/gui/widgets/CFGScene.cxx src/gui/widgets/ScriptingDock.cxx + src/gui/widgets/FunctionWidget.cxx src/gui/dialogs/NewFunctionDialog.cxx src/gui/dialogs/SimpleStringDialog.cxx src/disassembler/Disassembler.cxx @@ -60,6 +61,7 @@ SET(frida_HEADERS src/gui/widgets/BasicBlockWidget.hxx src/gui/widgets/CFGScene.hxx src/gui/widgets/ScriptingDock.hxx + src/gui/widgets/FunctionWidget.hxx src/gui/dialogs/NewFunctionDialog.hxx src/gui/dialogs/SimpleStringDialog.hxx src/disassembler/llvm/LLVMDisassembler.hxx diff --git a/src/core/Function.hxx b/src/core/Function.hxx index f4fa90e..39d3f51 100644 --- a/src/core/Function.hxx +++ b/src/core/Function.hxx @@ -18,9 +18,10 @@ public: return start_address; } - std::string getName() const { - return name; - } + std::string getName() const + { return name; } + void setName(const std::string& new_name) + { name = new_name; } InformationManager* getManager() const { return manager; diff --git a/src/gui/Mainwindow.cxx b/src/gui/Mainwindow.cxx index 4d6e2c0..b2f5b4d 100644 --- a/src/gui/Mainwindow.cxx +++ b/src/gui/Mainwindow.cxx @@ -6,6 +6,7 @@ #include "core/InformationManager.hxx" #include "widgets/ScriptingDock.hxx" #include "widgets/CFGScene.hxx" +#include "widgets/FunctionWidget.hxx" #include "dialogs/NewFunctionDialog.hxx" #include "dialogs/SimpleStringDialog.hxx" @@ -76,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()); }); } @@ -124,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())); @@ -148,25 +149,26 @@ void Mainwindow::requestNewFunctionByAddress(uint64_t address) { switchMainPlaneToAddress(address); } -void Mainwindow::renameFunction(QListWidgetItem * item) { +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; diff --git a/src/gui/Mainwindow.hxx b/src/gui/Mainwindow.hxx index 633c647..ba0d8b4 100644 --- a/src/gui/Mainwindow.hxx +++ b/src/gui/Mainwindow.hxx @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -16,6 +15,7 @@ class Disassembler; class Function; class InformationManager; +class FunctionWidget; class BasicBlockWidget; class ScriptingDock; @@ -47,11 +47,11 @@ private: QAction *saveAction; std::map blocks; - std::map objects_list; + std::map functions; + std::map objects_list; std::map objects_list_by_address; - std::set functions; - InformationManager* manager; + InformationManager* manager; log4cxx::LoggerPtr logger; private Q_SLOTS: @@ -61,7 +61,7 @@ private Q_SLOTS: void switchMainPlane(int); void showListContextMenu(const QPoint&); void requestNewFunction(); - void renameFunction(QListWidgetItem * item); + void renameFunction(Function* function); }; #endif /* INCLUDE__Mainwindow_hxx_ */ -- 2.39.2