diff --git a/UEFIExtract/uefiextract_main.cpp b/UEFIExtract/uefiextract_main.cpp index 63559f3..ad21fb6 100644 --- a/UEFIExtract/uefiextract_main.cpp +++ b/UEFIExtract/uefiextract_main.cpp @@ -30,11 +30,38 @@ enum ReadType { READ_SECTION }; +void print_usage() +{ + std::cout << "UEFIExtract " PROGRAM_VERSION << std::endl + << "Usage: UEFIExtract {-h | --help | -v | --version} - show help and/or version information." << std::endl + << " UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder." << std::endl + << " UEFIExtract imagefile all - generate report and dump all tree items." << std::endl + << " UEFIExtract imagefile unpack - generate report and dump all tree items in one dir." << std::endl + << " UEFIExtract imagefile dump - only generate dump, no report needed." << std::endl + << " UEFIExtract imagefile report - only generate report, no dump needed." << std::endl + << " UEFIExtract imagefile GUID_1 ... [ -o FILE_1 ... ] [ -m MODE_1 ... ] [ -t TYPE_1 ... ] -" << std::endl + << " Dump only FFS file(s) with specific GUID(s), without report." << std::endl + << " Type is section type or FF to ignore. Mode is one of: all, body, header, info, file." << std::endl + << "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise." << std::endl; +} + int main(int argc, char *argv[]) { initGuidDatabase("guids.csv"); if (argc > 1) { + if (argc == 2) { + UString arg = UString(argv[1]); + if (arg == UString("-h") || arg == UString("--help")) { + print_usage(); + return U_SUCCESS; + } + else if (arg == UString("-v") || arg == UString("--version")) { + std::cout << PROGRAM_VERSION << std::endl; + return U_SUCCESS; + } + } + // Check that input file exists USTATUS result; UByteArray buffer; @@ -154,16 +181,8 @@ int main(int argc, char *argv[]) return 0; } } + // If parameters are different, show version and usage information - std::cout << "UEFIExtract " PROGRAM_VERSION << std::endl << std::endl - << "Usage: UEFIExtract imagefile - generate report and dump only leaf tree items into .dump folder." << std::endl - << " UEFIExtract imagefile all - generate report and dump all tree items." << std::endl - << " UEFIExtract imagefile unpack - generate report and dump all tree items in one dir." << std::endl - << " UEFIExtract imagefile dump - only generate dump, no report needed." << std::endl - << " UEFIExtract imagefile report - only generate report, no dump needed." << std::endl - << " UEFIExtract imagefile GUID_1 ... [ -o FILE_1 ... ] [ -m MODE_1 ... ] [ -t TYPE_1 ... ] -" << std::endl - << " Dump only FFS file(s) with specific GUID(s), without report." << std::endl - << " Type is section type or FF to ignore. Mode is one of: all, body, header, info, file." << std::endl - << "Return value is a bit mask where 0 at position N means that file with GUID_N was found and unpacked, 1 otherwise." << std::endl; + print_usage(); return 1; } diff --git a/UEFIFind/uefifind_main.cpp b/UEFIFind/uefifind_main.cpp index b44302b..57c9eb3 100644 --- a/UEFIFind/uefifind_main.cpp +++ b/UEFIFind/uefifind_main.cpp @@ -19,6 +19,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "../common/guiddatabase.h" #include "uefifind.h" +void print_usage() +{ + std::cout << "UEFIFind " PROGRAM_VERSION << std::endl << + "Usage: UEFIFind {-h | --help | -v | -version}" << std::endl << + " UEFIFind imagefile {header | body | all} {list | count} pattern" << std::endl << + " UEFIFind imagefile file patternsfile" << std::endl; +} + int main(int argc, char *argv[]) { UEFIFind w; @@ -26,7 +34,22 @@ int main(int argc, char *argv[]) initGuidDatabase("guids.csv"); - if (argc == 5) { + if (argc == 1) { + print_usage(); + return U_SUCCESS; + } + else if (argc == 2) { + UString arg = argv[1]; + if (arg == UString("-h") || arg == UString("--help")) { + print_usage(); + return U_SUCCESS; + } + else if (arg == UString("-v") || arg == UString("--version")) { + std::cout << PROGRAM_VERSION << std::endl; + return U_SUCCESS; + } + } + else if (argc == 5) { UString inputArg = argv[1]; UString modeArg = argv[2]; UString subModeArg = argv[3]; @@ -165,10 +188,7 @@ int main(int argc, char *argv[]) return U_SUCCESS; } - else { - std::cout << "UEFIFind " PROGRAM_VERSION << std::endl << std::endl << - "Usage: UEFIFind imagefile {header | body | all} {list | count} pattern" << std::endl << - " or UEFIFind imagefile file patternsfile" << std::endl; - return U_INVALID_PARAMETER; - } + + print_usage(); + return U_INVALID_PARAMETER; }