Add hack for broken NVRAM store sizes in Apple images

This commit is contained in:
vit9696 2019-08-17 14:58:08 +03:00
parent 47637ef152
commit 1e1d5c6e17
2 changed files with 16 additions and 1 deletions

View File

@ -1010,7 +1010,7 @@ USTATUS FfsParser::parseVolumeHeader(const UByteArray & volume, const UINT32 loc
return U_INVALID_PARAMETER; return U_INVALID_PARAMETER;
// Check that there is space for the volume header // 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())); 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; return U_INVALID_VOLUME;
} }
@ -1279,6 +1279,17 @@ USTATUS FfsParser::findNextRawAreaItem(const UModelIndex & index, const UINT32 l
nextItemType = Types::Volume; nextItemType = Types::Volume;
nextItemSize = (UINT32)volumeHeader->FvLength; nextItemSize = (UINT32)volumeHeader->FvLength;
nextItemOffset = offset - EFI_FV_SIGNATURE_OFFSET; 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; break;
} }
} }

View File

@ -84,6 +84,10 @@ const UByteArray NVRAM_MAIN_STORE_VOLUME_GUID
const UByteArray NVRAM_ADDITIONAL_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); ("\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_VSS_STORE_SIGNATURE 0x53535624 // $VSS
#define NVRAM_APPLE_SVS_STORE_SIGNATURE 0x53565324 // $SVS #define NVRAM_APPLE_SVS_STORE_SIGNATURE 0x53565324 // $SVS
#define NVRAM_APPLE_NSS_STORE_SIGNATURE 0x53534E24 // $NSS #define NVRAM_APPLE_NSS_STORE_SIGNATURE 0x53534E24 // $NSS