+void Mainwindow::load() {
+ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
+ tr("Frida Archives (*.frida)"));
+ manager->load(fileName.toStdString());
+}
+
+void Mainwindow::save() {
+ QString filename = QFileDialog::getSaveFileName(this, tr("Save File"), "", tr("Frida Archives (*.frida)"));
+ manager->save(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);
+ QTreeWidgetItem * 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(QTreeWidgetItem* to) {
+ if (objects_list.end() != objects_list.find(to))
+ stackedWidget->setCurrentWidget(objects_list[to]);
+}
+
+void Mainwindow::showListContextMenu(const QPoint& point) {
+ QAction * act;
+ QTreeWidgetItem * item = listWidget->itemAt(point);
+ QMenu menu(this);
+
+ act = menu.addAction("Add Function");
+ connect(act, &QAction::triggered, this, &Mainwindow::requestNewFunction);
+
+ act = menu.addAction("Add Group");
+ connect(act, &QAction::triggered, this, &Mainwindow::requestNewGroup);
+
+ if (item) {
+ if (objects_list.find(item) != objects_list.end()) {
+ act = menu.addAction("Rename Function");
+ connect(act, &QAction::triggered, [=]() {this->renameFunction(objects_list[item]->getFunction());});
+ } else {
+ act = menu.addAction("Rename Group");
+ connect(act, &QAction::triggered, [=]() {renameGroup(item);});
+ }
+
+
+ QMenu* submenu = menu.addMenu("Move to group");
+
+ for (QTreeWidgetItem* groupitem : group_list) {
+ act = submenu->addAction(groupitem->text(0));
+ connect(act, &QAction::triggered,
+ [=] () {
+ listWidget->invisibleRootItem()->removeChild(item);
+ groupitem->addChild(item);
+ });
+ }
+ }
+
+ menu.exec(listWidget->mapToGlobal(point));
+}
+
+void Mainwindow::requestNewFunction() {
+ NewFunctionDialog dialog;
+ int result = dialog.exec();
+ if (QDialog::Accepted == result) {
+ requestNewFunctionByAddress(dialog.result());
+ } else {
+ LOG4CXX_DEBUG(logger, "requestNewFunction aborted");
+ }
+}
+
+void Mainwindow::requestNewGroup() {
+ SimpleStringDialog dialog("New Group");
+ int result = dialog.exec();
+ if (QDialog::Accepted == result) {
+ QTreeWidgetItem * external = new QTreeWidgetItem(listWidget, QStringList(dialog.result()));
+ external->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
+ group_list.push_back(external);
+ } else {
+ LOG4CXX_DEBUG(logger, "requestNewGroup aborted");
+ }
+}
+
+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 " << function->getName()
+ << " to " << dialog.result().toStdString());
+ function->setName(dialog.result().toStdString());
+ } else {
+ LOG4CXX_DEBUG(logger, "renameFunction aborted");
+ }
+}
+
+void Mainwindow::renameGroup(QTreeWidgetItem* item) {
+ SimpleStringDialog dialog("New name");
+ int result = dialog.exec();
+ if (QDialog::Accepted == result) {
+ LOG4CXX_DEBUG(logger, "renaming group " << item->text(0).toStdString()
+ << " to " << dialog.result().toStdString());
+ item->setText(0, dialog.result());
+ } else {
+ LOG4CXX_DEBUG(logger, "renameFunction aborted");
+ }
+}
+