#include "argumentParser.h" #include "handlers.h" #include #include "cxxopts.hpp" ParsedArguments parse_arguments(int argc, char* argv[]) { ParsedArguments args; cxxopts::Options options( "CopyReadProcessMemory", "C++ tool that supports exactly one input mode" ); options.add_options() ("s,string_inject", "", cxxopts::value()) ("f,file_path", "", cxxopts::value()) ("t,remote_payload", "", cxxopts::value()) ("e,execute", "Execute payload") ("x,xor", "XOR payload with key string", cxxopts::value()) ("h,help", "Show help") ("V,version", "Show version") ; auto result = options.parse(argc, argv); // Assign basic flags args.show_help = result.count("help"); args.show_version = result.count("version"); args.execute = result["execute"].as(); if (result.count("xor")) { args.xor_key = result["xor"].as(); if (args.xor_key.empty()) throw std::runtime_error("XOR key cannot be empty"); } int mode_count = 0; if (result.count("string_inject")) { args.string_inject = result["string_inject"].as(); args.mode = InputMode::StringInject; mode_count++; } if (result.count("file_path")) { args.file_path = result["file_path"].as(); args.mode = InputMode::FilePath; mode_count++; } if (result.count("remote_payload")) { args.remote_payload = result["remote_payload"].as(); args.mode = InputMode::RemotePayload; mode_count++; } if (!args.show_help && !args.show_version) { if (mode_count == 0) throw std::runtime_error("You must select exactly ONE mode: --string_inject, --file_path, or --remote_payload."); if (mode_count > 1) throw std::runtime_error("Only ONE mode is allowed. Remove conflicting options."); } if (!args.show_help && !args.show_version) { if (mode_count == 0) throw std::runtime_error("You must select exactly ONE mode: --string_inject, --file_path, or --remote_payload."); if (mode_count > 1) throw std::runtime_error("Only ONE mode is allowed. Remove conflicting options."); } return args; }