From b5961a7155ad4d3c7c87996e9fb7c30b4131839d Mon Sep 17 00:00:00 2001 From: vit9696 Date: Sat, 19 May 2018 18:55:51 +0300 Subject: [PATCH] Add -o / --output flag to UEFIPatch --- UEFIPatch/uefipatch.cpp | 4 ++-- UEFIPatch/uefipatch.h | 4 +--- UEFIPatch/uefipatch_main.cpp | 32 ++++++++++++++++++++++---------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/UEFIPatch/uefipatch.cpp b/UEFIPatch/uefipatch.cpp index 522a8ed..19129a0 100644 --- a/UEFIPatch/uefipatch.cpp +++ b/UEFIPatch/uefipatch.cpp @@ -25,7 +25,7 @@ UEFIPatch::~UEFIPatch() delete ffsEngine; } -UINT8 UEFIPatch::patchFromFile(QString path, QString patches) +UINT8 UEFIPatch::patchFromFile(const QString & path, const QString & patches, const QString & outputPath) { QFileInfo patchInfo = QFileInfo(patches); @@ -110,7 +110,7 @@ UINT8 UEFIPatch::patchFromFile(QString path, QString patches) return ERR_NOTHING_TO_PATCH; QFile outputFile; - outputFile.setFileName(path.append(".patched")); + outputFile.setFileName(outputPath); if (!outputFile.open(QFile::WriteOnly)) return ERR_FILE_WRITE; diff --git a/UEFIPatch/uefipatch.h b/UEFIPatch/uefipatch.h index dd1cdb8..d42b31d 100644 --- a/UEFIPatch/uefipatch.h +++ b/UEFIPatch/uefipatch.h @@ -33,9 +33,7 @@ public: explicit UEFIPatch(QObject *parent = 0); ~UEFIPatch(); - UINT8 patchFromFile(QString path, QString patches); - UINT8 patch(QString path, QString fileGuid, QString findPattern, QString replacePattern); - + UINT8 patchFromFile(const QString & path, const QString & patches, const QString & outputPath); private: UINT8 patchFile(const QModelIndex & index, const QByteArray & fileGuid, const UINT8 sectionType, const QVector & patches); FfsEngine* ffsEngine; diff --git a/UEFIPatch/uefipatch_main.cpp b/UEFIPatch/uefipatch_main.cpp index 6a7e50f..ff9177f 100644 --- a/UEFIPatch/uefipatch_main.cpp +++ b/UEFIPatch/uefipatch_main.cpp @@ -26,22 +26,34 @@ int main(int argc, char *argv[]) UEFIPatch w; UINT8 result = ERR_SUCCESS; - UINT32 argumentsCount = a.arguments().length(); - - QString patches = "patches.txt"; - if (argumentsCount == 3) - patches = a.arguments().at(2); + const QStringList &args = a.arguments(); + UINT32 argumentsCount = args.length(); - if (argumentsCount == 2 || argumentsCount == 3) { - result = w.patchFromFile(a.arguments().at(1), patches); - } - else { + if (argumentsCount < 2) { std::cout << "UEFIPatch 0.3.15 - UEFI image file patching utility" << std::endl << std::endl << - "Usage: UEFIPatch image_file [patches.txt]" << std::endl << std::endl << + "Usage: UEFIPatch image_file [patches.txt] [-o output]" << std::endl << std::endl << "Patches will be read from patches.txt file by default\n"; return ERR_SUCCESS; } + QString inputPath = a.arguments().at(1); + QString patches = "patches.txt"; + QString outputPath = inputPath + ".patched"; + for (UINT32 i = 2; i < argumentsCount; i++) { + if ((args.at(i) == "-o" || args.at(i) == "--output") && i + 1 < argumentsCount) { + outputPath = args.at(i+1); + i++; + } else if (patches == "patches.txt") { + patches = args.at(i); + } else { + result = ERR_INVALID_PARAMETER; + } + } + + if (result == ERR_SUCCESS) { + result = w.patchFromFile(inputPath, patches, outputPath); + } + switch (result) { case ERR_SUCCESS: std::cout << "Image patched" << std::endl;