1
0
mirror of synced 2024-11-24 07:40:17 +01:00

impr: Handle demangling of identifiers without leading underscore

This commit is contained in:
WerWolv 2024-07-11 20:38:22 +02:00
parent c311b5315f
commit 1e18935513
7 changed files with 37 additions and 8 deletions

View File

@ -48,6 +48,8 @@ add_imhex_plugin(
source/content/window_decoration.cpp
source/content/data_information_sections.cpp
source/content/helpers/demangle.cpp
source/content/data_processor_nodes/basic_nodes.cpp
source/content/data_processor_nodes/control_nodes.cpp
source/content/data_processor_nodes/decode_nodes.cpp

View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
namespace hex::plugin::builtin {
std::string demangle(const std::string &mangled);
}

View File

@ -1,5 +1,6 @@
#include <content/command_line_interface.hpp>
#include <content/providers/file_provider.hpp>
#include <content/helpers/demangle.hpp>
#include <hex/api/content_registry.hpp>
#include <hex/api/imhex_api.hpp>
@ -348,7 +349,7 @@ namespace hex::plugin::builtin {
std::exit(EXIT_FAILURE);
}
log::println("{}", llvm::demangle(args[0]));
log::println("{}", hex::plugin::builtin::demangle(args[0]));
std::exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,17 @@
#include <content/helpers/demangle.hpp>
#include <llvm/Demangle/Demangle.h>
namespace hex::plugin::builtin {
std::string demangle(const std::string &mangled) {
std::string result = llvm::demangle(mangled);
if (result.empty() || result == mangled)
result = llvm::demangle("_" + mangled);
if (result.empty() || result == ("_" + mangled))
result = mangled;
return result;
}
}

View File

@ -7,7 +7,7 @@
#include <pl/core/token.hpp>
#include <pl/core/evaluator.hpp>
#include <llvm/Demangle/Demangle.h>
#include <content/helpers/demangle.hpp>
#include <pl/patterns/pattern.hpp>
namespace hex::plugin::builtin {
@ -75,7 +75,7 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "demangle", FunctionParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional<Token::Literal> {
const auto mangledString = params[0].toString(false);
return llvm::demangle(mangledString);
return hex::plugin::builtin::demangle(mangledString);
});
}

View File

@ -1,7 +1,7 @@
#include <hex/helpers/utils.hpp>
#include <hex/api/localization_manager.hpp>
#include <llvm/Demangle/Demangle.h>
#include <content/helpers/demangle.hpp>
#include <imgui.h>
#include <hex/ui/imgui_imhex_extensions.h>
@ -31,7 +31,7 @@ namespace hex::plugin::builtin {
static float prevWindowWidth;
if (ImGui::InputTextWithHint("hex.builtin.tools.demangler.mangled"_lang, "Itanium, MSVC, Dlang & Rust", mangledName)) {
demangledName = llvm::demangle(mangledName);
demangledName = hex::plugin::builtin::demangle(mangledName);
if (demangledName == mangledName) {
demangledName = "???";

View File

@ -12,7 +12,7 @@
#include <string>
#include <utility>
#include <llvm/Demangle/Demangle.h>
#include <content/helpers/demangle.hpp>
#include <boost/regex.hpp>
namespace hex::plugin::builtin {
@ -68,7 +68,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGuiExt::TextFormatted("[ 0x{:08X} - 0x{:08X} ]", region.getStartAddress(), region.getEndAddress());
auto demangledValue = llvm::demangle(value);
auto demangledValue = hex::plugin::builtin::demangle(value);
if (value != demangledValue) {
ImGui::TableNextRow();
@ -602,7 +602,7 @@ namespace hex::plugin::builtin {
if (ImGui::MenuItem("hex.builtin.view.find.context.copy"_lang))
ImGui::SetClipboardText(value.c_str());
if (ImGui::MenuItem("hex.builtin.view.find.context.copy_demangle"_lang))
ImGui::SetClipboardText(llvm::demangle(value).c_str());
ImGui::SetClipboardText(hex::plugin::builtin::demangle(value).c_str());
if (ImGui::BeginMenu("hex.builtin.view.find.context.replace"_lang)) {
if (ImGui::BeginTabBar("##replace_tabs")) {
if (ImGui::BeginTabItem("hex.builtin.view.find.context.replace.hex"_lang)) {