From b5df20d7c6994846c6c6214bc802d82ef5e7af02 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 15 Dec 2023 08:11:51 +0100 Subject: [PATCH] feat: Exposed demangling of symbols to CLI --- .../include/content/command_line_interface.hpp | 1 + .../builtin/source/content/command_line_interface.cpp | 11 ++++++++++- .../source/content/command_palette_commands.cpp | 2 +- plugins/builtin/source/plugin_builtin.cpp | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/builtin/include/content/command_line_interface.hpp b/plugins/builtin/include/content/command_line_interface.hpp index c2381f1a6..a9921a863 100644 --- a/plugins/builtin/include/content/command_line_interface.hpp +++ b/plugins/builtin/include/content/command_line_interface.hpp @@ -18,6 +18,7 @@ namespace hex::plugin::builtin { void handleMagicCommand(const std::vector &args); void handlePatternLanguageCommand(const std::vector &args); void handleHexdumpCommand(const std::vector &args); + void handleDemangleCommand(const std::vector &args); void registerCommandForwarders(); diff --git a/plugins/builtin/source/content/command_line_interface.cpp b/plugins/builtin/source/content/command_line_interface.cpp index f780133bc..384c5b2a8 100644 --- a/plugins/builtin/source/content/command_line_interface.cpp +++ b/plugins/builtin/source/content/command_line_interface.cpp @@ -19,9 +19,9 @@ #include #include +#include namespace hex::plugin::builtin { - using namespace hex::literals; void handleVersionCommand(const std::vector &args) { @@ -302,6 +302,15 @@ namespace hex::plugin::builtin { std::exit(EXIT_SUCCESS); } + void handleDemangleCommand(const std::vector &args) { + if (args.size() != 1) { + log::println("usage: imhex --demangle "); + std::exit(EXIT_FAILURE); + } + + log::println("{}", llvm::demangle(args[0])); + } + void registerCommandForwarders() { hex::subcommands::registerSubCommand("open", [](const std::vector &args){ diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index e64329fee..4af735d6d 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -214,7 +214,7 @@ namespace hex::plugin::builtin { }; std::vector splitConversionCommandInput(const std::string &input) { - std::vector parts = wolv::util::splitString(input, " "); + std::vector parts = wolv::util::splitString(input, " ", true); std::erase_if(parts, [](auto &part) { return part.empty(); }); return parts; diff --git a/plugins/builtin/source/plugin_builtin.cpp b/plugins/builtin/source/plugin_builtin.cpp index 9f0354d9d..1909aef36 100644 --- a/plugins/builtin/source/plugin_builtin.cpp +++ b/plugins/builtin/source/plugin_builtin.cpp @@ -69,6 +69,7 @@ IMHEX_PLUGIN_SUBCOMMANDS() { { "magic", "Identify file types", hex::plugin::builtin::handleMagicCommand }, { "pl", "Interact with the pattern language", hex::plugin::builtin::handlePatternLanguageCommand }, { "hexdump", "Generate a hex dump of the provided file", hex::plugin::builtin::handleHexdumpCommand }, + { "hexdump", "Demangle a mangled symbol", hex::plugin::builtin::handleDemangleCommand }, }; IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {