mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-21 10:45:24 -04:00
Support applying patches from terminal, closes #186
This commit is contained in:
parent
4bee991c94
commit
31ccb2a054
4 changed files with 98 additions and 3 deletions
|
@ -121,6 +121,86 @@ UINT8 UEFIPatch::patchFromFile(const QString & path, const QString & patches, co
|
|||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 UEFIPatch::patchFromArg(const QString & path, const QString & patch, const QString & outputPath)
|
||||
{
|
||||
QFileInfo fileInfo = QFileInfo(path);
|
||||
|
||||
if (!fileInfo.exists())
|
||||
return ERR_FILE_OPEN;
|
||||
|
||||
QFile inputFile;
|
||||
inputFile.setFileName(path);
|
||||
|
||||
if (!inputFile.open(QFile::ReadOnly))
|
||||
return ERR_FILE_READ;
|
||||
|
||||
QByteArray buffer = inputFile.readAll();
|
||||
inputFile.close();
|
||||
|
||||
UINT8 result = ffsEngine->parseImageFile(buffer);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (patch != nullptr && !patch.isEmpty()) {
|
||||
QByteArray line = patch.toUtf8();
|
||||
|
||||
QList<QByteArray> list = line.split(' ');
|
||||
if (list.count() < 3)
|
||||
return ERR_INVALID_PARAMETER;
|
||||
|
||||
QUuid uuid = QUuid(list.at(0));
|
||||
QByteArray guid = QByteArray::fromRawData((const char*)&uuid.data1, sizeof(EFI_GUID));
|
||||
bool converted;
|
||||
UINT8 sectionType = (UINT8)list.at(1).toUShort(&converted, 16);
|
||||
if (!converted)
|
||||
return ERR_INVALID_PARAMETER;
|
||||
|
||||
QVector<PatchData> patches;
|
||||
|
||||
for (int i = 2; i < list.count(); i++) {
|
||||
QList<QByteArray> patchList = list.at(i).split(':');
|
||||
PatchData patch;
|
||||
patch.type = *(UINT8*)patchList.at(0).constData();
|
||||
if (patch.type == PATCH_TYPE_PATTERN) {
|
||||
patch.offset = 0xFFFFFFFF;
|
||||
patch.hexFindPattern = patchList.at(1);
|
||||
patch.hexReplacePattern = patchList.at(2);
|
||||
patches.append(patch);
|
||||
}
|
||||
else if (patch.type == PATCH_TYPE_OFFSET) {
|
||||
patch.offset = patchList.at(1).toUInt(NULL, 16);
|
||||
patch.hexReplacePattern = patchList.at(2);
|
||||
patches.append(patch);
|
||||
}
|
||||
else {
|
||||
// Ignore unknown patch type
|
||||
continue;
|
||||
}
|
||||
}
|
||||
result = patchFile(model->index(0, 0), guid, sectionType, patches);
|
||||
if (result && result != ERR_NOTHING_TO_PATCH)
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray reconstructed;
|
||||
result = ffsEngine->reconstructImageFile(reconstructed);
|
||||
if (result)
|
||||
return result;
|
||||
if (reconstructed == buffer)
|
||||
return ERR_NOTHING_TO_PATCH;
|
||||
|
||||
QFile outputFile;
|
||||
outputFile.setFileName(outputPath);
|
||||
if (!outputFile.open(QFile::WriteOnly))
|
||||
return ERR_FILE_WRITE;
|
||||
|
||||
outputFile.resize(0);
|
||||
outputFile.write(reconstructed);
|
||||
outputFile.close();
|
||||
|
||||
return ERR_SUCCESS;
|
||||
}
|
||||
|
||||
UINT8 UEFIPatch::patchFile(const QModelIndex & index, const QByteArray & fileGuid, const UINT8 sectionType, const QVector<PatchData> & patches)
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue