diff --git a/include/views/view_hexeditor.hpp b/include/views/view_hexeditor.hpp index f8f8e6b2f..a7d49e2ac 100644 --- a/include/views/view_hexeditor.hpp +++ b/include/views/view_hexeditor.hpp @@ -37,8 +37,8 @@ namespace hex { std::map m_highlightedBytes; - char m_searchStringBuffer[0xFFFF] = { 0 }; - char m_searchHexBuffer[0xFFFF] = { 0 }; + std::vector m_searchStringBuffer; + std::vector m_searchHexBuffer; SearchFunction m_searchFunction = nullptr; std::vector> *m_lastSearchBuffer; diff --git a/include/views/view_strings.hpp b/include/views/view_strings.hpp index 25e6fe524..851c6f3fb 100644 --- a/include/views/view_strings.hpp +++ b/include/views/view_strings.hpp @@ -28,7 +28,7 @@ namespace hex { std::vector m_foundStrings; int m_minimumLength = 5; - char *m_filter; + std::vector m_filter; std::string m_selectedString; std::string m_demangledName; diff --git a/plugins/libimhex/source/helpers/utils.cpp b/plugins/libimhex/source/helpers/utils.cpp index a64031fee..e26a0c3e8 100644 --- a/plugins/libimhex/source/helpers/utils.cpp +++ b/plugins/libimhex/source/helpers/utils.cpp @@ -122,21 +122,21 @@ namespace hex { } std::string toEngineeringString(double value) { - constexpr std::array prefixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" }; + constexpr std::array Suffixes = { "a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P", "E" }; - int8_t prefixIndex = 6; + int8_t suffixIndex = 6; - while (prefixIndex != 0 && prefixIndex != 12 && (value >= 1000 || value < 1) && value != 0) { + while (suffixIndex != 0 && suffixIndex != 12 && (value >= 1000 || value < 1) && value != 0) { if (value >= 1000) { value /= 1000; - prefixIndex++; + suffixIndex++; } else if (value < 1) { value *= 1000; - prefixIndex--; + suffixIndex--; } } - return std::to_string(value).substr(0, 5) + prefixes[prefixIndex]; + return std::to_string(value).substr(0, 5) + Suffixes[suffixIndex]; } std::vector readFile(std::string_view path) { diff --git a/plugins/libimhex/source/views/view.cpp b/plugins/libimhex/source/views/view.cpp index 39a7a808a..82f82edbc 100644 --- a/plugins/libimhex/source/views/view.cpp +++ b/plugins/libimhex/source/views/view.cpp @@ -40,7 +40,6 @@ namespace hex { } void View::drawCommonInterfaces() { - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 10)); if (ImGui::BeginPopupModal("Error", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) { ImGui::Text("%s", SharedData::errorPopupMessage.c_str()); ImGui::NewLine(); @@ -50,7 +49,6 @@ namespace hex { ImGui::EndPopup(); } - ImGui::PopStyleVar(); if (SharedData::fileBrowser.showFileDialog(SharedData::fileBrowserTitle, SharedData::fileBrowserDialogMode, ImVec2(0, 0), SharedData::fileBrowserValidExtensions)) { SharedData::fileBrowserCallback(SharedData::fileBrowser.selected_path); @@ -61,7 +59,7 @@ namespace hex { void View::showErrorPopup(std::string_view errorMessage) { SharedData::errorPopupMessage = errorMessage; - ImGui::OpenPopup("Error"); + View::doLater([] { ImGui::OpenPopup("Error"); }); } bool View::hasViewMenuItemEntry() { diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 58aa530e9..483f05e23 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -19,6 +19,9 @@ namespace hex { ViewHexEditor::ViewHexEditor(std::vector &patternData) : View("hex.view.hexeditor.title"_lang), m_patternData(patternData) { + this->m_searchStringBuffer.resize(0xFFF, 0x00); + this->m_searchHexBuffer.resize(0xFFF, 0x00); + this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 { auto provider = SharedData::currentProvider; if (!provider->isAvailable() || !provider->isReadable()) @@ -952,13 +955,13 @@ R"( if (ImGui::BeginPopupContextVoid("hex.view.hexeditor.menu.file.search"_lang)) { ImGui::TextUnformatted("hex.view.hexeditor.menu.file.search"_lang); if (ImGui::BeginTabBar("searchTabs")) { - char *currBuffer; + std::vector *currBuffer = nullptr; if (ImGui::BeginTabItem("hex.view.hexeditor.search.string"_lang)) { this->m_searchFunction = findString; this->m_lastSearchBuffer = &this->m_lastStringSearch; - currBuffer = this->m_searchStringBuffer; + currBuffer = &this->m_searchStringBuffer; - ImGui::InputText("##nolabel", currBuffer, 0xFFFF, ImGuiInputTextFlags_CallbackCompletion, + ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(), ImGuiInputTextFlags_CallbackCompletion, InputCallback, this); ImGui::EndTabItem(); } @@ -966,25 +969,27 @@ R"( if (ImGui::BeginTabItem("hex.view.hexeditor.search.hex"_lang)) { this->m_searchFunction = findHex; this->m_lastSearchBuffer = &this->m_lastHexSearch; - currBuffer = this->m_searchHexBuffer; + currBuffer = &this->m_searchHexBuffer; - ImGui::InputText("##nolabel", currBuffer, 0xFFFF, + ImGui::InputText("##nolabel", currBuffer->data(), currBuffer->size(), ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CallbackCompletion, InputCallback, this); ImGui::EndTabItem(); } - if (ImGui::Button("hex.view.hexeditor.search.find"_lang)) - Find(currBuffer); + if (currBuffer != nullptr) { + if (ImGui::Button("hex.view.hexeditor.search.find"_lang)) + Find(currBuffer->data()); - if (this->m_lastSearchBuffer->size() > 0) { - if ((ImGui::Button("hex.view.hexeditor.search.find_next"_lang))) - FindNext(); + if (this->m_lastSearchBuffer->size() > 0) { + if ((ImGui::Button("hex.view.hexeditor.search.find_next"_lang))) + FindNext(); - ImGui::SameLine(); + ImGui::SameLine(); - if ((ImGui::Button("hex.view.hexeditor.search.find_prev"_lang))) - FindPrevious(); + if ((ImGui::Button("hex.view.hexeditor.search.find_prev"_lang))) + FindPrevious(); + } } ImGui::EndTabBar(); diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index 5ac226ed4..3a80cdff3 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -16,13 +16,11 @@ namespace hex { this->m_foundStrings.clear(); }); - this->m_filter = new char[0xFFFF]; - std::memset(this->m_filter, 0x00, 0xFFFF); + this->m_filter.resize(0xFFFF, 0x00); } ViewStrings::~ViewStrings() { View::unsubscribeEvent(Events::DataChanged); - delete[] this->m_filter; } @@ -89,7 +87,7 @@ namespace hex { if (ImGui::InputInt("hex.view.strings.min_length"_lang, &this->m_minimumLength, 1, 0)) this->m_shouldInvalidate = true; - ImGui::InputText("hex.view.strings.filter"_lang, this->m_filter, 0xFFFF); + ImGui::InputText("hex.view.strings.filter"_lang, this->m_filter.data(), this->m_filter.size()); if (ImGui::Button("hex.view.strings.extract"_lang)) this->m_shouldInvalidate = true; @@ -109,17 +107,17 @@ namespace hex { if (sortSpecs->SpecsDirty) { std::sort(this->m_foundStrings.begin(), this->m_foundStrings.end(), [&sortSpecs](FoundString &left, FoundString &right) -> bool { - if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.offset"_lang)) { + if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("offset")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left.offset > right.offset; else return left.offset < right.offset; - } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.size"_lang)) { + } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("size")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left.size > right.size; else return left.size < right.size; - } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("hex.view.strings.string"_lang)) { + } else if (sortSpecs->Specs->ColumnUserID == ImGui::GetID("string")) { if (sortSpecs->Specs->SortDirection == ImGuiSortDirection_Ascending) return left.string > right.string; else @@ -141,8 +139,8 @@ namespace hex { for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { auto &foundString = this->m_foundStrings[i]; - if (strlen(this->m_filter) != 0 && - foundString.string.find(this->m_filter) == std::string::npos) + if (strlen(this->m_filter.data()) != 0 && + foundString.string.find(this->m_filter.data()) == std::string::npos) continue; ImGui::TableNextRow(); @@ -172,7 +170,7 @@ namespace hex { if (ImGui::BeginPopup("hex.view.strings.demangle.title"_lang)) { if (ImGui::BeginChild("##scrolling", ImVec2(500, 150))) { - ImGui::Text("hex.view.strings.demangle.title"_lang); + ImGui::TextUnformatted("hex.view.strings.demangle.title"_lang); ImGui::Separator(); ImGui::TextWrapped("%s", this->m_demangledName.c_str()); ImGui::EndChild();