mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-29 11:28:22 +08:00
Support replacing raw sections and ffs via -asis
This commit is contained in:
parent
2cfbb74465
commit
81766136cd
@ -25,7 +25,7 @@ UEFIReplace::~UEFIReplace()
|
||||
delete ffsEngine;
|
||||
}
|
||||
|
||||
UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, const UINT8 sectionType, const QString & contentPath, const QString & outPath, bool replaceOnce)
|
||||
UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, const UINT8 sectionType, const QString & contentPath, const QString & outPath, bool replaceAsIs, bool replaceOnce)
|
||||
{
|
||||
QFileInfo fileInfo = QFileInfo(inPath);
|
||||
if (!fileInfo.exists())
|
||||
@ -57,7 +57,8 @@ UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, cons
|
||||
QByteArray contents = contentFile.readAll();
|
||||
contentFile.close();
|
||||
|
||||
result = replaceInFile(model->index(0, 0), guid, sectionType, contents, replaceOnce);
|
||||
result = replaceInFile(model->index(0, 0), guid, sectionType, contents,
|
||||
replaceAsIs ? REPLACE_MODE_AS_IS : REPLACE_MODE_BODY, replaceOnce);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
@ -80,21 +81,24 @@ UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, cons
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & newData, bool replaceOnce)
|
||||
UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & newData, const UINT8 mode, bool replaceOnce)
|
||||
{
|
||||
if (!model || !index.isValid())
|
||||
return ERR_INVALID_PARAMETER;
|
||||
bool patched = false;
|
||||
if (model->subtype(index) == sectionType) {
|
||||
QModelIndex fileIndex = model->findParentOfType(index, Types::File);
|
||||
QModelIndex fileIndex = index;
|
||||
if (model->type(index) != Types::File)
|
||||
fileIndex = model->findParentOfType(index, Types::File);
|
||||
QByteArray fileGuid = model->header(fileIndex).left(sizeof(EFI_GUID));
|
||||
|
||||
bool guidMatch = fileGuid == guid;
|
||||
if (!guidMatch && sectionType == EFI_SECTION_FREEFORM_SUBTYPE_GUID) {
|
||||
QByteArray subGuid = model->header(index).mid(sizeof(uint32_t), sizeof(EFI_GUID));
|
||||
QByteArray subGuid = model->header(index).mid(sizeof(UINT32), sizeof(EFI_GUID));
|
||||
guidMatch = subGuid == guid;
|
||||
}
|
||||
if (guidMatch && model->action(index) != Actions::Replace) {
|
||||
UINT8 result = ffsEngine->replace(index, newData, REPLACE_MODE_BODY);
|
||||
UINT8 result = ffsEngine->replace(index, newData, mode);
|
||||
if (replaceOnce || (result != ERR_SUCCESS && result != ERR_NOTHING_TO_PATCH))
|
||||
return result;
|
||||
patched = result == ERR_SUCCESS;
|
||||
@ -103,7 +107,7 @@ UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & g
|
||||
|
||||
if (model->rowCount(index) > 0) {
|
||||
for (int i = 0; i < model->rowCount(index); i++) {
|
||||
UINT8 result = replaceInFile(index.child(i, 0), guid, sectionType, newData, replaceOnce);
|
||||
UINT8 result = replaceInFile(index.child(i, 0), guid, sectionType, newData, mode, replaceOnce);
|
||||
if (result == ERR_SUCCESS) {
|
||||
patched = true;
|
||||
if (replaceOnce)
|
||||
|
@ -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, const QString & outPath, bool replaceOnce);
|
||||
UINT8 replace(const QString & inPath, const QByteArray & guid, const UINT8 sectionType, const QString & contentPath, const QString & outPath, bool replaceAsIs, bool replaceOnce);
|
||||
|
||||
private:
|
||||
UINT8 replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & contents, bool replaceOnce);
|
||||
UINT8 replaceInFile(const QModelIndex & index, const QByteArray & guid, const UINT8 sectionType, const QByteArray & contents, const UINT8 mode, 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 [-o output] [-all]" << std::endl;
|
||||
"Usage: UEFIReplace image_file guid section_type contents_file [-o output] [-all] [-asis]" << std::endl;
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
@ -42,18 +42,21 @@ int main(int argc, char *argv[])
|
||||
} else {
|
||||
QString output = args.at(1) + ".patched";
|
||||
bool replaceOnce = true;
|
||||
bool replaceAsIs = false;
|
||||
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 if (args.at(i) == "-asis") {
|
||||
replaceAsIs = true;
|
||||
} else {
|
||||
result = ERR_INVALID_PARAMETER;
|
||||
}
|
||||
}
|
||||
if (result == ERR_SUCCESS) {
|
||||
result = r.replace(args.at(1), guid, sectionType, args.at(4), output, replaceOnce);
|
||||
result = r.replace(args.at(1), guid, sectionType, args.at(4), output, replaceAsIs, replaceOnce);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user