Merge pull request #3425 from G3ph4z/issue_3409

Add option to copy selection bytes only
This commit is contained in:
Duncan Ogilvie 2024-08-30 14:56:11 +02:00 committed by GitHub
commit 7dd1cd34f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include <QFile>
#include <QDesktopServices>
#include <QClipboard>
#include <QStringList>
#include "CPUDisassembly.h"
#include "main.h"
#include "CPUSideBar.h"
@ -292,6 +293,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"));
@ -1517,6 +1519,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;

View File

@ -77,6 +77,7 @@ public slots:
void copySelectionToFileSlot();
void copySelectionNoBytesSlot();
void copySelectionToFileNoBytesSlot();
void copySelectionBytesSlot();
void copyAddressSlot();
void copyRvaSlot();
void copyFileOffsetSlot();