From 706b0088e384f684ba509569ed1b9c35b8ce9bc4 Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Mon, 14 Apr 2014 14:10:08 +0200 Subject: [PATCH] Version 0.17.7 - corrected possible bug with extended volume header handling in growVolume routine --- basetypes.h | 1 + ffsengine.cpp | 17 +++++++++++------ ffsengine.h | 4 ++-- uefitool.ui | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/basetypes.h b/basetypes.h index b564fc7..9bd594e 100644 --- a/basetypes.h +++ b/basetypes.h @@ -82,6 +82,7 @@ typedef uint16_t CHAR16; #define ERR_GENERIC_CALL_NOT_SUPPORTED 32 #define ERR_VOLUME_BASE_NOT_FOUND 33 #define ERR_PEI_CORE_ENTRY_POINT_NOT_FOUND 34 +#define ERR_COMPLEX_BLOCK_MAP 35 #define ERR_NOT_IMPLEMENTED 0xFF // Compression algorithms diff --git a/ffsengine.cpp b/ffsengine.cpp index 179ff82..27e7f54 100644 --- a/ffsengine.cpp +++ b/ffsengine.cpp @@ -40,7 +40,7 @@ TreeModel* FfsEngine::treeModel() const return model; } -void FfsEngine::msg(const QString & message, const QModelIndex index) +void FfsEngine::msg(const QString & message, const QModelIndex & index) { messageItems.enqueue(MessageListItem(message, NULL, 0, index)); } @@ -1848,7 +1848,7 @@ UINT8 FfsEngine::compress(const QByteArray & data, const UINT8 algorithm, QByteA } // Construction routines -UINT8 FfsEngine::constructPadFile(const QByteArray guid, 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; @@ -2690,8 +2690,7 @@ UINT8 FfsEngine::growVolume(QByteArray & header, const UINT32 size, UINT32 & new EFI_FV_BLOCK_MAP_ENTRY* blockMap = (EFI_FV_BLOCK_MAP_ENTRY*) (header.data() + sizeof(EFI_FIRMWARE_VOLUME_HEADER)); // Get block map size - UINT32 extHeaderOffset = volumeHeader->Revision == 2 ? volumeHeader->ExtHeaderOffset : 0; - UINT32 blockMapSize = header.size() - extHeaderOffset - sizeof(EFI_FIRMWARE_VOLUME_HEADER); + UINT32 blockMapSize = volumeHeader->HeaderLength - sizeof(EFI_FIRMWARE_VOLUME_HEADER); if (blockMapSize % sizeof(EFI_FV_BLOCK_MAP_ENTRY)) return ERR_INVALID_VOLUME; UINT32 blockMapCount = blockMapSize / sizeof(EFI_FV_BLOCK_MAP_ENTRY); @@ -2700,13 +2699,19 @@ UINT8 FfsEngine::growVolume(QByteArray & header, const UINT32 size, UINT32 & new if (blockMap[blockMapCount-1].NumBlocks != 0 || blockMap[blockMapCount-1].Length != 0) return ERR_INVALID_VOLUME; + // Case of complex blockMap + //!TODO: implement this case + if (blockMapCount > 2) + return ERR_COMPLEX_BLOCK_MAP; + // Calculate new size if (newSize <= size) return ERR_INVALID_PARAMETER; - newSize += blockMap->Length - newSize % blockMap->Length; + + newSize += blockMap[0].Length - newSize % blockMap[0].Length; // Recalculate number of blocks - blockMap->NumBlocks = newSize / blockMap->Length; + blockMap[0].NumBlocks = newSize / blockMap[0].Length; // Set new volume size volumeHeader->FvLength = 0; diff --git a/ffsengine.h b/ffsengine.h index 92a3ba3..4113efd 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 QByteArray guid, 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 @@ -112,7 +112,7 @@ private: // Message helper QQueue messageItems; - void msg(const QString & message, const QModelIndex index = QModelIndex()); + void msg(const QString & message, const QModelIndex &index = QModelIndex()); // Internal operations bool hasIntersection(const UINT32 begin1, const UINT32 end1, const UINT32 begin2, const UINT32 end2); diff --git a/uefitool.ui b/uefitool.ui index d671e82..ff86839 100644 --- a/uefitool.ui +++ b/uefitool.ui @@ -20,7 +20,7 @@ true - UEFITool 0.17.6 + UEFITool 0.17.7