From 66c9d4a2cf928f901338f298fc97267bfc67beee Mon Sep 17 00:00:00 2001 From: vit9696 Date: Mon, 7 May 2018 22:01:17 +0300 Subject: [PATCH] Implement external patches.txt path for UEFIPatch --- UEFIPatch/uefipatch.cpp | 6 +++--- UEFIPatch/uefipatch.h | 2 +- UEFIPatch/uefipatch_main.cpp | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/UEFIPatch/uefipatch.cpp b/UEFIPatch/uefipatch.cpp index c2e3a20..522a8ed 100644 --- a/UEFIPatch/uefipatch.cpp +++ b/UEFIPatch/uefipatch.cpp @@ -25,15 +25,15 @@ UEFIPatch::~UEFIPatch() delete ffsEngine; } -UINT8 UEFIPatch::patchFromFile(QString path) +UINT8 UEFIPatch::patchFromFile(QString path, QString patches) { - QFileInfo patchInfo = QFileInfo("patches.txt"); + QFileInfo patchInfo = QFileInfo(patches); if (!patchInfo.exists()) return ERR_INVALID_FILE; QFile file; - file.setFileName("patches.txt"); + file.setFileName(patches); if (!file.open(QFile::ReadOnly | QFile::Text)) return ERR_INVALID_FILE; diff --git a/UEFIPatch/uefipatch.h b/UEFIPatch/uefipatch.h index 3d94ca2..dd1cdb8 100644 --- a/UEFIPatch/uefipatch.h +++ b/UEFIPatch/uefipatch.h @@ -33,7 +33,7 @@ public: explicit UEFIPatch(QObject *parent = 0); ~UEFIPatch(); - UINT8 patchFromFile(QString path); + UINT8 patchFromFile(QString path, QString patches); UINT8 patch(QString path, QString fileGuid, QString findPattern, QString replacePattern); private: diff --git a/UEFIPatch/uefipatch_main.cpp b/UEFIPatch/uefipatch_main.cpp index 3edb0f6..5e7ed4b 100644 --- a/UEFIPatch/uefipatch_main.cpp +++ b/UEFIPatch/uefipatch_main.cpp @@ -14,6 +14,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include "uefipatch.h" int main(int argc, char *argv[]) @@ -27,13 +28,17 @@ int main(int argc, char *argv[]) UINT8 result = ERR_SUCCESS; UINT32 argumentsCount = a.arguments().length(); - if (argumentsCount == 2) { - result = w.patchFromFile(a.arguments().at(1)); + QString patches = "patches.txt"; + if (argumentsCount == 3) + patches = a.arguments().at(2); + + if (argumentsCount == 2 || argumentsCount == 3) { + result = w.patchFromFile(a.arguments().at(1), patches); } else { std::cout << "UEFIPatch 0.3.14 - UEFI image file patching utility" << std::endl << std::endl << - "Usage: UEFIPatch image_file" << std::endl << std::endl << - "Patches will be read from patches.txt file\n"; + "Usage: UEFIPatch image_file [patches.txt]" << std::endl << std::endl << + "Patches will be read from patches.txt file by default\n"; return ERR_SUCCESS; } @@ -57,7 +62,7 @@ int main(int argc, char *argv[]) std::cout << "Pattern format mismatch" << std::endl; break; case ERR_INVALID_FILE: - std::cout << "patches.txt file not found or can't be read" << std::endl; + std::cout << patches.toStdString() << " file not found or can't be read" << std::endl; break; case ERR_FILE_OPEN: std::cout << "Input file not found" << std::endl;