From f17d6c2359010c3608ea866c9ba5f635b0c525c3 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 24 Nov 2020 02:59:49 +0100 Subject: [PATCH] Added copy string and copy demangled string to strings window --- include/utils.hpp | 20 ++++++++++++++++++++ include/views/view_tools.hpp | 2 +- source/views/view_hexeditor.cpp | 2 ++ source/views/view_strings.cpp | 19 +++++++++++++++++++ source/views/view_tools.cpp | 19 +++---------------- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/include/utils.hpp b/include/utils.hpp index c36d8f961..246db0e7e 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -11,6 +11,8 @@ #ifdef __MINGW32__ #include +#include + #else #include #endif @@ -163,6 +165,24 @@ namespace hex { } } + inline std::string demangleItaniumSymbol(const std::string &mangledSymbol) { + size_t length = 0; + int status = 0; + char *demangledSymbol = abi::__cxa_demangle(mangledSymbol.c_str(), nullptr, &length, &status); + + if (demangledSymbol == nullptr) + return "< ??? >"; + + std::string result = demangledSymbol; + + free(demangledSymbol); + + if (status != 0) + result = "< ??? >"; + + return result; + } + class ScopeExit { public: diff --git a/include/views/view_tools.hpp b/include/views/view_tools.hpp index e5e133a89..22f888ad4 100644 --- a/include/views/view_tools.hpp +++ b/include/views/view_tools.hpp @@ -22,7 +22,7 @@ namespace hex { private: char *m_mangledBuffer = nullptr; - char *m_demangledName = nullptr; + std::string m_demangledName; bool m_asciiTableShowOctal = false; diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 368c963c1..7af311f9c 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -116,6 +116,8 @@ namespace hex { this->drawGotoPopup(); } + + if (this->m_fileBrowser.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN)) { this->openFile(this->m_fileBrowser.selected_path); } diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index 3ccaacd14..8f24dc3ef 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -23,6 +23,21 @@ namespace hex { delete[] this->m_filter; } + + static void createStringContextMenu(const FoundString &foundString) { + if (ImGui::TableGetHoveredColumn() == 2 && ImGui::IsMouseReleased(1)) + ImGui::OpenPopup("StringContextMenu"); + if (ImGui::BeginPopup("StringContextMenu")) { + if (ImGui::MenuItem("Copy string")) + ImGui::SetClipboardText(foundString.string.c_str()); + ImGui::Separator(); + if (ImGui::MenuItem("Copy demangled string")) + ImGui::SetClipboardText(demangleItaniumSymbol(foundString.string).c_str()); + ImGui::EndPopup(); + } + } + + void ViewStrings::createView() { if (this->m_shouldInvalidate) { this->m_shouldInvalidate = false; @@ -131,6 +146,10 @@ namespace hex { ImGui::Text("0x%04lx", foundString.size); ImGui::TableNextColumn(); ImGui::Text("%s", foundString.string.c_str()); + + ImGui::PushID(i + 1); + createStringContextMenu(foundString); + ImGui::PopID(); } } clipper.End(); diff --git a/source/views/view_tools.cpp b/source/views/view_tools.cpp index 5e2581c17..823490402 100644 --- a/source/views/view_tools.cpp +++ b/source/views/view_tools.cpp @@ -10,10 +10,9 @@ namespace hex { ViewTools::ViewTools() : View("Tools") { this->m_mangledBuffer = new char[0xF'FFFF]; - this->m_demangledName = static_cast(malloc(8)); std::memset(this->m_mangledBuffer, 0x00, 0xF'FFFF); - strcpy(this->m_demangledName, "< ??? >"); + this->m_demangledName = "< ??? >"; this->m_regexInput = new char[0xF'FFFF]; this->m_regexPattern = new char[0xF'FFFF]; @@ -25,7 +24,6 @@ namespace hex { ViewTools::~ViewTools() { delete[] this->m_mangledBuffer; - free(this->m_demangledName); delete[] this->m_regexInput; delete[] this->m_regexPattern; @@ -34,21 +32,10 @@ namespace hex { void ViewTools::drawDemangler() { if (ImGui::CollapsingHeader("Itanium demangler")) { if (ImGui::InputText("Mangled name", this->m_mangledBuffer, 0xF'FFFF)) { - size_t length = 0; - int status = 0; - - if (this->m_demangledName != nullptr) - free(this->m_demangledName); - - this->m_demangledName = abi::__cxa_demangle(this->m_mangledBuffer, nullptr, &length, &status); - - if (status != 0) { - this->m_demangledName = static_cast(malloc(8)); - strcpy(this->m_demangledName, "< ??? >"); - } + this->m_demangledName = demangleItaniumSymbol(this->m_mangledBuffer); } - ImGui::InputText("Demangled name", this->m_demangledName, strlen(this->m_demangledName), ImGuiInputTextFlags_ReadOnly); + ImGui::InputText("Demangled name", this->m_demangledName.data(), this->m_demangledName.size(), ImGuiInputTextFlags_ReadOnly); ImGui::NewLine(); } }