mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-06-01 07:48:22 -04:00
Support replacing raw sections and ffs via -asis
This commit is contained in:
parent
e5d868977e
commit
8ea96ffd5d
3 changed files with 18 additions and 11 deletions
|
@ -25,7 +25,7 @@ UEFIReplace::~UEFIReplace()
|
||||||
delete ffsEngine;
|
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);
|
QFileInfo fileInfo = QFileInfo(inPath);
|
||||||
if (!fileInfo.exists())
|
if (!fileInfo.exists())
|
||||||
|
@ -57,7 +57,8 @@ UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, cons
|
||||||
QByteArray contents = contentFile.readAll();
|
QByteArray contents = contentFile.readAll();
|
||||||
contentFile.close();
|
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)
|
if (result)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
@ -80,21 +81,24 @@ UINT8 UEFIReplace::replace(const QString & inPath, const QByteArray & guid, cons
|
||||||
return ERR_SUCCESS;
|
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())
|
if (!model || !index.isValid())
|
||||||
return ERR_INVALID_PARAMETER;
|
return ERR_INVALID_PARAMETER;
|
||||||
bool patched = false;
|
bool patched = false;
|
||||||
if (model->subtype(index) == sectionType) {
|
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));
|
QByteArray fileGuid = model->header(fileIndex).left(sizeof(EFI_GUID));
|
||||||
|
|
||||||
bool guidMatch = fileGuid == guid;
|
bool guidMatch = fileGuid == guid;
|
||||||
if (!guidMatch && sectionType == EFI_SECTION_FREEFORM_SUBTYPE_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;
|
guidMatch = subGuid == guid;
|
||||||
}
|
}
|
||||||
if (guidMatch && model->action(index) != Actions::Replace) {
|
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))
|
if (replaceOnce || (result != ERR_SUCCESS && result != ERR_NOTHING_TO_PATCH))
|
||||||
return result;
|
return result;
|
||||||
patched = result == ERR_SUCCESS;
|
patched = result == ERR_SUCCESS;
|
||||||
|
@ -103,7 +107,7 @@ UINT8 UEFIReplace::replaceInFile(const QModelIndex & index, const QByteArray & g
|
||||||
|
|
||||||
if (model->rowCount(index) > 0) {
|
if (model->rowCount(index) > 0) {
|
||||||
for (int i = 0; i < model->rowCount(index); i++) {
|
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) {
|
if (result == ERR_SUCCESS) {
|
||||||
patched = true;
|
patched = true;
|
||||||
if (replaceOnce)
|
if (replaceOnce)
|
||||||
|
|
|
@ -30,10 +30,10 @@ public:
|
||||||
explicit UEFIReplace(QObject *parent = 0);
|
explicit UEFIReplace(QObject *parent = 0);
|
||||||
~UEFIReplace();
|
~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:
|
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;
|
FfsEngine* ffsEngine;
|
||||||
TreeModel* model;
|
TreeModel* model;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (args.length() < 5) {
|
if (args.length() < 5) {
|
||||||
std::cout << "UEFIReplace 0.1.3 - UEFI image file replacement utility" << std::endl << std::endl <<
|
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;
|
return ERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,18 +42,21 @@ int main(int argc, char *argv[])
|
||||||
} else {
|
} else {
|
||||||
QString output = args.at(1) + ".patched";
|
QString output = args.at(1) + ".patched";
|
||||||
bool replaceOnce = true;
|
bool replaceOnce = true;
|
||||||
|
bool replaceAsIs = false;
|
||||||
for (int i = 5, sz = args.size(); i < sz; i++) {
|
for (int i = 5, sz = args.size(); i < sz; i++) {
|
||||||
if ((args.at(i) == "-o" || args.at(i) == "--output") && i + 1 < sz) {
|
if ((args.at(i) == "-o" || args.at(i) == "--output") && i + 1 < sz) {
|
||||||
output = args.at(i+1);
|
output = args.at(i+1);
|
||||||
i++;
|
i++;
|
||||||
} else if (args.at(i) == "-all") {
|
} else if (args.at(i) == "-all") {
|
||||||
replaceOnce = false;
|
replaceOnce = false;
|
||||||
|
} else if (args.at(i) == "-asis") {
|
||||||
|
replaceAsIs = true;
|
||||||
} else {
|
} else {
|
||||||
result = ERR_INVALID_PARAMETER;
|
result = ERR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == ERR_SUCCESS) {
|
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…
Add table
Add a link
Reference in a new issue