Add dual mac image parsing support

This commit is contained in:
vit9696 2019-08-17 14:03:23 +03:00
parent a01d2c6003
commit 47637ef152
2 changed files with 34 additions and 6 deletions

View File

@ -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

View File

@ -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;