From 8266cd074f5fc371a259466c5aff751fa5fdf188 Mon Sep 17 00:00:00 2001 From: Itay Cohen Date: Sat, 25 Jan 2020 09:18:53 +0200 Subject: [PATCH] Add realname and libname to Flags and Imports widgets (#2024) * Add realname and libname to flags and imports --- src/core/Cutter.cpp | 4 ++++ src/core/CutterDescriptions.h | 2 ++ src/widgets/FlagsWidget.cpp | 10 +++++++++- src/widgets/FlagsWidget.h | 2 +- src/widgets/ImportsWidget.cpp | 18 +++++++++++++++++- src/widgets/ImportsWidget.h | 4 +++- 6 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/core/Cutter.cpp b/src/core/Cutter.cpp index 2ef79231..ffa5b61a 100644 --- a/src/core/Cutter.cpp +++ b/src/core/Cutter.cpp @@ -66,6 +66,7 @@ namespace RJsonKey { R_JSON_KEY(license); R_JSON_KEY(methods); R_JSON_KEY(name); + R_JSON_KEY(realname); R_JSON_KEY(nargs); R_JSON_KEY(nbbs); R_JSON_KEY(nlocals); @@ -73,6 +74,7 @@ namespace RJsonKey { R_JSON_KEY(opcode); R_JSON_KEY(opcodes); R_JSON_KEY(ordinal); + R_JSON_KEY(libname); R_JSON_KEY(outdegree); R_JSON_KEY(paddr); R_JSON_KEY(path); @@ -2425,6 +2427,7 @@ QList CutterCore::getAllImports() import.ordinal = importObject[RJsonKey::ordinal].toInt(); import.bind = importObject[RJsonKey::bind].toString(); import.type = importObject[RJsonKey::type].toString(); + import.libname = importObject[RJsonKey::libname].toString(); import.name = importObject[RJsonKey::name].toString(); ret << import; @@ -2662,6 +2665,7 @@ QList CutterCore::getAllFlags(QString flagspace) flag.offset = flagObject[RJsonKey::offset].toVariant().toULongLong(); flag.size = flagObject[RJsonKey::size].toVariant().toULongLong(); flag.name = flagObject[RJsonKey::name].toString(); + flag.realname = flagObject[RJsonKey::realname].toString(); ret << flag; } diff --git a/src/core/CutterDescriptions.h b/src/core/CutterDescriptions.h index 8cb35a60..23e97621 100644 --- a/src/core/CutterDescriptions.h +++ b/src/core/CutterDescriptions.h @@ -36,6 +36,7 @@ struct ImportDescription { QString bind; QString type; QString name; + QString libname; }; struct ExportDescription { @@ -117,6 +118,7 @@ struct FlagDescription { RVA offset; RVA size; QString name; + QString realname; }; struct SectionDescription { diff --git a/src/widgets/FlagsWidget.cpp b/src/widgets/FlagsWidget.cpp index 0bb46288..2fc1e2ce 100644 --- a/src/widgets/FlagsWidget.cpp +++ b/src/widgets/FlagsWidget.cpp @@ -42,6 +42,8 @@ QVariant FlagsModel::data(const QModelIndex &index, int role) const return RAddressString(flag.offset); case NAME: return flag.name; + case REALNAME: + return flag.realname; default: return QVariant(); } @@ -63,6 +65,8 @@ QVariant FlagsModel::headerData(int section, Qt::Orientation, int role) const return tr("Offset"); case NAME: return tr("Name"); + case REALNAME: + return tr("Real Name"); default: return QVariant(); } @@ -100,7 +104,7 @@ bool FlagsSortFilterProxyModel::filterAcceptsRow(int row, const QModelIndex &par { QModelIndex index = sourceModel()->index(row, 0, parent); FlagDescription flag = index.data(FlagsModel::FlagDescriptionRole).value(); - return flag.name.contains(filterRegExp()); + return flag.name.contains(filterRegExp()) || flag.realname.contains(filterRegExp()); } bool FlagsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const @@ -120,6 +124,10 @@ bool FlagsSortFilterProxyModel::lessThan(const QModelIndex &left, const QModelIn // fallthrough case FlagsModel::NAME: return left_flag->name < right_flag->name; + + case FlagsModel::REALNAME: + return left_flag->realname < right_flag->realname; + default: break; } diff --git a/src/widgets/FlagsWidget.h b/src/widgets/FlagsWidget.h index 235933d3..c43e403f 100644 --- a/src/widgets/FlagsWidget.h +++ b/src/widgets/FlagsWidget.h @@ -26,7 +26,7 @@ private: QList *flags; public: - enum Columns { OFFSET = 0, SIZE, NAME, COUNT }; + enum Columns { OFFSET = 0, SIZE, NAME, REALNAME, COUNT }; static const int FlagDescriptionRole = Qt::UserRole; FlagsModel(QList *flags, QObject *parent = nullptr); diff --git a/src/widgets/ImportsWidget.cpp b/src/widgets/ImportsWidget.cpp index c499fc1d..f666e928 100644 --- a/src/widgets/ImportsWidget.cpp +++ b/src/widgets/ImportsWidget.cpp @@ -46,6 +46,8 @@ QVariant ImportsModel::data(const QModelIndex &index, int role) const return import.type; case ImportsModel::SafetyColumn: return banned.match(import.name).hasMatch() ? tr("Unsafe") : QStringLiteral(""); + case ImportsModel::LibraryColumn: + return import.libname; case ImportsModel::NameColumn: return import.name; default: @@ -72,6 +74,8 @@ QVariant ImportsModel::headerData(int section, Qt::Orientation, int role) const return tr("Type"); case ImportsModel::SafetyColumn: return tr("Safety"); + case ImportsModel::LibraryColumn: + return tr("Library"); case ImportsModel::NameColumn: return tr("Name"); default: @@ -93,6 +97,12 @@ QString ImportsModel::name(const QModelIndex &index) const return import.name; } +QString ImportsModel::libname(const QModelIndex &index) const +{ + const ImportDescription &import = imports->at(index.row()); + return import.libname; +} + ImportsProxyModel::ImportsProxyModel(ImportsModel *sourceModel, QObject *parent) : AddressableFilterProxyModel(sourceModel, parent) { @@ -126,8 +136,13 @@ bool ImportsProxyModel::lessThan(const QModelIndex &left, const QModelIndex &rig return leftImport.type < rightImport.type; case ImportsModel::SafetyColumn: break; + case ImportsModel::LibraryColumn: + if (leftImport.libname != rightImport.libname) + return leftImport.libname < rightImport.libname; + // Fallthrough. Sort by Library and then by import name case ImportsModel::NameColumn: return leftImport.name < rightImport.name; + default: break; } @@ -148,7 +163,8 @@ ImportsWidget::ImportsWidget(MainWindow *main, QAction *action) : setObjectName("ImportsWidget"); setModels(importsProxyModel); - ui->treeView->sortByColumn(ImportsModel::NameColumn, Qt::AscendingOrder); + // Sort by library name by default to create a solid context per each group of imports + ui->treeView->sortByColumn(ImportsModel::LibraryColumn, Qt::AscendingOrder); QShortcut *toggle_shortcut = new QShortcut(widgetShortcuts["ImportsWidget"], main); connect(toggle_shortcut, &QShortcut::activated, this, [=] (){ toggleDockWidget(true); diff --git a/src/widgets/ImportsWidget.h b/src/widgets/ImportsWidget.h index add0ff42..7cb92327 100644 --- a/src/widgets/ImportsWidget.h +++ b/src/widgets/ImportsWidget.h @@ -43,7 +43,7 @@ private: QList *imports; public: - enum Column { AddressColumn = 0, TypeColumn, SafetyColumn, NameColumn, ColumnCount }; + enum Column { AddressColumn = 0, TypeColumn, LibraryColumn, NameColumn, SafetyColumn, ColumnCount }; enum Role { ImportDescriptionRole = Qt::UserRole, AddressRole }; ImportsModel(QList *imports, QObject *parent = nullptr); @@ -56,6 +56,8 @@ public: RVA address(const QModelIndex &index) const override; QString name(const QModelIndex &index) const override; + QString libname(const QModelIndex &index) const; + }; class ImportsProxyModel : public AddressableFilterProxyModel