diff --git a/ffs.h b/ffs.h index 64bb296..620183d 100644 --- a/ffs.h +++ b/ffs.h @@ -305,6 +305,10 @@ extern const UINT8 ffsAlignmentTable[]; const QByteArray EFI_FFS_VOLUME_TOP_FILE_GUID ("\x2E\x06\xA0\x1B\x79\xC7\x82\x45\x85\x66\x33\x6A\xE8\xF7\x8F\x09", 16); +// Pad file GUID +const QByteArray EFI_FFS_PAD_FILE_GUID +("\x85\x65\x53\xE4\x09\x79\x60\x4A\xB5\xC6\xEC\xDE\xA6\xEB\xFB\x54", 16); + // FFS size conversion routines extern VOID uint32ToUint24(UINT32 size, UINT8* ffsSize); extern UINT32 uint24ToUint32(UINT8* ffsSize); diff --git a/ffsengine.cpp b/ffsengine.cpp index f6fd3fd..14293bc 100644 --- a/ffsengine.cpp +++ b/ffsengine.cpp @@ -25,7 +25,7 @@ WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "LZMA/LzmaDecompress.h" FfsEngine::FfsEngine(QObject *parent) - : QObject(parent) +: QObject(parent) { model = new TreeModel(); } @@ -753,7 +753,7 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co // Check file size to be at least size of EFI_FFS_FILE_HEADER if (fileSize < sizeof(EFI_FFS_FILE_HEADER)) { - msg(tr("parseVolume: File with invalid size"), index); + msg(tr("parseVolume: FFS file with invalid size"), index); return ERR_INVALID_FILE; } @@ -774,7 +774,7 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co // Check file GUID if (fileHeader->Type != EFI_FV_FILETYPE_PAD && files.indexOf(header.left(sizeof(EFI_GUID))) != -1) - msg(tr("%1: file with duplicate GUID").arg(guidToQString(fileHeader->Name)), index); + msg(tr("parseVolume: %1, file with duplicate GUID").arg(guidToQString(fileHeader->Name)), index); // Add file GUID to queue files.enqueue(header.left(sizeof(EFI_GUID))); @@ -783,7 +783,7 @@ UINT8 FfsEngine::parseVolume(const QByteArray & volume, QModelIndex & index, co QModelIndex fileIndex; result = parseFile(file, fileIndex, empty == '\xFF' ? ERASE_POLARITY_TRUE : ERASE_POLARITY_FALSE, index); if (result) - msg(tr("parseVolume: Parse FFS file failed (%1)").arg(result), index); + msg(tr("parseVolume: FFS file parse failed (%1)").arg(result), index); // Move to next file fileOffset += fileSize; @@ -1826,12 +1826,13 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA } // Construction routines -UINT8 FfsEngine::constructPadFile(const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad) +UINT8 FfsEngine::constructPadFile(const QByteArray guid, const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad) { if (size < sizeof(EFI_FFS_FILE_HEADER) || erasePolarity == ERASE_POLARITY_UNKNOWN) return ERR_INVALID_PARAMETER; - pad = QByteArray(size, erasePolarity == ERASE_POLARITY_TRUE ? '\xFF' : '\x00'); + pad = QByteArray(size - guid.size(), erasePolarity == ERASE_POLARITY_TRUE ? '\xFF' : '\x00'); + pad.prepend(guid); EFI_FFS_FILE_HEADER* header = (EFI_FFS_FILE_HEADER*) pad.data(); uint32ToUint24(size, header->Size); header->Attributes = 0x00; @@ -2121,6 +2122,7 @@ out: // Reconstruct files in volume UINT32 offset = 0; + QByteArray padFileGuid = EFI_FFS_PAD_FILE_GUID; QByteArray vtf; QModelIndex vtfIndex; for (int i = 0; i < model->rowCount(index); i++) { @@ -2147,9 +2149,11 @@ out: EFI_FFS_FILE_HEADER* fileHeader = (EFI_FFS_FILE_HEADER*) file.data(); // Pad file - if (fileHeader->Type == EFI_FV_FILETYPE_PAD) + if (fileHeader->Type == EFI_FV_FILETYPE_PAD) { + padFileGuid = file.left(sizeof(EFI_GUID)); continue; - + } + // Volume Top File if (file.left(sizeof(EFI_GUID)) == EFI_FFS_VOLUME_TOP_FILE_GUID) { vtf = file; @@ -2174,7 +2178,7 @@ out: } // Construct pad file QByteArray pad; - result = constructPadFile(size, volumeHeader->Revision, polarity, pad); + result = constructPadFile(padFileGuid, size, volumeHeader->Revision, polarity, pad); if (result) return result; // Append constructed pad file to volume body @@ -2205,7 +2209,7 @@ out: UINT32 size = vtfOffset - offset; // Construct pad file QByteArray pad; - result = constructPadFile(size, volumeHeader->Revision, polarity, pad); + result = constructPadFile(padFileGuid, size, volumeHeader->Revision, polarity, pad); if (result) return result; // Append constructed pad file to volume body diff --git a/ffsengine.h b/ffsengine.h index 15e2f9a..4ae06df 100644 --- a/ffsengine.h +++ b/ffsengine.h @@ -98,7 +98,7 @@ private: UINT8 getSectionSize(const QByteArray & file, const UINT32 sectionOffset, UINT32 & sectionSize); // Reconstruction helpers - UINT8 constructPadFile(const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad); + UINT8 constructPadFile(const QByteArray guid, const UINT32 size, const UINT8 revision, const UINT8 erasePolarity, QByteArray & pad); UINT8 growVolume(QByteArray & header, const UINT32 size, UINT32 & newSize); // Rebase routines diff --git a/uefitool.ui b/uefitool.ui index a71205d..0d7e241 100644 --- a/uefitool.ui +++ b/uefitool.ui @@ -20,7 +20,7 @@ true - UEFITool 0.17.1 + UEFITool 0.17.2