From d05805595e7102633785a34f1bdfc0cf49160bc5 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 17 Nov 2020 02:36:12 +0100 Subject: [PATCH] Fixed copying when highlightEnd > highlightStart --- source/views/view_hexeditor.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 28ba45fb8..e98b6f4bb 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -84,10 +84,13 @@ namespace hex { } void ViewHexEditor::copyBytes() { - size_t copySize = (this->m_memoryEditor.DataPreviewAddrEnd - this->m_memoryEditor.DataPreviewAddr) + 1; + size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + + size_t copySize = (end - start) + 1; std::vector buffer(copySize, 0x00); - this->m_dataProvider->read(this->m_memoryEditor.DataPreviewAddr, buffer.data(), buffer.size()); + this->m_dataProvider->read(start, buffer.data(), buffer.size()); std::string str; for (const auto &byte : buffer) @@ -98,11 +101,14 @@ namespace hex { } void ViewHexEditor::copyString() { - size_t copySize = (this->m_memoryEditor.DataPreviewAddrEnd - this->m_memoryEditor.DataPreviewAddr) + 1; + size_t start = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + size_t end = std::max(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + + size_t copySize = (end - start) + 1; std::string buffer; buffer.reserve(copySize + 1); - this->m_dataProvider->read(this->m_memoryEditor.DataPreviewAddr, buffer.data(), copySize); + this->m_dataProvider->read(start, buffer.data(), copySize); ImGui::SetClipboardText(buffer.c_str()); }