2023-11-12 01:22:01 +01:00
|
|
|
#include <hex/helpers/utils.hpp>
|
2023-11-21 14:38:01 +01:00
|
|
|
#include <hex/api/localization_manager.hpp>
|
2023-11-12 01:22:01 +01:00
|
|
|
|
|
|
|
#include <llvm/Demangle/Demangle.h>
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2023-12-01 13:53:51 +01:00
|
|
|
#include <TextEditor.h>
|
2023-11-12 01:22:01 +01:00
|
|
|
|
2023-11-25 15:36:50 +01:00
|
|
|
|
2023-11-12 01:22:01 +01:00
|
|
|
namespace hex::plugin::builtin {
|
2023-11-25 15:36:50 +01:00
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
void drawDemangler() {
|
|
|
|
static std::string mangledName, demangledName, wrappedDemangledName;
|
|
|
|
static TextEditor outputField = []{
|
|
|
|
TextEditor editor;
|
|
|
|
editor.SetReadOnly(true);
|
|
|
|
editor.SetShowLineNumbers(false);
|
|
|
|
editor.SetShowWhitespaces(false);
|
|
|
|
editor.SetShowCursor(false);
|
|
|
|
editor.SetImGuiChildIgnored(true);
|
2023-11-25 15:36:50 +01:00
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
auto languageDef = TextEditor::LanguageDefinition::CPlusPlus();
|
|
|
|
for (auto &[name, identifier] : languageDef.mIdentifiers)
|
|
|
|
identifier.mDeclaration = "";
|
|
|
|
|
|
|
|
editor.SetLanguageDefinition(languageDef);
|
2023-11-12 01:22:01 +01:00
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
return editor;
|
|
|
|
}();
|
|
|
|
static float prevWindowWidth;
|
2023-11-25 15:36:50 +01:00
|
|
|
|
2023-12-01 13:53:51 +01:00
|
|
|
if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) {
|
|
|
|
demangledName = llvm::demangle(mangledName);
|
|
|
|
|
|
|
|
if (demangledName == mangledName) {
|
|
|
|
demangledName = "???";
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|
2023-12-01 13:53:51 +01:00
|
|
|
|
|
|
|
prevWindowWidth = 0;
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|
2023-12-01 13:53:51 +01:00
|
|
|
|
|
|
|
const auto windowWidth = ImGui::GetContentRegionAvail().x;
|
|
|
|
if (prevWindowWidth != windowWidth) {
|
|
|
|
wrappedDemangledName = wolv::util::wrapMonospacedString(
|
|
|
|
demangledName,
|
|
|
|
ImGui::CalcTextSize("M").x,
|
|
|
|
ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize
|
|
|
|
);
|
|
|
|
|
|
|
|
outputField.SetText(wrappedDemangledName);
|
|
|
|
prevWindowWidth = windowWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGuiExt::Header("hex.builtin.tools.demangler.demangled"_lang);
|
|
|
|
|
|
|
|
if (ImGui::BeginChild("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true, ImGuiWindowFlags_NoMove)) {
|
|
|
|
outputField.Render("Demangled", ImVec2(ImGui::GetContentRegionAvail().x, 150_scaled), true);
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|
2023-12-01 13:53:51 +01:00
|
|
|
|
2023-11-12 01:22:01 +01:00
|
|
|
}
|