Implement Mac Image parsing support

This commit is contained in:
vit9696 2019-08-17 13:22:32 +03:00
parent 2e7aa8133a
commit a01d2c6003
5 changed files with 71 additions and 14 deletions

View File

@ -27,6 +27,17 @@ 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;
UINT8 Unknown[0x100 - sizeof (UINT64)];
} 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,6 +133,12 @@ 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) {
@ -300,6 +306,37 @@ 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)) {
UByteArray header = macImage.left(sizeof(MAC_IMAGE_HEADER));
UByteArray body = macImage.mid(sizeof(MAC_IMAGE_HEADER));
UString name("Mac image");
// Add tree item
index = model->addItem(localOffset, Types::MacImage, Subtypes::MacGenericImage, name, UString(), UString(), header, body, UByteArray(), Fixed, parent);
UModelIndex imageIndex;
// Try parsing as Intel image
USTATUS result = parseIntelImage(body, sizeof(MAC_IMAGE_HEADER), index, imageIndex);
if (result != U_ITEM_NOT_FOUND) {
return result;
}
// Parse as generic image
return parseGenericImage(body, 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

View File

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

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