Skip to content

Commit

Permalink
feat: Added right click option to copy pointer address from a watch e…
Browse files Browse the repository at this point in the history
…ntry

Added an option (copy address) to the right click menu of a MemWatchWidget. Selecting Copy address on a pointer watch can copy the address at any pointer level to the clipboard. Selecting Copy address on a non-pointer watch will copy the base address of the watch to the clipboard.

ref: #160
  • Loading branch information
jahorta committed Jul 7, 2024
1 parent 17ed8bf commit edcf1d5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,43 @@ void MemWatchWidget::onMemWatchContextMenuRequested(const QPoint& pos)
connect(copy, &QAction::triggered, this, [this] { copySelectedWatchesToClipBoard(); });
contextMenu->addAction(copy);

if (index != QModelIndex())
{
MemWatchEntry* entry = m_watchModel->getEntryFromIndex(index);
if (entry->isBoundToPointer())
{
QMenu* copyAddrSubmenu = contextMenu->addMenu(tr("Copy add&ress..."));
QAction* copyPointer = new QAction(tr("Copy &base address..."), this);
connect(copyPointer, &QAction::triggered, this,
[=] { copyAddressToClipboard(entry->getConsoleAddress()); });
copyAddrSubmenu->addAction(copyPointer);
for (int i = 0; i < entry->getPointerLevel(); ++i)
{
std::string strAddressOfPath = entry->getAddressStringForPointerLevel(i + 1);
if (strAddressOfPath == "???")
break;
QAction* showAddressOfPathInViewer = new QAction(
tr("Copy pointed address at &level %1...").arg(QString::number(i + 1)), this);
connect(showAddressOfPathInViewer, &QAction::triggered, this,
[=] { copyAddressToClipboard(entry->getAddressForPointerLevel(i + 1)); });
copyAddrSubmenu->addAction(showAddressOfPathInViewer);
}
}
else
{
QAction* copyPointer = new QAction(tr("Copy add&ress"), this);
connect(copyPointer, &QAction::triggered, this,
[=] { copyAddressToClipboard(entry->getConsoleAddress()); });
contextMenu->addAction(copyPointer);

QModelIndexList selection = m_watchView->selectionModel()->selectedRows();
if (selection.count() == 0)
{
copyPointer->setEnabled(false);
}
}
}

QAction* paste = new QAction(tr("&Paste"), this);
connect(paste, &QAction::triggered, this, [this, index] { pasteWatchFromClipBoard(index); });
contextMenu->addAction(paste);
Expand Down Expand Up @@ -393,6 +430,14 @@ void MemWatchWidget::pasteWatchFromClipBoard(const QModelIndex& referenceIndex)
m_hasUnsavedChanges = true;
}

void MemWatchWidget::copyAddressToClipboard(u32 addr)
{
char hex_string[10];
sprintf_s(hex_string, "%X", addr);
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(hex_string);
}

void MemWatchWidget::onWatchDoubleClicked(const QModelIndex& index)
{
if (index != QVariant())
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/MemWatcher/MemWatchWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MemWatchWidget : public QWidget
void copySelectedWatchesToClipBoard();
void cutSelectedWatchesToClipBoard();
void pasteWatchFromClipBoard(const QModelIndex& referenceIndex);
void copyAddressToClipboard(u32 addr);
bool saveWatchFile();
bool saveAsWatchFile();
void clearWatchList();
Expand Down

0 comments on commit edcf1d5

Please sign in to comment.