Skip to content

Commit

Permalink
impr: Handle demangling of identifiers without leading underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Jul 11, 2024
1 parent c311b53 commit 1e18935
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions plugins/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions plugins/builtin/include/content/helpers/demangle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include <string>

namespace hex::plugin::builtin {

std::string demangle(const std::string &mangled);

}
3 changes: 2 additions & 1 deletion plugins/builtin/source/content/command_line_interface.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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);
}

Expand Down
17 changes: 17 additions & 0 deletions plugins/builtin/source/content/helpers/demangle.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

}
4 changes: 2 additions & 2 deletions plugins/builtin/source/content/pl_builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
});
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/builtin/source/content/tools/demangler.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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 = "???";
Expand Down
6 changes: 3 additions & 3 deletions plugins/builtin/source/content/views/view_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 1e18935

Please sign in to comment.