forked from radareorg/radare2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common behaviour for lists with items that have address (radareorg#1700)
- Loading branch information
Showing
37 changed files
with
906 additions
and
1,290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "AddressableItemModel.h" | ||
|
||
AddressableFilterProxyModel::AddressableFilterProxyModel(AddressableItemModelI *sourceModel, | ||
QObject *parent) : | ||
AddressableItemModel<QSortFilterProxyModel>(parent) | ||
{ | ||
setSourceModel(sourceModel); | ||
addressableSourceModel = sourceModel; | ||
} | ||
|
||
RVA AddressableFilterProxyModel::address(const QModelIndex &index) const | ||
{ | ||
return addressableSourceModel->address(this->mapToSource(index)); | ||
} | ||
|
||
QString AddressableFilterProxyModel::name(const QModelIndex &index) const | ||
{ | ||
return addressableSourceModel->name(this->mapToSource(index)); | ||
} | ||
|
||
void AddressableFilterProxyModel::setSourceModel(QAbstractItemModel *) | ||
{ | ||
throw new std::runtime_error("Not supported"); | ||
} | ||
|
||
void AddressableFilterProxyModel::setSourceModel(AddressableItemModelI *sourceModel) | ||
{ | ||
ParentClass::setSourceModel(sourceModel->asItemModel()); | ||
addressableSourceModel = sourceModel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#ifndef ADDRESSABLEITEMMODEL_H | ||
#define ADDRESSABLEITEMMODEL_H | ||
|
||
#include <QAbstractItemModel> | ||
#include <QSortFilterProxyModel> | ||
#include <QAbstractItemModel> | ||
|
||
#include <core/CutterCommon.h> | ||
|
||
class AddressableItemModelI | ||
{ | ||
public: | ||
virtual RVA address(const QModelIndex &index) const = 0; | ||
/** | ||
* @brief Get name for item, optional. | ||
* @param index item intex | ||
* @return Item name or empty QString if item doesn't have short descriptive name. | ||
*/ | ||
virtual QString name(const QModelIndex &index) const { Q_UNUSED(index) return QString(); } | ||
virtual QAbstractItemModel *asItemModel() = 0; | ||
}; | ||
|
||
template <class ParentModel = QAbstractItemModel> | ||
class AddressableItemModel : public ParentModel, public AddressableItemModelI | ||
{ | ||
static_assert (std::is_base_of<QAbstractItemModel, ParentModel>::value, | ||
"ParentModel needs to inherit from QAbstractItemModel"); | ||
public: | ||
explicit AddressableItemModel(QObject *parent = nullptr) : ParentModel(parent) {} | ||
virtual ~AddressableItemModel() {} | ||
QAbstractItemModel *asItemModel() { return this; } | ||
}; | ||
|
||
class AddressableFilterProxyModel : public AddressableItemModel<QSortFilterProxyModel> | ||
{ | ||
using ParentClass = AddressableItemModel<QSortFilterProxyModel>; | ||
public: | ||
AddressableFilterProxyModel(AddressableItemModelI *sourceModel, QObject *parent); | ||
|
||
RVA address(const QModelIndex &index) const override; | ||
QString name(const QModelIndex &) const override; | ||
void setSourceModel(AddressableItemModelI *sourceModel); | ||
private: | ||
void setSourceModel(QAbstractItemModel *sourceModel) override; // Don't use this directly | ||
AddressableItemModelI *addressableSourceModel; | ||
}; | ||
|
||
#endif // ADDRESSABLEITEMMODEL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include "AddressableItemContextMenu.h" | ||
#include "dialogs/XrefsDialog.h" | ||
#include "MainWindow.h" | ||
#include "dialogs/CommentsDialog.h" | ||
|
||
#include <QtCore> | ||
#include <QShortcut> | ||
#include <QJsonArray> | ||
#include <QClipboard> | ||
#include <QApplication> | ||
#include <QPushButton> | ||
|
||
AddressableItemContextMenu::AddressableItemContextMenu(QWidget *parent, MainWindow *mainWindow) | ||
: QMenu(parent) | ||
, mainWindow(mainWindow) | ||
, actionShowInMenu(tr("Show in"), this) | ||
, actionCopyAddress(tr("Copy address"), this) | ||
, actionShowXrefs(tr("Show X-Refs"), this) | ||
, actionAddcomment(tr("Add comment"), this) | ||
{ | ||
connect(&actionCopyAddress, &QAction::triggered, this, | ||
&AddressableItemContextMenu::onActionCopyAddress); | ||
actionCopyAddress.setShortcuts({Qt::CTRL + Qt::SHIFT + Qt::Key_C}); | ||
actionCopyAddress.setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); | ||
|
||
connect(&actionShowXrefs, &QAction::triggered, this, | ||
&AddressableItemContextMenu::onActionShowXrefs); | ||
actionShowXrefs.setShortcut({Qt::Key_X}); | ||
actionShowXrefs.setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut); | ||
|
||
connect(&actionAddcomment, &QAction::triggered, this, | ||
&AddressableItemContextMenu::onActionAddComment); | ||
|
||
|
||
addAction(&actionShowInMenu); | ||
addAction(&actionCopyAddress); | ||
addAction(&actionShowXrefs); | ||
addSeparator(); | ||
addAction(&actionAddcomment); | ||
|
||
connect(this, &QMenu::aboutToShow, this, &AddressableItemContextMenu::aboutToShowSlot); | ||
} | ||
|
||
AddressableItemContextMenu::~AddressableItemContextMenu() | ||
{ | ||
} | ||
|
||
void AddressableItemContextMenu::setWholeFunction(bool wholeFunciton) | ||
{ | ||
this->wholeFunction = wholeFunciton; | ||
} | ||
|
||
void AddressableItemContextMenu::setOffset(RVA offset) | ||
{ | ||
setTarget(offset); | ||
} | ||
|
||
void AddressableItemContextMenu::setTarget(RVA offset, QString name) | ||
{ | ||
this->offset = offset; | ||
this->name = name; | ||
} | ||
|
||
void AddressableItemContextMenu::onActionCopyAddress() | ||
{ | ||
auto clipboard = QApplication::clipboard(); | ||
clipboard->setText(RAddressString(offset)); | ||
} | ||
|
||
void AddressableItemContextMenu::onActionShowXrefs() | ||
{ | ||
XrefsDialog dialog(nullptr); | ||
QString tmpName = name; | ||
if (name.isEmpty()) { | ||
name = RAddressString(offset); | ||
} | ||
dialog.fillRefsForAddress(offset, name, wholeFunction); | ||
dialog.exec(); | ||
} | ||
|
||
void AddressableItemContextMenu::onActionAddComment() | ||
{ | ||
// Create dialog | ||
CommentsDialog c(this); | ||
|
||
if (c.exec()) { | ||
// Get new function name | ||
QString comment = c.getComment(); | ||
// Rename function in r2 core | ||
Core()->setComment(offset, comment); | ||
// Seek to new renamed function | ||
Core()->seekAndShow(offset); | ||
} | ||
} | ||
|
||
void AddressableItemContextMenu::aboutToShowSlot() | ||
{ | ||
if (actionShowInMenu.menu()) { | ||
actionShowInMenu.menu()->deleteLater(); | ||
} | ||
actionShowInMenu.setMenu(mainWindow->createShowInMenu(this, offset)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef ADDRESSABLEITEMCONTEXTMENU_H | ||
#define ADDRESSABLEITEMCONTEXTMENU_H | ||
|
||
#include "core/Cutter.h" | ||
#include <QMenu> | ||
#include <QKeySequence> | ||
|
||
class AddressableItemContextMenu : public QMenu | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
AddressableItemContextMenu(QWidget *parent, MainWindow *mainWindow); | ||
~AddressableItemContextMenu(); | ||
|
||
/** | ||
* @brief Configure if addressable item refers to whole function or specific address | ||
* @param wholeFunciton | ||
*/ | ||
void setWholeFunction(bool wholeFunciton); | ||
public slots: | ||
void setOffset(RVA offset); | ||
void setTarget(RVA offset, QString name = QString()); | ||
private: | ||
void onActionCopyAddress(); | ||
void onActionShowXrefs(); | ||
void onActionAddComment(); | ||
|
||
virtual void aboutToShowSlot(); | ||
|
||
MainWindow *mainWindow; | ||
|
||
RVA offset; | ||
protected: | ||
QAction actionShowInMenu; | ||
QAction actionCopyAddress; | ||
QAction actionShowXrefs; | ||
QAction actionAddcomment; | ||
|
||
QString name; | ||
bool wholeFunction = false; | ||
}; | ||
#endif // ADDRESSABLEITEMCONTEXTMENU_H |
Oops, something went wrong.