mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-02-13 15:22:42 +08:00
Implement replace all and add -o (--output) path to UEFIReplace
This commit is contained in:
parent
8d8f764e01
commit
a9399a0785
3
.gitignore
vendored
3
.gitignore
vendored
@ -235,3 +235,6 @@ UEFIFind/UEFIFind
|
||||
UEFIPatch/UEFIPatch
|
||||
UEFIReplace/UEFIReplace
|
||||
UEFITool
|
||||
.qmake.stash
|
||||
UEFITool.app/
|
||||
uefitool_plugin_import.cpp
|
||||
|
@ -25,7 +25,7 @@ UEFIReplace::~UEFIReplace()
|
||||
delete ffsEngine;
|
||||
}
|
||||
|
||||
UINT8 UEFIReplace::replace(QString inPath, const QByteArray & guid, const UINT8 sectionType, const QString contentPath)
|
||||
UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, const UINT8 sectionType, const QString & contentPath, const QString & outPath, bool replaceOnce)
|
||||
{
|
||||
QFileInfo fileInfo = QFileInfo(inPath);
|
||||
if (!fileInfo.exists())
|
||||
@ -57,7 +57,7 @@ UINT8 UEFIReplace::replace(QString inPath, const QByteArray & guid, const UINT8
|
||||
QByteArray contents = contentFile.readAll();
|
||||
contentFile.close();
|
||||
|
||||
result = replaceInFile(model->index(0, 0), guid, sectionType, contents);
|
||||
result = replaceInFile(model->index(0, 0), guid, sectionType, contents, replaceOnce);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
@ -69,7 +69,7 @@ UINT8 UEFIReplace::replace(QString inPath, const QByteArray & guid, const UINT8
|
||||
return ERR_NOTHING_TO_PATCH;
|
||||
|
||||
QFile outputFile;
|
||||
outputFile.setFileName(inPath.append(".patched"));
|
||||
outputFile.setFileName(outPath);
|
||||
if (!outputFile.open(QFile::WriteOnly))
|
||||
return ERR_FILE_WRITE;
|
||||
|
||||
@ -80,7 +80,7 @@ UINT8 UEFIReplace::replace(QString inPath, const QByteArray & guid, const UINT8
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & newData)
|
||||
UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & newData, bool replaceOnce)
|
||||
{
|
||||
if (!model || !index.isValid())
|
||||
return ERR_INVALID_PARAMETER;
|
||||
@ -88,19 +88,23 @@ UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & g
|
||||
QModelIndex fileIndex = model->findParentOfType(index, Types::File);
|
||||
QByteArray fileGuid = model->header(fileIndex).left(sizeof(EFI_GUID));
|
||||
if (fileGuid == guid) {
|
||||
return ffsEngine->replace(index, newData, REPLACE_MODE_BODY);
|
||||
UINT8 result = ffsEngine->replace(index, newData, REPLACE_MODE_BODY);
|
||||
if (replaceOnce || (result != ERR_SUCCESS && result != ERR_NOTHING_TO_PATCH))
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
bool patched = false;
|
||||
if (model->rowCount(index) > 0) {
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
UINT8 result = replaceInFile(index.child(i, 0), guid, sectionType, newData);
|
||||
if (!result) {
|
||||
UINT8 result = replaceInFile(index.child(i, 0), guid, sectionType, newData, replaceOnce);
|
||||
if (result == ERR_SUCCESS) {
|
||||
patched = true;
|
||||
break;
|
||||
} else if (result != ERR_NOTHING_TO_PATCH)
|
||||
if (replaceOnce)
|
||||
break;
|
||||
} else if (result != ERR_NOTHING_TO_PATCH) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,10 +30,10 @@ public:
|
||||
explicit UEFIReplace(QObject *parent = 0);
|
||||
~UEFIReplace();
|
||||
|
||||
UINT8 replace(const QString inPath, const QByteArray & guid, const UINT8 sectionType, const QString contentPath);
|
||||
UINT8 replace(const QString & inPath, const QByteArray & guid, const UINT8 sectionType, const QString & contentPath, const QString & outPath, bool replaceOnce);
|
||||
|
||||
private:
|
||||
UINT8 replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & contents);
|
||||
UINT8 replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & contents, bool replaceOnce);
|
||||
FfsEngine* ffsEngine;
|
||||
TreeModel* model;
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (args.length() < 5) {
|
||||
std::cout << "UEFIReplace 0.1.3 - UEFI image file replacement utility" << std::endl << std::endl <<
|
||||
"Usage: UEFIReplace image_file guid section_type contents_file" << std::endl;
|
||||
"Usage: UEFIReplace image_file guid section_type contents_file [-o output] [-all]" << std::endl;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
@ -37,10 +37,25 @@ int main(int argc, char *argv[])
|
||||
QByteArray guid = QByteArray::fromRawData((const char*)&uuid.data1, sizeof(EFI_GUID));
|
||||
bool converted;
|
||||
UINT8 sectionType = (UINT8)args.at(3).toUShort(&converted, 16);
|
||||
if (!converted)
|
||||
if (!converted) {
|
||||
result = ERR_INVALID_PARAMETER;
|
||||
else
|
||||
result = r.replace(args.at(1), guid, sectionType, args.at(4));
|
||||
} else {
|
||||
QString output = args.at(1) + ".patched";
|
||||
bool replaceOnce = true;
|
||||
for (int i = 5, sz = args.size(); i < sz; i++) {
|
||||
if ((args.at(i) == "-o" || args.at(i) == "--output") && i + 1 < sz) {
|
||||
output = args.at(i+1);
|
||||
i++;
|
||||
} else if (args.at(i) == "-all") {
|
||||
replaceOnce = false;
|
||||
} else {
|
||||
result = ERR_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
if (result == ERR_SUCCESS) {
|
||||
result = r.replace(args.at(1), guid, sectionType, args.at(4), output, replaceOnce);
|
||||
}
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case ERR_SUCCESS:
|
||||
|
Loading…
Reference in New Issue
Block a user