From 54bdb2c373e418430f183639455aba0dc43cb175 Mon Sep 17 00:00:00 2001 From: redthing1 Date: Tue, 27 May 2025 22:22:28 -0700 Subject: [PATCH 1/2] analyzer: add help and long options to cli --- src/analyzer/main.cpp | 63 ++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index b95bd429..7858930b 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -348,6 +348,27 @@ namespace return args; } + void print_help() + { + printf("Usage: analyzer [options] [application] [args...]\n\n"); + printf("Options:\n"); + printf(" -h, --help Show this help message\n"); + printf(" -d, --debug Enable GDB debugging mode\n"); + printf(" -s, --silent Silent mode\n"); + printf(" -v, --verbose Verbose logging\n"); + printf(" -b, --buffer Buffer stdout\n"); + printf(" -c, --concise Concise logging\n"); + printf(" -m, --module Specify module to track\n"); + printf(" -e, --emulation Set emulation root path\n"); + printf(" -a, --snapshot Load snapshot dump from path\n"); + printf(" -i, --ignore Comma-separated list of functions to ignore\n"); + printf(" -p, --path Map Windows path to host path\n"); + printf(" -r, --registry Set registry path (default: ./registry)\n\n"); + printf("Examples:\n"); + printf(" analyzer -v -e path/to/root myapp.exe\n"); + printf(" analyzer -e path/to/root -p c:/analysis-sample.exe /path/to/sample.exe c:/analysis-sample.exe\n"); + } + analysis_options parse_options(std::vector& args) { analysis_options options{}; @@ -357,68 +378,73 @@ namespace auto arg_it = args.begin(); const auto& arg = *arg_it; - if (arg == "-d") + if (arg == "-h" || arg == "--help") + { + print_help(); + std::exit(0); + } + else if (arg == "-d" || arg == "--debug") { options.use_gdb = true; } - else if (arg == "-s") + else if (arg == "-s" || arg == "--silent") { options.silent = true; } - else if (arg == "-v") + else if (arg == "-v" || arg == "--verbose") { options.verbose_logging = true; } - else if (arg == "-b") + else if (arg == "-b" || arg == "--buffer") { options.buffer_stdout = true; } - else if (arg == "-c") + else if (arg == "-c" || arg == "--concise") { options.concise_logging = true; } - else if (arg == "-m") + else if (arg == "-m" || arg == "--module") { if (args.size() < 2) { - throw std::runtime_error("No module provided after -m"); + throw std::runtime_error("No module provided after -m/--module"); } arg_it = args.erase(arg_it); options.modules.insert(std::string(args[0])); } - else if (arg == "-e") + else if (arg == "-e" || arg == "--emulation") { if (args.size() < 2) { - throw std::runtime_error("No emulation root path provided after -e"); + throw std::runtime_error("No emulation root path provided after -e/--emulation"); } arg_it = args.erase(arg_it); options.emulation_root = args[0]; } - else if (arg == "-a") + else if (arg == "-a" || arg == "--snapshot") { if (args.size() < 2) { - throw std::runtime_error("No dump path provided after -a"); + throw std::runtime_error("No dump path provided after -a/--snapshot"); } arg_it = args.erase(arg_it); options.dump = args[0]; } - else if (arg == "-i") + else if (arg == "-i" || arg == "--ignore") { if (args.size() < 2) { - throw std::runtime_error("No ignored function(s) provided after -i"); + throw std::runtime_error("No ignored function(s) provided after -i/--ignore"); } arg_it = args.erase(arg_it); split_and_insert(options.ignored_functions, args[0]); } - else if (arg == "-p") + else if (arg == "-p" || arg == "--path") { if (args.size() < 3) { - throw std::runtime_error("No path mapping provided after -p"); + throw std::runtime_error("No path mapping provided after -p/--path"); } arg_it = args.erase(arg_it); windows_path source = args[0]; @@ -427,11 +453,11 @@ namespace options.path_mappings[std::move(source)] = std::move(target); } - else if (arg == "-r") + else if (arg == "-r" || arg == "--registry") { if (args.size() < 2) { - throw std::runtime_error("No registry path provided after -r"); + throw std::runtime_error("No registry path provided after -r/--registry"); } arg_it = args.erase(arg_it); options.registry_path = args[0]; @@ -457,7 +483,8 @@ int main(const int argc, char** argv) if (args.empty() && options.dump.empty()) { - throw std::runtime_error("Application not specified!"); + print_help(); + return 1; } bool result{}; From b05794375146660f467d6eccaf734faaada4ece7 Mon Sep 17 00:00:00 2001 From: redthing1 Date: Tue, 27 May 2025 22:55:16 -0700 Subject: [PATCH 2/2] fixup! analyzer: add help and long options to cli --- src/analyzer/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/analyzer/main.cpp b/src/analyzer/main.cpp index 7858930b..363fb450 100644 --- a/src/analyzer/main.cpp +++ b/src/analyzer/main.cpp @@ -479,14 +479,14 @@ int main(const int argc, char** argv) try { auto args = bundle_arguments(argc, argv); - const auto options = parse_options(args); - - if (args.empty() && options.dump.empty()) + if (args.empty()) { print_help(); return 1; } + const auto options = parse_options(args); + bool result{}; do