From 1e1c93d9d1c2b2bdf8ad5f633f78143d50cad252 Mon Sep 17 00:00:00 2001 From: frmdstryr Date: Tue, 5 Sep 2023 20:51:32 -0400 Subject: [PATCH] Add 'Copy instruction bytes' to disassembly context menu (#3242) --- src/menus/DisassemblyContextMenu.cpp | 16 ++++++++++++++++ src/menus/DisassemblyContextMenu.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index b2cb760d..9879a16e 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -31,6 +31,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main actionEditBytes(this), actionCopy(this), actionCopyAddr(this), + actionCopyInstrBytes(this), actionAddComment(this), actionAnalyzeFunction(this), actionEditFunction(this), @@ -76,6 +77,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *main getCopyAddressSequence()); addAction(&actionCopyAddr); + initAction(&actionCopyInstrBytes, tr("Copy instruction bytes"), + SLOT(on_actionCopyInstrBytes_triggered()), getCopyInstrBytesSequence()); + addAction(&actionCopyInstrBytes); + initAction(&showInSubmenu, tr("Show in"), nullptr); addAction(&showInSubmenu); @@ -643,6 +648,11 @@ QKeySequence DisassemblyContextMenu::getCopyAddressSequence() const return { Qt::CTRL | Qt::SHIFT | Qt::Key_C }; } +QKeySequence DisassemblyContextMenu::getCopyInstrBytesSequence() const +{ + return { Qt::CTRL | Qt::ALT | Qt::Key_C }; +} + QKeySequence DisassemblyContextMenu::getSetToCodeSequence() const { return { Qt::Key_C }; @@ -793,6 +803,12 @@ void DisassemblyContextMenu::on_actionCopyAddr_triggered() clipboard->setText(RzAddressString(offset)); } +void DisassemblyContextMenu::on_actionCopyInstrBytes_triggered() +{ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(Core()->getInstructionBytes(offset)); +} + void DisassemblyContextMenu::on_actionAddBreakpoint_triggered() { Core()->toggleBreakpoint(offset); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index e6c0773d..0cf91556 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -42,6 +42,7 @@ private slots: void on_actionCopy_triggered(); void on_actionCopyAddr_triggered(); + void on_actionCopyInstrBytes_triggered(); void on_actionAddComment_triggered(); void on_actionAnalyzeFunction_triggered(); void on_actionRename_triggered(); @@ -79,6 +80,7 @@ private: QKeySequence getCopySequence() const; QKeySequence getCommentSequence() const; QKeySequence getCopyAddressSequence() const; + QKeySequence getCopyInstrBytesSequence() const; QKeySequence getGlobalVarSequence() const; QKeySequence getSetToCodeSequence() const; QKeySequence getSetAsStringSequence() const; @@ -111,6 +113,7 @@ private: QAction actionCopy; QAction *copySeparator; QAction actionCopyAddr; + QAction actionCopyInstrBytes; QAction actionAddComment; QAction actionAnalyzeFunction;