mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Add dual mac image parsing support
This commit is contained in:
parent
a01d2c6003
commit
47637ef152
14
common/ffs.h
14
common/ffs.h
@ -31,8 +31,18 @@ extern UString sectionTypeToUString(const UINT8 type);
|
||||
// Mac Image
|
||||
//*****************************************************************************
|
||||
typedef struct MAC_IMAGE_HEADER_ {
|
||||
UINT64 Magic;
|
||||
UINT8 Unknown[0x100 - sizeof (UINT64)];
|
||||
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
|
||||
|
@ -315,23 +315,41 @@ USTATUS FfsParser::parseMacImage(const UByteArray & macImage, const UINT32 local
|
||||
|
||||
// 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 body = macImage.mid(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(), UString(), header, body, UByteArray(), Fixed, parent);
|
||||
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(body, sizeof(MAC_IMAGE_HEADER), index, imageIndex);
|
||||
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(body, sizeof(MAC_IMAGE_HEADER), index, imageIndex);
|
||||
return parseGenericImage(fullBody, sizeof(MAC_IMAGE_HEADER), index, imageIndex);
|
||||
}
|
||||
|
||||
return U_ITEM_NOT_FOUND;
|
||||
|
Loading…
Reference in New Issue
Block a user