mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
Added copy string and copy demangled string to strings window
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#include <winsock.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#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:
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace hex {
|
||||
|
||||
private:
|
||||
char *m_mangledBuffer = nullptr;
|
||||
char *m_demangledName = nullptr;
|
||||
std::string m_demangledName;
|
||||
|
||||
bool m_asciiTableShowOctal = false;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -10,10 +10,9 @@ namespace hex {
|
||||
|
||||
ViewTools::ViewTools() : View("Tools") {
|
||||
this->m_mangledBuffer = new char[0xF'FFFF];
|
||||
this->m_demangledName = static_cast<char*>(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<char*>(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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user