mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Implement Mac Image parsing support
This commit is contained in:
parent
2e7aa8133a
commit
a01d2c6003
11
common/ffs.h
11
common/ffs.h
@ -27,6 +27,17 @@ extern bool ustringToGuid(const UString& str, EFI_GUID& guid);
|
||||
extern UString fileTypeToUString(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
|
||||
|
@ -133,6 +133,12 @@ USTATUS FfsParser::performFirstPass(const UByteArray & buffer, UModelIndex & ind
|
||||
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
|
||||
result = parseIntelImage(buffer, 0, UModelIndex(), index);
|
||||
if (result != U_ITEM_NOT_FOUND) {
|
||||
@ -300,6 +306,37 @@ USTATUS FfsParser::parseCapsule(const UByteArray & capsule, const UINT32 localOf
|
||||
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)
|
||||
{
|
||||
// Check for buffer size to be greater or equal to descriptor region size
|
||||
|
@ -94,6 +94,7 @@ private:
|
||||
USTATUS performFirstPass(const UByteArray & imageFile, 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 parseGenericImage(const UByteArray & intelImage, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index);
|
||||
|
||||
|
@ -110,6 +110,9 @@ UString itemSubtypeToUString(const UINT8 type, const UINT8 subtype)
|
||||
if (subtype == Subtypes::UefiCapsule) return UString("UEFI 2.0");
|
||||
if (subtype == Subtypes::ToshibaCapsule) return UString("Toshiba");
|
||||
break;
|
||||
case Types::MacImage:
|
||||
if (subtype == Subtypes::MacGenericImage) return UString("Mac 1.0");
|
||||
break;
|
||||
case Types::Region: return regionTypeToUString(subtype);
|
||||
case Types::File: return fileTypeToUString(subtype);
|
||||
case Types::Section: return sectionTypeToUString(subtype);
|
||||
@ -216,4 +219,4 @@ UString fitEntryTypeToUString(const UINT8 type)
|
||||
}
|
||||
|
||||
return UString("Unknown");
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ namespace Types {
|
||||
enum ItemTypes {
|
||||
Root = 60,
|
||||
Capsule,
|
||||
MacImage,
|
||||
Image,
|
||||
Region,
|
||||
Padding,
|
||||
@ -88,8 +89,12 @@ namespace Subtypes {
|
||||
ToshibaCapsule
|
||||
};
|
||||
|
||||
enum MacImageSubtypes {
|
||||
MacGenericImage = 110,
|
||||
};
|
||||
|
||||
enum VolumeSubtypes {
|
||||
UnknownVolume = 110,
|
||||
UnknownVolume = 120,
|
||||
Ffs2Volume,
|
||||
Ffs3Volume,
|
||||
NvramVolume,
|
||||
@ -116,13 +121,13 @@ namespace Subtypes {
|
||||
};
|
||||
|
||||
enum PaddingSubtypes {
|
||||
ZeroPadding = 120,
|
||||
ZeroPadding = 130,
|
||||
OnePadding,
|
||||
DataPadding
|
||||
};
|
||||
|
||||
enum NvarEntrySubtypes {
|
||||
InvalidNvarEntry = 130,
|
||||
InvalidNvarEntry = 140,
|
||||
InvalidLinkNvarEntry,
|
||||
LinkNvarEntry,
|
||||
DataNvarEntry,
|
||||
@ -130,7 +135,7 @@ namespace Subtypes {
|
||||
};
|
||||
|
||||
enum VssEntrySubtypes {
|
||||
InvalidVssEntry = 140,
|
||||
InvalidVssEntry = 150,
|
||||
StandardVssEntry,
|
||||
AppleVssEntry,
|
||||
AuthVssEntry,
|
||||
@ -138,12 +143,12 @@ namespace Subtypes {
|
||||
};
|
||||
|
||||
enum FsysEntrySubtypes {
|
||||
InvalidFsysEntry = 150,
|
||||
InvalidFsysEntry = 160,
|
||||
NormalFsysEntry
|
||||
};
|
||||
|
||||
enum EvsaEntrySubtypes {
|
||||
InvalidEvsaEntry = 160,
|
||||
InvalidEvsaEntry = 170,
|
||||
UnknownEvsaEntry,
|
||||
GuidEvsaEntry,
|
||||
NameEvsaEntry,
|
||||
@ -151,39 +156,39 @@ namespace Subtypes {
|
||||
};
|
||||
|
||||
enum FlashMapEntrySubtypes {
|
||||
VolumeFlashMapEntry = 170,
|
||||
VolumeFlashMapEntry = 180,
|
||||
DataFlashMapEntry
|
||||
};
|
||||
|
||||
enum MicrocodeSubtypes {
|
||||
IntelMicrocode = 180,
|
||||
IntelMicrocode = 190,
|
||||
AmdMicrocode
|
||||
};
|
||||
|
||||
enum SlicDataSubtypes {
|
||||
PubkeySlicData = 190,
|
||||
PubkeySlicData = 200,
|
||||
MarkerSlicData
|
||||
};
|
||||
|
||||
// ME-specific
|
||||
enum IfwiPartitionSubtypes {
|
||||
DataIfwiPartition = 200,
|
||||
DataIfwiPartition = 210,
|
||||
BootIfwiPartition
|
||||
};
|
||||
|
||||
enum FptEntrySubtypes {
|
||||
ValidFptEntry = 210,
|
||||
ValidFptEntry = 220,
|
||||
InvalidFptEntry
|
||||
};
|
||||
|
||||
enum FptPartitionSubtypes {
|
||||
CodeFptPartition = 220,
|
||||
CodeFptPartition = 230,
|
||||
DataFptPartition,
|
||||
GlutFptPartition
|
||||
};
|
||||
|
||||
enum CpdPartitionSubtypes {
|
||||
ManifestCpdPartition = 230,
|
||||
ManifestCpdPartition = 240,
|
||||
MetadataCpdPartition,
|
||||
KeyCpdPartition,
|
||||
CodeCpdPartition
|
||||
|
Loading…
Reference in New Issue
Block a user