Add -o / --output flag to UEFIPatch

This commit is contained in:
vit9696 2018-05-19 18:55:51 +03:00
parent 8db52ea51a
commit b5961a7155
3 changed files with 25 additions and 15 deletions

View file

@ -25,7 +25,7 @@ UEFIPatch::~UEFIPatch()
delete ffsEngine; 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); QFileInfo patchInfo = QFileInfo(patches);
@ -110,7 +110,7 @@ UINT8 UEFIPatch::patchFromFile(QString path, QString patches)
return ERR_NOTHING_TO_PATCH; return ERR_NOTHING_TO_PATCH;
QFile outputFile; QFile outputFile;
outputFile.setFileName(path.append(".patched")); outputFile.setFileName(outputPath);
if (!outputFile.open(QFile::WriteOnly)) if (!outputFile.open(QFile::WriteOnly))
return ERR_FILE_WRITE; return ERR_FILE_WRITE;

View file

@ -33,9 +33,7 @@ public:
explicit UEFIPatch(QObject *parent = 0); explicit UEFIPatch(QObject *parent = 0);
~UEFIPatch(); ~UEFIPatch();
UINT8 patchFromFile(QString path, QString patches); UINT8 patchFromFile(const QString & path, const QString & patches, const QString & outputPath);
UINT8 patch(QString path, QString fileGuid, QString findPattern, QString replacePattern);
private: private:
UINT8 patchFile(const QModelIndex & index, const QByteArray & fileGuid, const UINT8 sectionType, const QVector<PatchData> & patches); UINT8 patchFile(const QModelIndex & index, const QByteArray & fileGuid, const UINT8 sectionType, const QVector<PatchData> & patches);
FfsEngine* ffsEngine; FfsEngine* ffsEngine;

View file

@ -26,22 +26,34 @@ int main(int argc, char *argv[])
UEFIPatch w; UEFIPatch w;
UINT8 result = ERR_SUCCESS; UINT8 result = ERR_SUCCESS;
UINT32 argumentsCount = a.arguments().length(); const QStringList &args = a.arguments();
UINT32 argumentsCount = args.length();
QString patches = "patches.txt";
if (argumentsCount == 3)
patches = a.arguments().at(2);
if (argumentsCount == 2 || argumentsCount == 3) { if (argumentsCount < 2) {
result = w.patchFromFile(a.arguments().at(1), patches);
}
else {
std::cout << "UEFIPatch 0.3.15 - UEFI image file patching utility" << std::endl << std::endl << 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"; "Patches will be read from patches.txt file by default\n";
return ERR_SUCCESS; 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) { switch (result) {
case ERR_SUCCESS: case ERR_SUCCESS:
std::cout << "Image patched" << std::endl; std::cout << "Image patched" << std::endl;