From 1e1d5c6e176f736cb9e2e793af5371ad29ea619e Mon Sep 17 00:00:00 2001 From: vit9696 Date: Sat, 17 Aug 2019 14:58:08 +0300 Subject: [PATCH] Add hack for broken NVRAM store sizes in Apple images --- common/ffsparser.cpp | 13 ++++++++++++- common/nvram.h | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index f4b54cf..972a72b 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -1010,7 +1010,7 @@ USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 loc return U_INVALID_PARAMETER; // Check that there is space for the volume header - if ((UINT32)volume.size() < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) { + if ((UINT32)volume.size() < sizeof(EFI_FIRMWARE_VOLUME_HEADER)) { msg(usprintf("%s: input volume size %Xh (%u) is smaller than volume header size 40h (64)", __FUNCTION__, volume.size(), volume.size())); return U_INVALID_VOLUME; } @@ -1279,6 +1279,17 @@ USTATUS FfsParser::findNextRawAreaItem(const UModelIndex & index, const UINT32 l nextItemType = Types::Volume; nextItemSize = (UINT32)volumeHeader->FvLength; nextItemOffset = offset - EFI_FV_SIGNATURE_OFFSET; + + // Hack for Apple images with an extra zero typo in NVRAM volume size. + uint32_t appleWrongSize = 0x2F0000; + uint32_t appleRightSize = 0x2EFC0; + if ((volumeHeader->FvLength == appleWrongSize) + && UByteArray((const char *)&volumeHeader->FileSystemGuid, sizeof(EFI_GUID)) == NVRAM_MAIN_STORE_VOLUME_GUID + && UByteArray((const char *)volumeHeader + appleRightSize + sizeof(EFI_GUID), sizeof(EFI_GUID)) == APPLE_UNKNOWN_STORE_VOLUME_GUID) { + msg(usprintf("%s: hack, fixing up NVRAM volume size from %Xh to %Xh", __FUNCTION__, volumeHeader->FvLength, appleRightSize), index); + nextItemSize = appleRightSize; + } + break; } } diff --git a/common/nvram.h b/common/nvram.h index 74d9126..a234f12 100755 --- a/common/nvram.h +++ b/common/nvram.h @@ -84,6 +84,10 @@ const UByteArray NVRAM_MAIN_STORE_VOLUME_GUID const UByteArray NVRAM_ADDITIONAL_STORE_VOLUME_GUID ("\x24\x46\x50\x00\x59\x8A\xEB\x4E\xBD\x0F\x6B\x36\xE9\x61\x28\xE0", 16); +// TODO: Explore +const UByteArray APPLE_UNKNOWN_STORE_VOLUME_GUID +("\xE4\x0E\x81\x0A\x93\xBF\x59\x4B\xDD\xBC\xA2\x9D\xB4\x4B\x4A\x95", 16); + #define NVRAM_VSS_STORE_SIGNATURE 0x53535624 // $VSS #define NVRAM_APPLE_SVS_STORE_SIGNATURE 0x53565324 // $SVS #define NVRAM_APPLE_NSS_STORE_SIGNATURE 0x53534E24 // $NSS