mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 05:05:19 -05:00
feat: Added command line interface support (#1172)
System design has been discussed on discord Should fix #948 --------- Co-authored-by: WerWolv <werwolv98@gmail.com>
This commit is contained in:
21
plugins/builtin/romfs/logo.ans
Normal file
21
plugins/builtin/romfs/logo.ans
Normal file
@@ -0,0 +1,21 @@
|
||||
[1mImHex Hex Editor[0m
|
||||
[3mA Hex Editor for Reverse Engineers, Programmers and people
|
||||
who value their retinas when working at 3 AM.[0m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;062m([38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;062m([38;5;061m/[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;062m([38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;068m([38;5;062m([38;5;061m/[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;060m*[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;237m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;024m*[38;5;m [38;5;m [38;5;m [0m[1mVersion: [0m{0}[0m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;068m([38;5;062m([38;5;062m([38;5;062m([38;5;062m/[38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;068m([38;5;062m([38;5;062m([38;5;062m([38;5;062m([38;5;062m/[38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;068m([38;5;062m([38;5;062m([38;5;068m([38;5;062m([38;5;061m/[38;5;m [38;5;m [38;5;m [0m[1mCommit: [0m{1}@{2}[0m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;062m([38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;062m([38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;061m/[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;062m([38;5;062m([38;5;062m([38;5;062m([38;5;062m/[38;5;061m/[38;5;m [38;5;m [38;5;m [0m[1mBuild time: [0m{3}, {4}[0m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;062m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;061m/[38;5;061m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;062m/[38;5;062m/[38;5;062m/[38;5;062m/[38;5;061m/[38;5;061m/[38;5;m [38;5;m [38;5;m [0m[1mType: [0m{5}[0m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;025m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;025m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m*[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;025m/[38;5;025m/[38;5;061m/[38;5;025m*[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;025m*[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;061m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;024m*[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;025m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;024m*[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;060m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;025m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;061m*[38;5;025m*[38;5;025m*[38;5;025m*[38;5;024m*[38;5;024m*[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m*[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m,[38;5;024m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m,[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m,[38;5;024m,[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;024m,[38;5;023m,[38;5;004m,[38;5;004m,[38;5;017m,[38;5;017m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;017m,[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m*[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;023m,[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;061m/[38;5;060m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;024m,[38;5;017m,[38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;061m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;024m*[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;237m,[38;5;017m.[38;5;017m.[38;5;017m.[38;5;017m.[38;5;017m.[38;5;m [38;5;m [38;5;m [38;5;m
|
||||
[38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m [38;5;m
|
||||
[0m
|
||||
@@ -1,11 +1,15 @@
|
||||
#include <hex/plugin.hpp>
|
||||
#include <hex/subcommands/subcommands.hpp>
|
||||
|
||||
#include <hex/api/event.hpp>
|
||||
#include <hex/api/content_registry.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <romfs/romfs.hpp>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using namespace hex;
|
||||
|
||||
namespace hex::plugin::builtin {
|
||||
|
||||
void registerEventHandlers();
|
||||
@@ -41,8 +45,69 @@ namespace hex::plugin::builtin {
|
||||
|
||||
void handleBorderlessWindowMode();
|
||||
|
||||
void handleSubCommands();
|
||||
|
||||
}
|
||||
|
||||
IMHEX_PLUGIN_SUBCOMMANDS() {
|
||||
{ "version", "Print ImHex version and exit", [](const std::vector<std::string>&) {
|
||||
hex::print(romfs::get("logo.ans").string(),
|
||||
ImHexApi::System::getImHexVersion(),
|
||||
ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash(),
|
||||
__DATE__, __TIME__,
|
||||
ImHexApi::System::isPortableVersion() ? "Portable" : "Installed");
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}},
|
||||
{ "help", "Print help about this command and exit", [](const std::vector<std::string>&) {
|
||||
hex::print(
|
||||
"ImHex - A Hex Editor for Reverse Engineers, Programmers and people who value their retinas when working at 3 AM.\n"
|
||||
"\n"
|
||||
"usage: imhex [subcommand] [options]\n"
|
||||
"Available subcommands:\n"
|
||||
);
|
||||
|
||||
size_t longestCommand = 0;
|
||||
for (const auto &plugin : PluginManager::getPlugins()) {
|
||||
for (const auto &subCommand : plugin.getSubCommands()) {
|
||||
longestCommand = std::max(longestCommand, subCommand.commandKey.size());
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &plugin : PluginManager::getPlugins()) {
|
||||
for (const auto &subCommand : plugin.getSubCommands()) {
|
||||
hex::print(" --{}{: <{}} {}\n", subCommand.commandKey, "", longestCommand - subCommand.commandKey.size(), subCommand.commandDesc);
|
||||
}
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}},
|
||||
{ "open", "Open files passed as argument. This is the default subcommand is none is entered",
|
||||
[](const std::vector<std::string> &args) {
|
||||
|
||||
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){
|
||||
for (auto &arg : args) {
|
||||
EventManager::post<RequestOpenFile>(arg);
|
||||
}
|
||||
});
|
||||
|
||||
std::vector<std::string> fullPaths;
|
||||
bool doubleDashFound = false;
|
||||
for (auto &arg : args) {
|
||||
|
||||
// Skip the first argument named `--`
|
||||
if (arg == "--" && !doubleDashFound) {
|
||||
doubleDashFound = true;
|
||||
} else {
|
||||
auto path = std::filesystem::weakly_canonical(arg);
|
||||
fullPaths.push_back(wolv::util::toUTF8String(path));
|
||||
}
|
||||
}
|
||||
|
||||
hex::subcommands::forwardSubCommand("open", fullPaths);
|
||||
}}
|
||||
};
|
||||
|
||||
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
||||
|
||||
using namespace hex::plugin::builtin;
|
||||
|
||||
Reference in New Issue
Block a user