Skip to content

Commit

Permalink
Fixed copying when highlightEnd > highlightStart
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Nov 17, 2020
1 parent 975c3a9 commit d058055
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions source/views/view_hexeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> 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)
Expand All @@ -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());
}
Expand Down

0 comments on commit d058055

Please sign in to comment.