1
0
mirror of synced 2024-11-12 02:00:52 +01:00

feat: Added --hexdump subcommand

This commit is contained in:
WerWolv 2023-12-05 16:45:35 +01:00
parent 760b8c7a88
commit 2b22a15e8c
3 changed files with 30 additions and 0 deletions

View File

@ -17,6 +17,7 @@ namespace hex::plugin::builtin {
void handleDecodeCommand(const std::vector<std::string> &args);
void handleMagicCommand(const std::vector<std::string> &args);
void handlePatternLanguageCommand(const std::vector<std::string> &args);
void handleHexdumpCommand(const std::vector<std::string> &args);
void registerCommandForwarders();

View File

@ -1,5 +1,6 @@
#include "content/command_line_interface.hpp"
#include <content/providers/file_provider.hpp>
#include <hex/api/imhex_api.hpp>
#include <hex/api/event_manager.hpp>
@ -11,6 +12,7 @@
#include <romfs/romfs.hpp>
#include <hex/api/plugin_manager.hpp>
#include <hex/helpers/utils.hpp>
#include <hex/subcommands/subcommands.hpp>
#include <wolv/utils/string.hpp>
@ -274,6 +276,32 @@ namespace hex::plugin::builtin {
std::exit(pl::cli::executeCommandLineInterface(processedArgs));
}
void handleHexdumpCommand(const std::vector<std::string> &args) {
if (args.size() < 1 || args.size() > 3) {
log::println("usage: imhex --hexdump <file> <offset> <size>");
std::exit(EXIT_FAILURE);
}
std::fs::path filePath = reinterpret_cast<const char8_t*>(args[0].data());
FileProvider provider;
provider.setPath(filePath);
if (!provider.open()) {
log::println("Failed to open file '{}'", args[0]);
std::exit(EXIT_FAILURE);
}
u64 startAddress = args.size() >= 2 ? std::stoull(args[1], nullptr, 0) : 0x00;
u64 size = args.size() >= 3 ? std::stoull(args[2], nullptr, 0) : provider.getActualSize();
size = std::min(size, provider.getActualSize());
log::print("{}", hex::generateHexView(startAddress, size - startAddress, &provider));
std::exit(EXIT_SUCCESS);
}
void registerCommandForwarders() {
hex::subcommands::registerSubCommand("open", [](const std::vector<std::string> &args){

View File

@ -66,6 +66,7 @@ IMHEX_PLUGIN_SUBCOMMANDS() {
{ "decode", "Decode a string", hex::plugin::builtin::handleDecodeCommand },
{ "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 },
};
IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {