From f748b75a19ec2d9a6dbf8d4545215bc3ba5e0904 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 19 Nov 2020 23:24:34 +0100 Subject: [PATCH] Added begin, current and end goto offset modes --- include/views/view_hexeditor.hpp | 2 +- source/views/view_hexeditor.cpp | 54 +++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/include/views/view_hexeditor.hpp b/include/views/view_hexeditor.hpp index fac5466dd..e31dc1ecb 100644 --- a/include/views/view_hexeditor.hpp +++ b/include/views/view_hexeditor.hpp @@ -43,7 +43,7 @@ namespace hex { std::vector> m_lastStringSearch; std::vector> m_lastHexSearch; - u64 m_gotoAddress = 0; + s64 m_gotoAddress = 0; void drawSearchPopup(); diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index a4af614f2..0beae6dd2 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -339,13 +339,57 @@ namespace hex { void ViewHexEditor::drawGotoPopup() { if (ImGui::BeginPopup("Goto")) { ImGui::TextUnformatted("Goto"); - ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal); + if (ImGui::BeginTabBar("gotoTabs")) { + s64 newOffset = 0; + if (ImGui::BeginTabItem("Begin")) { + ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal); - if (this->m_gotoAddress >= this->m_dataProvider->getSize()) - this->m_gotoAddress = this->m_dataProvider->getSize() - 1; + if (this->m_gotoAddress >= this->m_dataProvider->getSize()) + this->m_gotoAddress = this->m_dataProvider->getSize() - 1; - if (ImGui::Button("Goto")) { - this->m_memoryEditor.GotoAddr = this->m_gotoAddress; + newOffset = this->m_gotoAddress; + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("Current")) { + ImGui::InputScalar("##nolabel", ImGuiDataType_S64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal); + + if (this->m_memoryEditor.DataPreviewAddr == -1 || this->m_memoryEditor.DataPreviewAddrEnd == -1) { + this->m_memoryEditor.DataPreviewAddr = 0; + this->m_memoryEditor.DataPreviewAddrEnd = 0; + } + + s64 currHighlightStart = std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); + + newOffset = this->m_gotoAddress + currHighlightStart; + if (newOffset >= this->m_dataProvider->getSize()) { + newOffset = this->m_dataProvider->getSize() - 1; + this->m_gotoAddress = (this->m_dataProvider->getSize() - 1) - currHighlightStart; + } else if (newOffset < 0) { + newOffset = 0; + this->m_gotoAddress = -currHighlightStart; + } + + ImGui::EndTabItem(); + } + if (ImGui::BeginTabItem("End")) { + ImGui::InputScalar("##nolabel", ImGuiDataType_U64, &this->m_gotoAddress, nullptr, nullptr, "%llx", ImGuiInputTextFlags_CharsHexadecimal); + + if (this->m_gotoAddress >= this->m_dataProvider->getSize()) + this->m_gotoAddress = this->m_dataProvider->getSize() - 1; + + newOffset = (this->m_dataProvider->getSize() - 1) - this->m_gotoAddress; + + ImGui::EndTabItem(); + } + + if (ImGui::Button("Goto")) { + this->m_memoryEditor.GotoAddr = newOffset; + this->m_memoryEditor.DataPreviewAddr = newOffset; + this->m_memoryEditor.DataPreviewAddrEnd = newOffset; + } + + ImGui::EndTabBar(); } ImGui::EndPopup();