From cf8f1f8cd9ed156297afc808a3628aa356d2790d Mon Sep 17 00:00:00 2001 From: G3ph4z <26697727+G3ph4z@users.noreply.github.com> Date: Fri, 23 Aug 2024 00:21:19 +0200 Subject: [PATCH] Add option to copy selection bytes only --- src/gui/Src/Gui/CPUDisassembly.cpp | 28 ++++++++++++++++++++++++++++ src/gui/Src/Gui/CPUDisassembly.h | 1 + 2 files changed, 29 insertions(+) diff --git a/src/gui/Src/Gui/CPUDisassembly.cpp b/src/gui/Src/Gui/CPUDisassembly.cpp index 739d0d89..a4802572 100644 --- a/src/gui/Src/Gui/CPUDisassembly.cpp +++ b/src/gui/Src/Gui/CPUDisassembly.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "CPUDisassembly.h" #include "main.h" #include "CPUSideBar.h" @@ -295,6 +296,7 @@ void CPUDisassembly::setupRightClickContextMenu() MenuBuilder* copyMenu = new MenuBuilder(this); copyMenu->addAction(makeShortcutAction(DIcon("copy_selection"), tr("&Selection"), SLOT(copySelectionSlot()), "ActionCopy")); copyMenu->addAction(makeAction(DIcon("copy_selection"), tr("Selection to &File"), SLOT(copySelectionToFileSlot()))); + copyMenu->addAction(makeAction(DIcon("copy_selection"), tr("Selection (Bytes only)"), SLOT(copySelectionBytesSlot()))); copyMenu->addAction(makeAction(DIcon("copy_selection_no_bytes"), tr("Selection (&No Bytes)"), SLOT(copySelectionNoBytesSlot()))); copyMenu->addAction(makeAction(DIcon("copy_selection_no_bytes"), tr("Selection to File (No Bytes)"), SLOT(copySelectionToFileNoBytesSlot()))); copyMenu->addAction(makeShortcutAction(DIcon("copy_address"), tr("&Address"), SLOT(copyAddressSlot()), "ActionCopyAddress")); @@ -1520,6 +1522,32 @@ void CPUDisassembly::copySelectionToFileSlot(bool copyBytes) } } +void CPUDisassembly::copySelectionBytesSlot() +{ + QStringList lines; + + prepareDataRange(getSelectionStart(), getSelectionEnd(), [&](int i, const Instruction_t & inst) + { + QByteArray bytes = inst.dump.toHex().toUpper(); + QString hexString; + hexString.reserve(bytes.size() + bytes.size() / 2); + + for(int j = 0; j < bytes.size(); j += 2) + { + if(j > 0) + { + hexString.append(' '); + } + hexString.append(bytes.mid(j, 2)); + } + + lines.append(hexString); + return true; + }); + + Bridge::CopyToClipboard(lines.join("\r\n")); +} + void CPUDisassembly::setSideBar(CPUSideBar* sideBar) { mSideBar = sideBar; diff --git a/src/gui/Src/Gui/CPUDisassembly.h b/src/gui/Src/Gui/CPUDisassembly.h index b7a4e122..424fd365 100644 --- a/src/gui/Src/Gui/CPUDisassembly.h +++ b/src/gui/Src/Gui/CPUDisassembly.h @@ -77,6 +77,7 @@ public slots: void copySelectionToFileSlot(); void copySelectionNoBytesSlot(); void copySelectionToFileNoBytesSlot(); + void copySelectionBytesSlot(); void copyAddressSlot(); void copyRvaSlot(); void copyFileOffsetSlot();