From cf23b1ecf2bfb9d0a07c7332b9de7a8070570892 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Tue, 12 Mar 2024 19:33:01 +0530 Subject: [PATCH 1/9] Add Copy to Clipboard for VersionInfo dialog --- src/dialogs/VersionInfoDialog.cpp | 40 +++++++++++++++++++++++++++++++ src/dialogs/VersionInfoDialog.h | 10 ++++++++ src/dialogs/VersionInfoDialog.ui | 23 ++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 9cd5e03c1e..8871ae0534 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -8,6 +8,7 @@ #include #include #include +#include VersionInfoDialog::VersionInfoDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core()) @@ -21,6 +22,45 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) VersionInfoDialog::~VersionInfoDialog() {} +void VersionInfoDialog::on_buttonBox_rejected() +{ + close(); +} + +void VersionInfoDialog::on_copyVersionInfoButton_clicked() +{ + QString vinfo = "# " + ui->leftLabel->text() + "\n"; + + // Iterate & Copy leftTreeWidget items + QTreeWidgetItemIterator itl(ui->leftTreeWidget); + + int keyColumnIndex = 0, valueColumnIndex = 1; + + while (*itl) { + QString row = (*itl)->text(keyColumnIndex) + " : " + (*itl)->text(valueColumnIndex) + "\n"; + vinfo.append(row); + ++itl; + } + + vinfo.append("\n# " + ui->rightLabel->text() + "\n"); + + // Iterate & Copy rightTreeWidget items + QTreeWidgetItemIterator itr(ui->rightTreeWidget); + + while (*itr) { + QString row = (*itr)->text(keyColumnIndex) + " : " + (*itr)->text(valueColumnIndex) + "\n"; + vinfo.append(row); + ++itr; + } + + // Copy to Clipboard + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(vinfo); + + QMessageBox::information(this, tr("Copy to Clipboard"), + tr("Version information was successfully copied!")); +} + void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index 7974e059db..8803705e7e 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -18,6 +18,16 @@ class VersionInfoDialog : public QDialog explicit VersionInfoDialog(QWidget *parent = nullptr); ~VersionInfoDialog(); +private slots: + void on_buttonBox_rejected(); + + /** + * @fn AboutDialog::on_copyVersionInfoButton_clicked() + * + * @brief Copies the table values to Clipboard. + */ + void on_copyVersionInfoButton_clicked(); + private: std::unique_ptr ui; CutterCore *core; diff --git a/src/dialogs/VersionInfoDialog.ui b/src/dialogs/VersionInfoDialog.ui index 54e197b83b..2c48324715 100644 --- a/src/dialogs/VersionInfoDialog.ui +++ b/src/dialogs/VersionInfoDialog.ui @@ -135,6 +135,29 @@ + + + + + + + + :/img/icons/copy.svg:/img/icons/copy.svg + + + Copy + + + + + + + QDialogButtonBox::Close + + + + + From 6bb001a65e43c7939de548185ed8a67a0aa0f456 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Mon, 18 Mar 2024 12:44:24 +0530 Subject: [PATCH 2/9] update: versioninfo copy --- src/dialogs/VersionInfoDialog.cpp | 68 ++++++++++++++++++++++++++++++- src/dialogs/VersionInfoDialog.h | 16 +++++++- src/dialogs/VersionInfoDialog.ui | 14 ++++++- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 9cd5e03c1e..e562ac6818 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -8,19 +8,83 @@ #include #include #include +#include +#include VersionInfoDialog::VersionInfoDialog(QWidget *parent) : QDialog(parent), ui(new Ui::VersionInfoDialog), core(Core()) -{ +{ ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); // Get version information fillVersionInfo(); + + // Setup context menu and actions + copyActionLeftTreewidget = new QAction(tr("Copy"), this); + copyActionLeftTreewidget->setIcon(QIcon(":/img/icons/copy.svg")); + copyActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::Copy); + copyActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + copyActionRightTreewidget = new QAction(tr("Copy"), this); + copyActionRightTreewidget->setIcon(QIcon(":/img/icons/copy.svg")); + copyActionRightTreewidget->setShortcut(QKeySequence::StandardKey::Copy); + copyActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + selAllActionLeftTreewidget = new QAction(tr("Select All"), this); + selAllActionLeftTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll); + selAllActionLeftTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + selAllActionRightTreewidget = new QAction(tr("Select All"), this); + selAllActionRightTreewidget->setShortcut(QKeySequence::StandardKey::SelectAll); + selAllActionRightTreewidget->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); + + connect(copyActionLeftTreewidget, &QAction::triggered, this, [this](){ + CopyTreeWidgetSelection(ui->leftTreeWidget); + }); + + connect(copyActionRightTreewidget, &QAction::triggered, this, [this](){ + CopyTreeWidgetSelection(ui->rightTreeWidget); + }); + + connect(selAllActionLeftTreewidget, &QAction::triggered, this, [this](){ + ui->leftTreeWidget->selectAll(); + }); + + connect(selAllActionRightTreewidget, &QAction::triggered, this, [this](){ + ui->rightTreeWidget->selectAll(); + }); + + ui->leftTreeWidget->addAction(copyActionLeftTreewidget); + ui->leftTreeWidget->addAction(selAllActionLeftTreewidget); + + ui->rightTreeWidget->addAction(copyActionRightTreewidget); + ui->rightTreeWidget->addAction(selAllActionRightTreewidget); + + contextMenu = new QMenu(this); } VersionInfoDialog::~VersionInfoDialog() {} +void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) +{ + const int keyColumnIndex = 0, valueColumnIndex = 1; + QString vinfo, row; + + for(QTreeWidgetItem *x: t->selectedItems()){ + row = x->text(keyColumnIndex) + " = " + x->text(valueColumnIndex) + "\n"; + vinfo.append(row); + } + + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(vinfo.trimmed()); +} + +void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event){ + contextMenu->exec(event->globalPos()); + event->accept(); +} + void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); @@ -236,4 +300,4 @@ void VersionInfoDialog::fillVersionInfo() } qhelpers::adjustColumns(ui->rightTreeWidget, 0); } -} +} \ No newline at end of file diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index 7974e059db..b303a6af24 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -15,9 +15,21 @@ class VersionInfoDialog : public QDialog Q_OBJECT public: - explicit VersionInfoDialog(QWidget *parent = nullptr); + explicit VersionInfoDialog(QWidget *parent = nullptr); ~VersionInfoDialog(); +private slots: + void CopyTreeWidgetSelection(QTreeWidget *t); + +protected: + QMenu *contextMenu = nullptr; + QAction *copyActionLeftTreewidget = nullptr; + QAction *copyActionRightTreewidget = nullptr; + QAction *selAllActionLeftTreewidget = nullptr; + QAction *selAllActionRightTreewidget = nullptr; + + void contextMenuEvent(QContextMenuEvent *event) override; + private: std::unique_ptr ui; CutterCore *core; @@ -25,4 +37,4 @@ class VersionInfoDialog : public QDialog void fillVersionInfo(); }; -#endif // VERSIONINFODIALOG_H +#endif // VERSIONINFODIALOG_H \ No newline at end of file diff --git a/src/dialogs/VersionInfoDialog.ui b/src/dialogs/VersionInfoDialog.ui index 54e197b83b..59d41f3150 100644 --- a/src/dialogs/VersionInfoDialog.ui +++ b/src/dialogs/VersionInfoDialog.ui @@ -71,6 +71,12 @@ + + Qt::ActionsContextMenu + + + QAbstractItemView::ExtendedSelection + QFrame::StyledPanel @@ -103,6 +109,12 @@ + + Qt::ActionsContextMenu + + + QAbstractItemView::ExtendedSelection + QFrame::StyledPanel @@ -139,4 +151,4 @@ - + \ No newline at end of file From d8fc87411426a81a97cd0401bb6db626ba00cc1f Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Tue, 19 Mar 2024 03:12:58 +0530 Subject: [PATCH 3/9] update: versioninfo copy fix code --- src/dialogs/VersionInfoDialog.cpp | 19 ++++++++----------- src/dialogs/VersionInfoDialog.h | 3 --- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 24246683e3..01a90b323c 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -57,8 +57,6 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) ui->rightTreeWidget->addAction(copyActionRightTreewidget); ui->rightTreeWidget->addAction(selAllActionRightTreewidget); - - contextMenu = new QMenu(this); } VersionInfoDialog::~VersionInfoDialog() {} @@ -68,21 +66,20 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) const int keyColumnIndex = 0, valueColumnIndex = 1; QString vinfo, row; - for (QTreeWidgetItem *x : t->selectedItems()) { - row = x->text(keyColumnIndex) + " = " + x->text(valueColumnIndex) + "\n"; - vinfo.append(row); + QTreeWidgetItemIterator it(t); + + while (*it) { + if ((*it)->isSelected()) { + row = (*it)->text(keyColumnIndex) + " = " + (*it)->text(valueColumnIndex) + "\n"; + vinfo.append(row); + } + it++; } QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(vinfo.trimmed()); } -void VersionInfoDialog::contextMenuEvent(QContextMenuEvent *event) -{ - contextMenu->exec(event->globalPos()); - event->accept(); -} - void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index b3cfffe5a2..8f96e7bea2 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -22,14 +22,11 @@ private slots: void CopyTreeWidgetSelection(QTreeWidget *t); protected: - QMenu *contextMenu = nullptr; QAction *copyActionLeftTreewidget = nullptr; QAction *copyActionRightTreewidget = nullptr; QAction *selAllActionLeftTreewidget = nullptr; QAction *selAllActionRightTreewidget = nullptr; - void contextMenuEvent(QContextMenuEvent *event) override; - private: std::unique_ptr ui; CutterCore *core; From abb43ca78b17b8c24b11ab004dcbae8ab4c0ca29 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Thu, 28 Mar 2024 19:21:41 +0530 Subject: [PATCH 4/9] updated column handling --- src/dialogs/VersionInfoDialog.cpp | 77 ++++++++++++++++--------------- src/dialogs/VersionInfoDialog.h | 2 + 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 01a90b323c..6b1041edd1 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -63,14 +63,13 @@ VersionInfoDialog::~VersionInfoDialog() {} void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) { - const int keyColumnIndex = 0, valueColumnIndex = 1; QString vinfo, row; QTreeWidgetItemIterator it(t); while (*it) { if ((*it)->isSelected()) { - row = (*it)->text(keyColumnIndex) + " = " + (*it)->text(valueColumnIndex) + "\n"; + row = (*it)->text(KeyColumn) + " " + (*it)->text(ValueColumn) + "\n"; vinfo.append(row); } it++; @@ -104,17 +103,17 @@ void VersionInfoDialog::fillVersionInfo() // Left tree QTreeWidgetItem *addrItemL = new QTreeWidgetItem(); - addrItemL->setText(0, "Address:"); - addrItemL->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0))); + addrItemL->setText(KeyColumn, "Address:"); + addrItemL->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "addr", 0))); ui->leftTreeWidget->addTopLevelItem(addrItemL); QTreeWidgetItem *offItemL = new QTreeWidgetItem(); - offItemL->setText(0, "Offset:"); - offItemL->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0))); + offItemL->setText(KeyColumn, "Offset:"); + offItemL->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "offset", 0))); ui->leftTreeWidget->addTopLevelItem(offItemL); QTreeWidgetItem *entriesItemL = new QTreeWidgetItem(); - entriesItemL->setText(0, "Entries:"); + entriesItemL->setText(KeyColumn, "Entries:"); const ut64 num_entries = sdb_num_get(sdb, "num_entries", 0); for (size_t i = 0; i < num_entries; ++i) { auto key = QString("entry%0").arg(i); @@ -123,8 +122,8 @@ void VersionInfoDialog::fillVersionInfo() continue; } auto item = new QTreeWidgetItem(); - item->setText(0, RzAddressString(i)); - item->setText(1, value); + item->setText(KeyColumn, RzAddressString(i)); + item->setText(ValueColumn, value); entriesItemL->addChild(item); } ui->leftTreeWidget->addTopLevelItem(entriesItemL); @@ -135,17 +134,17 @@ void VersionInfoDialog::fillVersionInfo() // Right tree QTreeWidgetItem *addrItemR = new QTreeWidgetItem(); - addrItemR->setText(0, "Address:"); - addrItemR->setText(1, RzAddressString(sdb_num_get(sdb, "addr", 0))); + addrItemR->setText(KeyColumn, "Address:"); + addrItemR->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "addr", 0))); ui->rightTreeWidget->addTopLevelItem(addrItemR); QTreeWidgetItem *offItemR = new QTreeWidgetItem(); - offItemR->setText(0, "Offset:"); - offItemR->setText(1, RzAddressString(sdb_num_get(sdb, "offset", 0))); + offItemR->setText(KeyColumn, "Offset:"); + offItemR->setText(ValueColumn, RzAddressString(sdb_num_get(sdb, "offset", 0))); ui->rightTreeWidget->addTopLevelItem(offItemR); QTreeWidgetItem *entriesItemR = new QTreeWidgetItem(); - entriesItemR->setText(0, "Entries:"); + entriesItemR->setText(KeyColumn, "Entries:"); for (size_t num_version = 0;; num_version++) { auto path_version = QString("bin/cur/info/versioninfo/verneed/version%0").arg(num_version); @@ -155,8 +154,8 @@ void VersionInfoDialog::fillVersionInfo() } const char *filename = sdb_const_get(sdb, "file_name", 0); auto *parentItem = new QTreeWidgetItem(); - parentItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0))); - parentItem->setText(1, + parentItem->setText(KeyColumn, RzAddressString(sdb_num_get(sdb, "idx", 0))); + parentItem->setText(ValueColumn, QString("Version: %0\t" "File: %1") .arg(QString::number(sdb_num_get(sdb, "vn_version", 0)), @@ -172,14 +171,14 @@ void VersionInfoDialog::fillVersionInfo() } auto *childItem = new QTreeWidgetItem(); - childItem->setText(0, RzAddressString(sdb_num_get(sdb, "idx", 0))); + childItem->setText(KeyColumn, RzAddressString(sdb_num_get(sdb, "idx", 0))); QString childString = QString("Name: %0\t" "Flags: %1\t" "Version: %2\t") .arg(sdb_const_get(sdb, "name", 0), sdb_const_get(sdb, "flags", 0), QString::number(sdb_num_get(sdb, "version", 0))); - childItem->setText(1, childString); + childItem->setText(ValueColumn, childString); parentItem->addChild(childItem); } entriesItemR->addChild(parentItem); @@ -219,48 +218,48 @@ void VersionInfoDialog::fillVersionInfo() .arg(product_version_ls & 0xFFFF); auto item = new QTreeWidgetItem(); - item->setText(0, "Signature"); - item->setText(1, RzHexString(sdb_num_get(sdb, "Signature", 0))); + item->setText(KeyColumn, "Signature"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "Signature", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "StrucVersion"); - item->setText(1, RzHexString(sdb_num_get(sdb, "StrucVersion", 0))); + item->setText(KeyColumn, "StrucVersion"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "StrucVersion", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileVersion"); - item->setText(1, file_version); + item->setText(KeyColumn, "FileVersion"); + item->setText(ValueColumn, file_version); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "ProductVersion"); - item->setText(1, product_version); + item->setText(KeyColumn, "ProductVersion"); + item->setText(ValueColumn, product_version); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileFlagsMask"); - item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlagsMask", 0))); + item->setText(KeyColumn, "FileFlagsMask"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileFlagsMask", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileFlags"); - item->setText(1, RzHexString(sdb_num_get(sdb, "FileFlags", 0))); + item->setText(KeyColumn, "FileFlags"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileFlags", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileOS"); - item->setText(1, RzHexString(sdb_num_get(sdb, "FileOS", 0))); + item->setText(KeyColumn, "FileOS"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileOS", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileType"); - item->setText(1, RzHexString(sdb_num_get(sdb, "FileType", 0))); + item->setText(KeyColumn, "FileType"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileType", 0))); ui->leftTreeWidget->addTopLevelItem(item); item = new QTreeWidgetItem(); - item->setText(0, "FileSubType"); - item->setText(1, RzHexString(sdb_num_get(sdb, "FileSubType", 0))); + item->setText(KeyColumn, "FileSubType"); + item->setText(ValueColumn, RzHexString(sdb_num_get(sdb, "FileSubType", 0))); ui->leftTreeWidget->addTopLevelItem(item); // Adjust columns to content @@ -286,8 +285,10 @@ void VersionInfoDialog::fillVersionInfo() ut8 *key_utf16 = sdb_decode(sdb_const_get(sdb, "key", 0), &lenkey); ut8 *val_utf16 = sdb_decode(sdb_const_get(sdb, "value", 0), &lenval); item = new QTreeWidgetItem(); - item->setText(0, QString::fromUtf16(reinterpret_cast(key_utf16))); - item->setText(1, QString::fromUtf16(reinterpret_cast(val_utf16))); + item->setText(KeyColumn, + QString::fromUtf16(reinterpret_cast(key_utf16))); + item->setText(ValueColumn, + QString::fromUtf16(reinterpret_cast(val_utf16))); ui->rightTreeWidget->addTopLevelItem(item); free(key_utf16); free(val_utf16); diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index 8f96e7bea2..57cec36e3e 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -18,6 +18,8 @@ class VersionInfoDialog : public QDialog explicit VersionInfoDialog(QWidget *parent = nullptr); ~VersionInfoDialog(); + enum Column { KeyColumn = 0, ValueColumn = 1 }; + private slots: void CopyTreeWidgetSelection(QTreeWidget *t); From 8aec5de2690985bfd75d7328f0ac65406aa39eab Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Tue, 2 Apr 2024 21:56:02 +0530 Subject: [PATCH 5/9] clear selection upon window close --- src/dialogs/VersionInfoDialog.cpp | 43 +++++++++++++++++++++++++++++++ src/dialogs/VersionInfoDialog.h | 1 + 2 files changed, 44 insertions(+) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 6b1041edd1..aaf3674610 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -40,18 +40,28 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) selAllActionRightTreewidget->setShortcutContext( Qt::ShortcutContext::WidgetWithChildrenShortcut); + // Connect Copy actions connect(copyActionLeftTreewidget, &QAction::triggered, this, [this]() { CopyTreeWidgetSelection(ui->leftTreeWidget); }); connect(copyActionRightTreewidget, &QAction::triggered, this, [this]() { CopyTreeWidgetSelection(ui->rightTreeWidget); }); + // Connect select sll actions connect(selAllActionLeftTreewidget, &QAction::triggered, this, [this]() { ui->leftTreeWidget->selectAll(); }); connect(selAllActionRightTreewidget, &QAction::triggered, this, [this]() { ui->rightTreeWidget->selectAll(); }); + // Connect selection handles + connect(ui->leftTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, + [this]() { ui->rightTreeWidget->clearSelection(); }); + connect(ui->rightTreeWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, + [this]() { ui->leftTreeWidget->clearSelection(); }); + connect(this, &VersionInfoDialog::finished, this, &VersionInfoDialog::clearSelectionOnClose); + + // Add actions to context menu ui->leftTreeWidget->addAction(copyActionLeftTreewidget); ui->leftTreeWidget->addAction(selAllActionLeftTreewidget); @@ -61,6 +71,18 @@ VersionInfoDialog::VersionInfoDialog(QWidget *parent) VersionInfoDialog::~VersionInfoDialog() {} +void VersionInfoDialog::clearSelectionOnClose() +{ + ui->leftTreeWidget->clearSelection(); + ui->rightTreeWidget->clearSelection(); + + // remove default "current" item selection after dialog close + auto model = ui->leftTreeWidget->model(); + ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1)); + model = ui->rightTreeWidget->model(); + ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1)); +} + void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) { QString vinfo, row; @@ -79,6 +101,27 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) clipboard->setText(vinfo.trimmed()); } +/* +void VersionInfoDialog::leftTreeWidgetItemSelectionChanged() +{ + auto index = ui->leftTreeWidget->currentIndex(); + if (!ui->leftTreeWidget->selectionModel()->hasSelection() || !index.isValid()) { + return; + } + ui->leftTreeWidget->clearSelection(); +} + +void VersionInfoDialog::rightTreeWidgetItemSelectionChanged() +{ + auto index = ui->rightTreeWidget->currentIndex(); + if (!ui->rightTreeWidget->selectionModel()->hasSelection() || !index.isValid()) { + return; + } + if (ui->rightTreeWidget->selectionModel()->hasSelection()) + ui->rightTreeWidget->clearSelection(); +} +*/ + void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index 57cec36e3e..bce5631f25 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -22,6 +22,7 @@ class VersionInfoDialog : public QDialog private slots: void CopyTreeWidgetSelection(QTreeWidget *t); + void clearSelectionOnClose(); protected: QAction *copyActionLeftTreewidget = nullptr; From ece87c2df052e24b365a1dea32f83d56b5cd1eba Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Fri, 5 Apr 2024 01:14:19 +0530 Subject: [PATCH 6/9] removed comments --- .gitmodules | 1 + rizin | 2 +- src/dialogs/VersionInfoDialog.cpp | 21 --------------------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/.gitmodules b/.gitmodules index 52bebc1ce2..2325aee9ac 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "rizin"] path = rizin url = https://github.com/rizinorg/rizin + branch = dev [submodule "src/translations"] path = src/translations url = https://github.com/rizinorg/cutter-translations diff --git a/rizin b/rizin index 4a0dca6613..eeda6b1b59 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit 4a0dca66131de65ca10679e42e3adb5d39735ffa +Subproject commit eeda6b1b59da83886cafdf06100188f906500dda diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index aaf3674610..75baba211f 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -101,27 +101,6 @@ void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) clipboard->setText(vinfo.trimmed()); } -/* -void VersionInfoDialog::leftTreeWidgetItemSelectionChanged() -{ - auto index = ui->leftTreeWidget->currentIndex(); - if (!ui->leftTreeWidget->selectionModel()->hasSelection() || !index.isValid()) { - return; - } - ui->leftTreeWidget->clearSelection(); -} - -void VersionInfoDialog::rightTreeWidgetItemSelectionChanged() -{ - auto index = ui->rightTreeWidget->currentIndex(); - if (!ui->rightTreeWidget->selectionModel()->hasSelection() || !index.isValid()) { - return; - } - if (ui->rightTreeWidget->selectionModel()->hasSelection()) - ui->rightTreeWidget->clearSelection(); -} -*/ - void VersionInfoDialog::fillVersionInfo() { RzCoreLocked core(Core()); From 91f64a770eaf99959da62d52749a0ee1af4ebe23 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Fri, 12 Apr 2024 01:15:17 +0530 Subject: [PATCH 7/9] use QModelIndex instead --- src/dialogs/VersionInfoDialog.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 75baba211f..108821c0e3 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -77,10 +77,9 @@ void VersionInfoDialog::clearSelectionOnClose() ui->rightTreeWidget->clearSelection(); // remove default "current" item selection after dialog close - auto model = ui->leftTreeWidget->model(); - ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1)); - model = ui->rightTreeWidget->model(); - ui->leftTreeWidget->setCurrentIndex(model->index(-1, -1)); + QModelIndex defaultIndex; + ui->leftTreeWidget->setCurrentIndex(defaultIndex); + ui->rightTreeWidget->setCurrentIndex(defaultIndex); } void VersionInfoDialog::CopyTreeWidgetSelection(QTreeWidget *t) From 1085a913530e70055ac65353ba35f71302e500a1 Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Fri, 12 Apr 2024 01:16:16 +0530 Subject: [PATCH 8/9] Rizin update --- .gitmodules | 3 +-- cmake/BundledRizin.cmake | 7 +++--- rizin | 2 +- src/core/Cutter.cpp | 10 ++++----- src/widgets/DisassemblerGraphView.cpp | 2 +- src/widgets/ProcessesWidget.cpp | 31 ++++++++++++--------------- src/widgets/ProcessesWidget.h | 7 ++++++ src/widgets/ThreadsWidget.cpp | 24 +++++++++------------ src/widgets/ThreadsWidget.h | 6 ++++++ 9 files changed, 47 insertions(+), 45 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2325aee9ac..8dfdd99a4c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,6 @@ [submodule "rizin"] path = rizin url = https://github.com/rizinorg/rizin - branch = dev [submodule "src/translations"] path = src/translations - url = https://github.com/rizinorg/cutter-translations + url = https://github.com/rizinorg/cutter-translations \ No newline at end of file diff --git a/cmake/BundledRizin.cmake b/cmake/BundledRizin.cmake index 1d6208b9a1..3e05b26304 100644 --- a/cmake/BundledRizin.cmake +++ b/cmake/BundledRizin.cmake @@ -59,10 +59,9 @@ endif() # instead of being hardcoded. set (Rizin_VERSION 0.8) -set (RZ_LIBS rz_core rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug - rz_hash rz_bin rz_lang rz_il rz_analysis rz_parse rz_bp rz_egg rz_reg - rz_search rz_syscall rz_socket rz_magic rz_crypto rz_type rz_diff rz_sign - rz_demangler) +set (RZ_LIBS rz_core rz_config rz_cons rz_io rz_util rz_flag rz_arch rz_debug + rz_hash rz_bin rz_lang rz_il rz_bp rz_egg rz_reg rz_search rz_syscall + rz_socket rz_magic rz_crypto rz_type rz_diff rz_sign rz_demangler) set (RZ_EXTRA_LIBS rz_main) set (RZ_BIN rz-bin rizin rz-diff rz-find rz-gg rz-hash rz-run rz-asm rz-ax) diff --git a/rizin b/rizin index eeda6b1b59..3d93397dd8 160000 --- a/rizin +++ b/rizin @@ -1 +1 @@ -Subproject commit eeda6b1b59da83886cafdf06100188f906500dda +Subproject commit 3d93397dd8b96ce1e8683a21ab86d94812f0b23f diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 6951e01a02..0f646b810e 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -1295,7 +1295,7 @@ RVA CutterCore::getLastFunctionInstruction(RVA addr) if (!fcn) { return RVA_INVALID; } - RzAnalysisBlock *lastBB = (RzAnalysisBlock *)rz_list_last(fcn->bbs); + RzAnalysisBlock *lastBB = (RzAnalysisBlock *)rz_pvector_tail(fcn->bbs); return lastBB ? rz_analysis_block_get_op_addr(lastBB, lastBB->ninstr - 1) : RVA_INVALID; } @@ -1641,7 +1641,7 @@ QVector CutterCore::getHeapChunks(RVA arena_addr) rz_list_free(arenas); return chunks_vector; } - m_arena = ((RzArenaListItem *)rz_list_get_head_data(arenas))->addr; + m_arena = ((RzArenaListItem *)rz_list_first(arenas))->addr; rz_list_free(arenas); } else { m_arena = arena_addr; @@ -3061,7 +3061,7 @@ QList CutterCore::getAllFunctions() function.linearSize = rz_analysis_function_linear_size(fcn); function.nargs = rz_analysis_arg_count(fcn); function.nlocals = rz_analysis_var_local_count(fcn); - function.nbbs = rz_list_length(fcn->bbs); + function.nbbs = rz_pvector_len(fcn->bbs); function.calltype = fcn->cc ? QString::fromUtf8(fcn->cc) : QString(); function.name = fcn->name ? QString::fromUtf8(fcn->name) : QString(); function.edges = rz_analysis_function_count_edges(fcn, nullptr); @@ -4334,10 +4334,9 @@ QString CutterCore::getVersionInformation() const char *name; const char *(*callback)(); } vcs[] = { - { "rz_analysis", &rz_analysis_version }, + { "rz_arch", &rz_arch_version }, { "rz_lib", &rz_lib_version }, { "rz_egg", &rz_egg_version }, - { "rz_asm", &rz_asm_version }, { "rz_bin", &rz_bin_version }, { "rz_cons", &rz_cons_version }, { "rz_flag", &rz_flag_version }, @@ -4350,7 +4349,6 @@ QString CutterCore::getVersionInformation() #if !USE_LIB_MAGIC { "rz_magic", &rz_magic_version }, #endif - { "rz_parse", &rz_parse_version }, { "rz_reg", &rz_reg_version }, { "rz_sign", &rz_sign_version }, { "rz_search", &rz_search_version }, diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 82da086613..a220188f61 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -225,7 +225,7 @@ void DisassemblerGraphView::loadCurrentGraph() return; } - for (const auto &bbi : CutterRzList(fcn->bbs)) { + for (const auto &bbi : CutterPVector(fcn->bbs)) { RVA bbiFail = bbi->fail; RVA bbiJump = bbi->jump; diff --git a/src/widgets/ProcessesWidget.cpp b/src/widgets/ProcessesWidget.cpp index 2a9477f8f4..0a45a98e55 100644 --- a/src/widgets/ProcessesWidget.cpp +++ b/src/widgets/ProcessesWidget.cpp @@ -9,13 +9,6 @@ #define DEBUGGED_PID (-1) -enum ColumnIndex { - COLUMN_PID = 0, - COLUMN_UID, - COLUMN_STATUS, - COLUMN_PATH, -}; - ProcessesWidget::ProcessesWidget(MainWindow *main) : CutterDockWidget(main), ui(new Ui::ProcessesWidget) { @@ -23,10 +16,14 @@ ProcessesWidget::ProcessesWidget(MainWindow *main) // Setup processes model modelProcesses = new QStandardItemModel(1, 4, this); - modelProcesses->setHorizontalHeaderItem(COLUMN_PID, new QStandardItem(tr("PID"))); - modelProcesses->setHorizontalHeaderItem(COLUMN_UID, new QStandardItem(tr("UID"))); - modelProcesses->setHorizontalHeaderItem(COLUMN_STATUS, new QStandardItem(tr("Status"))); - modelProcesses->setHorizontalHeaderItem(COLUMN_PATH, new QStandardItem(tr("Path"))); + modelProcesses->setHorizontalHeaderItem(ProcessesWidget::COLUMN_PID, + new QStandardItem(tr("PID"))); + modelProcesses->setHorizontalHeaderItem(ProcessesWidget::COLUMN_UID, + new QStandardItem(tr("UID"))); + modelProcesses->setHorizontalHeaderItem(ProcessesWidget::COLUMN_STATUS, + new QStandardItem(tr("Status"))); + modelProcesses->setHorizontalHeaderItem(ProcessesWidget::COLUMN_PATH, + new QStandardItem(tr("Path"))); ui->viewProcesses->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); ui->viewProcesses->verticalHeader()->setVisible(false); ui->viewProcesses->setFont(Config()->getFont()); @@ -129,10 +126,10 @@ void ProcessesWidget::setProcessesGrid() rowStatus->setFont(font); rowPath->setFont(font); - modelProcesses->setItem(i, COLUMN_PID, rowPid); - modelProcesses->setItem(i, COLUMN_UID, rowUid); - modelProcesses->setItem(i, COLUMN_STATUS, rowStatus); - modelProcesses->setItem(i, COLUMN_PATH, rowPath); + modelProcesses->setItem(i, ProcessesWidget::COLUMN_PID, rowPid); + modelProcesses->setItem(i, ProcessesWidget::COLUMN_UID, rowUid); + modelProcesses->setItem(i, ProcessesWidget::COLUMN_STATUS, rowStatus); + modelProcesses->setItem(i, ProcessesWidget::COLUMN_PATH, rowPath); i++; } @@ -155,7 +152,7 @@ void ProcessesWidget::onActivated(const QModelIndex &index) if (!index.isValid()) return; - int pid = modelFilter->data(index.sibling(index.row(), COLUMN_PID)).toInt(); + int pid = modelFilter->data(index.sibling(index.row(), ProcessesWidget::COLUMN_PID)).toInt(); // Verify that the selected pid is still in the processes list since dp= will // attach to any given id. If it isn't found simply update the UI. for (const auto &value : Core()->getAllProcesses()) { @@ -185,7 +182,7 @@ ProcessesFilterModel::ProcessesFilterModel(QObject *parent) : QSortFilterProxyMo bool ProcessesFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const { // All columns are checked for a match - for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { + for (int i = ProcessesWidget::COLUMN_PID; i <= ProcessesWidget::COLUMN_PATH; ++i) { QModelIndex index = sourceModel()->index(row, i, parent); if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) { return true; diff --git a/src/widgets/ProcessesWidget.h b/src/widgets/ProcessesWidget.h index fcc9db8008..40f2f0f657 100644 --- a/src/widgets/ProcessesWidget.h +++ b/src/widgets/ProcessesWidget.h @@ -31,6 +31,13 @@ class ProcessesWidget : public CutterDockWidget Q_OBJECT public: + enum ColumnIndex { + COLUMN_PID = 0, + COLUMN_UID, + COLUMN_STATUS, + COLUMN_PATH, + }; + explicit ProcessesWidget(MainWindow *main); ~ProcessesWidget(); diff --git a/src/widgets/ThreadsWidget.cpp b/src/widgets/ThreadsWidget.cpp index d9149108f9..8d47412888 100644 --- a/src/widgets/ThreadsWidget.cpp +++ b/src/widgets/ThreadsWidget.cpp @@ -9,21 +9,17 @@ #define DEBUGGED_PID (-1) -enum ColumnIndex { - COLUMN_PID = 0, - COLUMN_STATUS, - COLUMN_PATH, -}; - ThreadsWidget::ThreadsWidget(MainWindow *main) : CutterDockWidget(main), ui(new Ui::ThreadsWidget) { ui->setupUi(this); // Setup threads model modelThreads = new QStandardItemModel(1, 3, this); - modelThreads->setHorizontalHeaderItem(COLUMN_PID, new QStandardItem(tr("PID"))); - modelThreads->setHorizontalHeaderItem(COLUMN_STATUS, new QStandardItem(tr("Status"))); - modelThreads->setHorizontalHeaderItem(COLUMN_PATH, new QStandardItem(tr("Path"))); + modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_PID, new QStandardItem(tr("PID"))); + modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_STATUS, + new QStandardItem(tr("Status"))); + modelThreads->setHorizontalHeaderItem(ThreadsWidget::COLUMN_PATH, + new QStandardItem(tr("Path"))); ui->viewThreads->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); ui->viewThreads->verticalHeader()->setVisible(false); ui->viewThreads->setFont(Config()->getFont()); @@ -120,9 +116,9 @@ void ThreadsWidget::setThreadsGrid() rowStatus->setFont(font); QStandardItem *rowPath = new QStandardItem(path); rowPath->setFont(font); - modelThreads->setItem(i, COLUMN_PID, rowPid); - modelThreads->setItem(i, COLUMN_STATUS, rowStatus); - modelThreads->setItem(i, COLUMN_PATH, rowPath); + modelThreads->setItem(i, ThreadsWidget::COLUMN_PID, rowPid); + modelThreads->setItem(i, ThreadsWidget::COLUMN_STATUS, rowStatus); + modelThreads->setItem(i, ThreadsWidget::COLUMN_PATH, rowPath); i++; } @@ -146,7 +142,7 @@ void ThreadsWidget::onActivated(const QModelIndex &index) if (!index.isValid()) return; - int tid = modelFilter->data(index.sibling(index.row(), COLUMN_PID)).toInt(); + int tid = modelFilter->data(index.sibling(index.row(), ThreadsWidget::COLUMN_PID)).toInt(); // Verify that the selected tid is still in the threads list since dpt= will // attach to any given id. If it isn't found simply update the UI. @@ -169,7 +165,7 @@ ThreadsFilterModel::ThreadsFilterModel(QObject *parent) : QSortFilterProxyModel( bool ThreadsFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const { // All columns are checked for a match - for (int i = COLUMN_PID; i <= COLUMN_PATH; ++i) { + for (int i = ThreadsWidget::COLUMN_PID; i <= ThreadsWidget::COLUMN_PATH; ++i) { QModelIndex index = sourceModel()->index(row, i, parent); if (qhelpers::filterStringContains(sourceModel()->data(index).toString(), this)) { return true; diff --git a/src/widgets/ThreadsWidget.h b/src/widgets/ThreadsWidget.h index 259c919de2..fd452d1e19 100644 --- a/src/widgets/ThreadsWidget.h +++ b/src/widgets/ThreadsWidget.h @@ -31,6 +31,12 @@ class ThreadsWidget : public CutterDockWidget Q_OBJECT public: + enum ColumnIndex { + COLUMN_PID = 0, + COLUMN_STATUS, + COLUMN_PATH, + }; + explicit ThreadsWidget(MainWindow *main); ~ThreadsWidget(); From 44a99ca77160df8f4ae89e243bfe808e0b10896f Mon Sep 17 00:00:00 2001 From: r3yc0n1c Date: Sun, 21 Apr 2024 22:04:37 +0530 Subject: [PATCH 9/9] fixed line feed --- .gitmodules | 2 +- src/dialogs/VersionInfoDialog.cpp | 2 +- src/dialogs/VersionInfoDialog.h | 2 +- src/dialogs/VersionInfoDialog.ui | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitmodules b/.gitmodules index 8dfdd99a4c..52bebc1ce2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,4 +3,4 @@ url = https://github.com/rizinorg/rizin [submodule "src/translations"] path = src/translations - url = https://github.com/rizinorg/cutter-translations \ No newline at end of file + url = https://github.com/rizinorg/cutter-translations diff --git a/src/dialogs/VersionInfoDialog.cpp b/src/dialogs/VersionInfoDialog.cpp index 108821c0e3..f9008b2ccf 100644 --- a/src/dialogs/VersionInfoDialog.cpp +++ b/src/dialogs/VersionInfoDialog.cpp @@ -317,4 +317,4 @@ void VersionInfoDialog::fillVersionInfo() } qhelpers::adjustColumns(ui->rightTreeWidget, 0); } -} \ No newline at end of file +} diff --git a/src/dialogs/VersionInfoDialog.h b/src/dialogs/VersionInfoDialog.h index bce5631f25..358fc23dea 100644 --- a/src/dialogs/VersionInfoDialog.h +++ b/src/dialogs/VersionInfoDialog.h @@ -37,4 +37,4 @@ private slots: void fillVersionInfo(); }; -#endif // VERSIONINFODIALOG_H \ No newline at end of file +#endif // VERSIONINFODIALOG_H diff --git a/src/dialogs/VersionInfoDialog.ui b/src/dialogs/VersionInfoDialog.ui index 59d41f3150..9ab0da67dd 100644 --- a/src/dialogs/VersionInfoDialog.ui +++ b/src/dialogs/VersionInfoDialog.ui @@ -151,4 +151,4 @@ - \ No newline at end of file +