Remove mac image parsing as it breaks GUI navigation

Use MacEfiUnpack utility to expand the images prior to using UEFITool:
https://github.com/acidanthera/OcSupportPkg/tree/master/Utilities/MacEfiUnpack
This commit is contained in:
vit9696 2019-08-18 03:40:37 +03:00
parent 1e1d5c6e17
commit fa954394cc
6 changed files with 15 additions and 115 deletions

View File

@ -27,27 +27,6 @@ extern bool ustringToGuid(const UString& str, EFI_GUID& guid);
extern UString fileTypeToUString(const UINT8 type); extern UString fileTypeToUString(const UINT8 type);
extern UString sectionTypeToUString(const UINT8 type); extern UString sectionTypeToUString(const UINT8 type);
//*****************************************************************************
// Mac Image
//*****************************************************************************
typedef struct MAC_IMAGE_HEADER_ {
UINT64 Magic; // _MEFIBIN
UINT32 FirstImage; // 0x00000000
UINT32 SecondImage; // 0x00080000
// Region numbers?
UINT32 Unk1; // 1
UINT32 Unk2; // 0/4/5
UINT32 Unk3; // 2/7
// Region image choices?
UINT32 UnkOff1; // 0x00080000
UINT32 UnkOff2; // 0x00080000
UINT32 UnkOff3; // 0x0
UINT8 Zero[0x100 - sizeof (UINT64) - sizeof (UINT32)*8];
} MAC_IMAGE_HEADER;
// Mac Image magic
const UByteArray MAC_IMAGE_MAGIC
("\x5F\x4D\x45\x46\x49\x42\x49\x4E", 8);
//***************************************************************************** //*****************************************************************************
// EFI Capsule // EFI Capsule

View File

@ -133,12 +133,6 @@ USTATUS FfsParser::performFirstPass(const UByteArray & buffer, UModelIndex & ind
return result; return result;
} }
// Try parsing as Mac EFI
result = parseMacImage(buffer, 0, UModelIndex(), index);;
if (result != U_ITEM_NOT_FOUND) {
return result;
}
// Try parsing as Intel image // Try parsing as Intel image
result = parseIntelImage(buffer, 0, UModelIndex(), index); result = parseIntelImage(buffer, 0, UModelIndex(), index);
if (result != U_ITEM_NOT_FOUND) { if (result != U_ITEM_NOT_FOUND) {
@ -306,55 +300,6 @@ USTATUS FfsParser::parseCapsule(const UByteArray & capsule, const UINT32 localOf
return U_ITEM_NOT_FOUND; return U_ITEM_NOT_FOUND;
} }
USTATUS FfsParser::parseMacImage(const UByteArray & macImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index)
{
// Check buffer size to be more than or equal to size of MAC_IMAGE_HEADER
if ((UINT32)macImage.size() < sizeof(MAC_IMAGE_HEADER)) {
return U_ITEM_NOT_FOUND;
}
// Check buffer for being normal Mac Image header
if (macImage.startsWith(MAC_IMAGE_MAGIC)) {
// Get info
const MAC_IMAGE_HEADER* macImageHeader = (const MAC_IMAGE_HEADER*)macImage.constData();
if (macImageHeader->FirstImage >= macImage.size() - sizeof(MAC_IMAGE_HEADER)
|| macImageHeader->SecondImage >= macImage.size() - sizeof(MAC_IMAGE_HEADER)
|| macImageHeader->FirstImage >= macImageHeader->SecondImage) {
msg(usprintf("%s: unsupported image combination %Xh %Xh", __FUNCTION__, macImageHeader->FirstImage, macImageHeader->SecondImage));
return U_INVALID_FLASH_DESCRIPTOR;
}
UByteArray header = macImage.left(sizeof(MAC_IMAGE_HEADER));
UByteArray fullBody = macImage.mid(sizeof(MAC_IMAGE_HEADER));
UByteArray firstBody = macImage.mid(sizeof(MAC_IMAGE_HEADER) + macImageHeader->FirstImage, macImageHeader->SecondImage);
UByteArray secondBody = macImage.mid(sizeof(MAC_IMAGE_HEADER) + macImageHeader->SecondImage);
UString name("Mac image");
UString info = usprintf("Mac image:\nFirst image: %Xh\nSecond image: %08Xh",
macImageHeader->FirstImage, macImageHeader->SecondImage);
// Add tree item
index = model->addItem(localOffset, Types::MacImage, Subtypes::MacGenericImage, name, UString(), info, header, fullBody, UByteArray(), Fixed, parent);
UModelIndex imageIndex;
// Try parsing as Intel image
USTATUS result = parseIntelImage(firstBody, sizeof(MAC_IMAGE_HEADER) + macImageHeader->FirstImage, index, imageIndex);
if (result == U_SUCCESS) {
result = parseIntelImage(secondBody, sizeof(MAC_IMAGE_HEADER) + macImageHeader->SecondImage, index, imageIndex);
}
if (result != U_ITEM_NOT_FOUND) {
return result;
}
// Parse as generic image
return parseGenericImage(fullBody, sizeof(MAC_IMAGE_HEADER), index, imageIndex);
}
return U_ITEM_NOT_FOUND;
}
USTATUS FfsParser::parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index) USTATUS FfsParser::parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index)
{ {
// Check for buffer size to be greater or equal to descriptor region size // Check for buffer size to be greater or equal to descriptor region size
@ -1279,17 +1224,6 @@ 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

@ -94,7 +94,6 @@ private:
USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index); USTATUS performFirstPass(const UByteArray & imageFile, UModelIndex & index);
USTATUS parseCapsule(const UByteArray & capsule, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseCapsule(const UByteArray & capsule, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseMacImage(const UByteArray & macImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseIntelImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
USTATUS parseGenericImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); USTATUS parseGenericImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);

View File

@ -84,10 +84,6 @@ 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

View File

@ -110,9 +110,6 @@ UString itemSubtypeToUString(const UINT8 type, const UINT8 subtype)
if (subtype == Subtypes::UefiCapsule) return UString("UEFI 2.0"); if (subtype == Subtypes::UefiCapsule) return UString("UEFI 2.0");
if (subtype == Subtypes::ToshibaCapsule) return UString("Toshiba"); if (subtype == Subtypes::ToshibaCapsule) return UString("Toshiba");
break; break;
case Types::MacImage:
if (subtype == Subtypes::MacGenericImage) return UString("Mac 1.0");
break;
case Types::Region: return regionTypeToUString(subtype); case Types::Region: return regionTypeToUString(subtype);
case Types::File: return fileTypeToUString(subtype); case Types::File: return fileTypeToUString(subtype);
case Types::Section: return sectionTypeToUString(subtype); case Types::Section: return sectionTypeToUString(subtype);

View File

@ -36,7 +36,6 @@ namespace Types {
enum ItemTypes { enum ItemTypes {
Root = 60, Root = 60,
Capsule, Capsule,
MacImage,
Image, Image,
Region, Region,
Padding, Padding,
@ -89,12 +88,8 @@ namespace Subtypes {
ToshibaCapsule ToshibaCapsule
}; };
enum MacImageSubtypes {
MacGenericImage = 110,
};
enum VolumeSubtypes { enum VolumeSubtypes {
UnknownVolume = 120, UnknownVolume = 110,
Ffs2Volume, Ffs2Volume,
Ffs3Volume, Ffs3Volume,
NvramVolume, NvramVolume,
@ -121,13 +116,13 @@ namespace Subtypes {
}; };
enum PaddingSubtypes { enum PaddingSubtypes {
ZeroPadding = 130, ZeroPadding = 120,
OnePadding, OnePadding,
DataPadding DataPadding
}; };
enum NvarEntrySubtypes { enum NvarEntrySubtypes {
InvalidNvarEntry = 140, InvalidNvarEntry = 130,
InvalidLinkNvarEntry, InvalidLinkNvarEntry,
LinkNvarEntry, LinkNvarEntry,
DataNvarEntry, DataNvarEntry,
@ -135,7 +130,7 @@ namespace Subtypes {
}; };
enum VssEntrySubtypes { enum VssEntrySubtypes {
InvalidVssEntry = 150, InvalidVssEntry = 140,
StandardVssEntry, StandardVssEntry,
AppleVssEntry, AppleVssEntry,
AuthVssEntry, AuthVssEntry,
@ -143,12 +138,12 @@ namespace Subtypes {
}; };
enum FsysEntrySubtypes { enum FsysEntrySubtypes {
InvalidFsysEntry = 160, InvalidFsysEntry = 150,
NormalFsysEntry NormalFsysEntry
}; };
enum EvsaEntrySubtypes { enum EvsaEntrySubtypes {
InvalidEvsaEntry = 170, InvalidEvsaEntry = 160,
UnknownEvsaEntry, UnknownEvsaEntry,
GuidEvsaEntry, GuidEvsaEntry,
NameEvsaEntry, NameEvsaEntry,
@ -156,39 +151,39 @@ namespace Subtypes {
}; };
enum FlashMapEntrySubtypes { enum FlashMapEntrySubtypes {
VolumeFlashMapEntry = 180, VolumeFlashMapEntry = 170,
DataFlashMapEntry DataFlashMapEntry
}; };
enum MicrocodeSubtypes { enum MicrocodeSubtypes {
IntelMicrocode = 190, IntelMicrocode = 180,
AmdMicrocode AmdMicrocode
}; };
enum SlicDataSubtypes { enum SlicDataSubtypes {
PubkeySlicData = 200, PubkeySlicData = 190,
MarkerSlicData MarkerSlicData
}; };
// ME-specific // ME-specific
enum IfwiPartitionSubtypes { enum IfwiPartitionSubtypes {
DataIfwiPartition = 210, DataIfwiPartition = 200,
BootIfwiPartition BootIfwiPartition
}; };
enum FptEntrySubtypes { enum FptEntrySubtypes {
ValidFptEntry = 220, ValidFptEntry = 210,
InvalidFptEntry InvalidFptEntry
}; };
enum FptPartitionSubtypes { enum FptPartitionSubtypes {
CodeFptPartition = 230, CodeFptPartition = 220,
DataFptPartition, DataFptPartition,
GlutFptPartition GlutFptPartition
}; };
enum CpdPartitionSubtypes { enum CpdPartitionSubtypes {
ManifestCpdPartition = 240, ManifestCpdPartition = 230,
MetadataCpdPartition, MetadataCpdPartition,
KeyCpdPartition, KeyCpdPartition,
CodeCpdPartition CodeCpdPartition