From 4992474e8364da9cd6807d816687068d20cc3121 Mon Sep 17 00:00:00 2001 From: Kamay Xutax Date: Sat, 19 Aug 2023 22:25:38 +0200 Subject: [PATCH] Fix CPD Extension offset (reverts 29915ca) The CPD Extensions should have the header size added as an offset instead. --- common/ffsparser.cpp | 19 +++++++++++-------- common/ffsparser.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/ffsparser.cpp b/common/ffsparser.cpp index ab85969..6bfbe96 100644 --- a/common/ffsparser.cpp +++ b/common/ffsparser.cpp @@ -4673,10 +4673,13 @@ make_partition_table_consistent: manifestHeader->ExponentSize * (UINT32)sizeof(UINT32), manifestHeader->ExponentSize * (UINT32)sizeof(UINT32)); // Add tree item - UModelIndex partitionIndex = model->addItem(localOffset + header.size() + partitions[i].ptEntry.Offset.Offset, Types::CpdPartition, Subtypes::ManifestCpdPartition, name, UString(), info, header, body, UByteArray(), Fixed, parent); + UModelIndex partitionIndex = model->addItem(localOffset + partitions[i].ptEntry.Offset.Offset, Types::CpdPartition, Subtypes::ManifestCpdPartition, name, UString(), info, header, body, UByteArray(), Fixed, parent); // Parse data as extensions area - parseCpdExtensionsArea(partitionIndex); + // Add the header size as a local offset + // Since the body starts after the + // header length + parseCpdExtensionsArea(partitionIndex, header.size()); } } } @@ -4695,7 +4698,7 @@ make_partition_table_consistent: UModelIndex partitionIndex = model->addItem(localOffset + partitions[i].ptEntry.Offset.Offset, Types::CpdPartition, Subtypes::MetadataCpdPartition, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, parent); // Parse data as extensions area - parseCpdExtensionsArea(partitionIndex); + parseCpdExtensionsArea(partitionIndex, 0); } // It's a code else { @@ -4731,7 +4734,7 @@ make_partition_table_consistent: return U_SUCCESS; } -USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index) +USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index, const UINT32 localOffset) { if (!index.isValid()) { return U_INVALID_PARAMETER; @@ -4772,7 +4775,7 @@ USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index) infoHeader->UsageBitmap[12], infoHeader->UsageBitmap[13], infoHeader->UsageBitmap[14], infoHeader->UsageBitmap[15]); // Add tree item - extIndex = model->addItem(offset, Types::CpdExtension, 0, name, UString(), info, header, data, UByteArray(), Fixed, index); + extIndex = model->addItem(offset + localOffset, Types::CpdExtension, 0, name, UString(), info, header, data, UByteArray(), Fixed, index); parseSignedPackageInfoData(extIndex); } // Parse IFWI Partition Manifest a bit further @@ -4815,7 +4818,7 @@ USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index) + UString("\nPartition hash: ") + UString(hash.toHex().constData()); // Add tree item - extIndex = model->addItem(offset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); + extIndex = model->addItem(offset + localOffset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); if (msgHashSizeMismatch) { msg(usprintf("%s: IFWI Partition Manifest hash size is %u, maximum allowed is %u, truncated", __FUNCTION__, attrHeader->HashSize, (UINT32)sizeof(attrHeader->CompletePartitionHash)), extIndex); } @@ -4840,12 +4843,12 @@ USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index) attrHeader->GlobalModuleId) + UString(hash.toHex().constData()); // Add tree item - extIndex = model->addItem(offset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); + extIndex = model->addItem(offset + localOffset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); } // Parse everything else else { // Add tree item, if needed - extIndex = model->addItem(offset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); + extIndex = model->addItem(offset + localOffset, Types::CpdExtension, 0, name, UString(), info, UByteArray(), partition, UByteArray(), Fixed, index); } // There needs to be a more generic way to do it, but it is fine for now diff --git a/common/ffsparser.h b/common/ffsparser.h index b62367f..5d2d647 100644 --- a/common/ffsparser.h +++ b/common/ffsparser.h @@ -130,7 +130,7 @@ private: USTATUS parseBpdtRegion(const UByteArray & region, const UINT32 localOffset, const UINT32 sbpdtOffsetFixup, const UModelIndex & parent, UModelIndex & index); USTATUS parseCpdRegion(const UByteArray & region, const UINT32 localOffset, const UModelIndex & parent, UModelIndex & index); - USTATUS parseCpdExtensionsArea(const UModelIndex & index); + USTATUS parseCpdExtensionsArea(const UModelIndex & index, const UINT32 localOffset); USTATUS parseSignedPackageInfoData(const UModelIndex & index); USTATUS parseRawArea(const UModelIndex & index);