2021-01-22 18:01:39 +01:00
|
|
|
#include <hex/plugin.hpp>
|
2023-07-13 14:08:23 +02:00
|
|
|
#include <hex/subcommands/subcommands.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
#include <hex/api/event.hpp>
|
2022-12-02 12:00:04 +01:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2022-12-05 09:31:16 +01:00
|
|
|
#include <hex/helpers/logger.hpp>
|
|
|
|
|
2022-12-02 12:00:04 +01:00
|
|
|
#include <romfs/romfs.hpp>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
using namespace hex;
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
void registerEventHandlers();
|
|
|
|
void registerDataVisualizers();
|
2021-01-22 18:01:39 +01:00
|
|
|
void registerDataInspectorEntries();
|
|
|
|
void registerToolEntries();
|
|
|
|
void registerPatternLanguageFunctions();
|
2022-04-17 16:57:30 +02:00
|
|
|
void registerPatternLanguagePragmas();
|
2023-01-20 21:16:28 +01:00
|
|
|
void registerPatternLanguageVisualizers();
|
2023-07-04 22:18:06 +02:00
|
|
|
void registerPatternLanguageInlineVisualizers();
|
2021-01-22 18:01:39 +01:00
|
|
|
void registerCommandPaletteCommands();
|
|
|
|
void registerSettings();
|
2022-07-02 16:22:38 +02:00
|
|
|
void loadSettings();
|
2021-01-30 22:39:06 +01:00
|
|
|
void registerDataProcessorNodes();
|
2022-05-30 16:36:46 +02:00
|
|
|
void registerHashes();
|
2021-12-07 22:47:41 +01:00
|
|
|
void registerProviders();
|
2022-01-13 00:27:31 +01:00
|
|
|
void registerDataFormatters();
|
2022-01-18 00:10:10 +01:00
|
|
|
void registerMainMenuEntries();
|
2022-02-01 18:09:40 +01:00
|
|
|
void createWelcomeScreen();
|
2022-05-27 20:42:07 +02:00
|
|
|
void registerViews();
|
2022-12-29 19:26:00 +01:00
|
|
|
void registerThemeHandlers();
|
2023-02-16 18:06:40 +01:00
|
|
|
void registerStyleHandlers();
|
2022-12-29 19:26:00 +01:00
|
|
|
void registerThemes();
|
2023-05-15 11:30:24 +02:00
|
|
|
void registerBackgroundServices();
|
|
|
|
void registerNetworkEndpoints();
|
2023-06-06 21:35:13 +02:00
|
|
|
void registerFileHandlers();
|
2023-06-21 20:07:36 +02:00
|
|
|
void registerProjectHandlers();
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
void addFooterItems();
|
2023-05-25 09:26:40 +02:00
|
|
|
void addTitleBarButtons();
|
2021-08-21 00:52:11 +02:00
|
|
|
void addToolbarItems();
|
2022-05-27 20:42:07 +02:00
|
|
|
void addGlobalUIItems();
|
2021-06-07 18:13:54 +02:00
|
|
|
|
2022-07-29 11:34:55 +02:00
|
|
|
void handleBorderlessWindowMode();
|
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
void handleSubCommands();
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
|
|
|
|
2023-07-13 14:08:23 +02:00
|
|
|
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);
|
|
|
|
}}
|
|
|
|
};
|
|
|
|
|
2021-02-19 13:22:12 +01:00
|
|
|
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
using namespace hex::plugin::builtin;
|
|
|
|
|
2022-12-05 09:31:16 +01:00
|
|
|
hex::log::debug("Using romfs: '{}'", romfs::name());
|
2022-12-02 12:00:04 +01:00
|
|
|
for (auto &path : romfs::list("lang"))
|
|
|
|
hex::ContentRegistry::Language::addLocalization(nlohmann::json::parse(romfs::get(path).string()));
|
2022-02-16 21:32:33 +01:00
|
|
|
|
2022-05-27 20:42:07 +02:00
|
|
|
registerEventHandlers();
|
|
|
|
registerDataVisualizers();
|
2021-01-22 18:01:39 +01:00
|
|
|
registerDataInspectorEntries();
|
|
|
|
registerToolEntries();
|
|
|
|
registerPatternLanguageFunctions();
|
2022-04-17 16:57:30 +02:00
|
|
|
registerPatternLanguagePragmas();
|
2023-01-20 21:16:28 +01:00
|
|
|
registerPatternLanguageVisualizers();
|
2023-07-04 22:18:06 +02:00
|
|
|
registerPatternLanguageInlineVisualizers();
|
2021-01-22 18:01:39 +01:00
|
|
|
registerCommandPaletteCommands();
|
|
|
|
registerSettings();
|
2022-07-02 16:22:38 +02:00
|
|
|
loadSettings();
|
2021-01-30 22:39:06 +01:00
|
|
|
registerDataProcessorNodes();
|
2022-05-30 16:36:46 +02:00
|
|
|
registerHashes();
|
2021-12-07 22:47:41 +01:00
|
|
|
registerProviders();
|
2022-01-13 00:27:31 +01:00
|
|
|
registerDataFormatters();
|
2022-02-01 18:09:40 +01:00
|
|
|
createWelcomeScreen();
|
2022-05-27 20:42:07 +02:00
|
|
|
registerViews();
|
2022-12-29 19:26:00 +01:00
|
|
|
registerThemeHandlers();
|
2023-02-16 18:06:40 +01:00
|
|
|
registerStyleHandlers();
|
2022-12-29 19:26:00 +01:00
|
|
|
registerThemes();
|
2023-05-15 11:30:24 +02:00
|
|
|
registerBackgroundServices();
|
|
|
|
registerNetworkEndpoints();
|
2023-06-06 21:35:13 +02:00
|
|
|
registerFileHandlers();
|
2023-06-21 20:07:36 +02:00
|
|
|
registerProjectHandlers();
|
2021-02-13 15:15:32 +01:00
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
addFooterItems();
|
2023-05-25 09:26:40 +02:00
|
|
|
addTitleBarButtons();
|
2021-08-21 00:52:11 +02:00
|
|
|
addToolbarItems();
|
2022-05-27 20:42:07 +02:00
|
|
|
addGlobalUIItems();
|
|
|
|
|
2022-01-18 00:10:10 +01:00
|
|
|
registerMainMenuEntries();
|
2022-07-29 11:34:55 +02:00
|
|
|
|
|
|
|
handleBorderlessWindowMode();
|
2021-01-22 18:01:39 +01:00
|
|
|
}
|
2022-02-01 18:09:40 +01:00
|
|
|
|
|
|
|
// This is the default plugin
|
|
|
|
// DO NOT USE THIS IN ANY OTHER PLUGIN
|
2022-02-07 15:42:38 +01:00
|
|
|
extern "C" bool isBuiltinPlugin() { return true; }
|