]> git.siccegge.de Git - frida/frida.git/commitdiff
Properly rename function
authorChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Feb 2015 17:25:54 +0000 (18:25 +0100)
committerChristoph Egger <Christoph.Egger@fau.de>
Fri, 20 Feb 2015 17:25:54 +0000 (18:25 +0100)
Renaming a function now also changes the Function object and therefor is
represented in the saved data (and available for forther processing)

CMakeLists.txt
src/core/Function.hxx
src/gui/Mainwindow.cxx
src/gui/Mainwindow.hxx

index 6ee8b0edf1feb66d66c2c242ee0e41f65ede6694..629d7e125653de0f4f3746b94e65799277c0b150 100644 (file)
@@ -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
index f4fa90e1e429eeaf9928896b454906226ce3e223..39d3f51b47cc39aab43c453f0cf3edc4b598b55f 100644 (file)
@@ -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;
index 4d6e2c05c1b3b2dd5805131229cd6dd00b3847e1..b2f5b4da2b1e273e1e3a0ed7065bb1e9b2ba3996 100644 (file)
@@ -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;
index 633c6478a8ce28002f85b47c6c2455584fc04ad4..ba0d8b4944529138ff78fbf2e9b995133c677dab 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <memory>
 #include <map>
-#include <set>
 
 #include <QTextEdit>
 #include <QPushButton>
@@ -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<uint64_t, BasicBlockWidget*> blocks;
-       std::map<QListWidgetItem*, QWidget*> objects_list;
+       std::map<uint64_t, Function*> functions;
+       std::map<QListWidgetItem*, FunctionWidget*> objects_list;
        std::map<uint64_t, QListWidgetItem*> objects_list_by_address;
-       std::set<Function*> 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_ */