mirror of
https://github.com/LongSoft/UEFITool.git
synced 2024-11-22 07:58:22 +08:00
Use constant offsets instead of 1-byte arrays
This commit is contained in:
parent
fae9d6681d
commit
d9af12b567
@ -753,9 +753,11 @@ typedef struct CPD_EXT_SIGNED_PACKAGE_INFO_MODULE_ {
|
|||||||
UINT8 HashAlgorithm;
|
UINT8 HashAlgorithm;
|
||||||
UINT16 HashSize;
|
UINT16 HashSize;
|
||||||
UINT32 MetadataSize;
|
UINT32 MetadataSize;
|
||||||
UINT8 MetadataHash[1]; // Can be 32 or 48 bit
|
// UINT8 MetadataHash[]; with the actual hash size is 32 or 48 bytes
|
||||||
} CPD_EXT_SIGNED_PACKAGE_INFO_MODULE;
|
} CPD_EXT_SIGNED_PACKAGE_INFO_MODULE;
|
||||||
|
|
||||||
|
static const size_t CpdExtSignedPkgMetadataHashOffset = sizeof(CPD_EXT_SIGNED_PACKAGE_INFO_MODULE);
|
||||||
|
|
||||||
typedef struct CPD_EXT_SIGNED_PACKAGE_INFO_ {
|
typedef struct CPD_EXT_SIGNED_PACKAGE_INFO_ {
|
||||||
UINT32 ExtensionType;
|
UINT32 ExtensionType;
|
||||||
UINT32 ExtensionLength;
|
UINT32 ExtensionLength;
|
||||||
@ -774,9 +776,11 @@ typedef struct CPD_EXT_MODULE_ATTRIBUTES_ {
|
|||||||
UINT32 UncompressedSize;
|
UINT32 UncompressedSize;
|
||||||
UINT32 CompressedSize;
|
UINT32 CompressedSize;
|
||||||
UINT32 GlobalModuleId;
|
UINT32 GlobalModuleId;
|
||||||
UINT8 ImageHash[1]; // The actual hash size is 32 or 48 bytes
|
// UINT8 ImageHash[]; with the actual hash size is 32 or 48 bytes
|
||||||
} CPD_EXT_MODULE_ATTRIBUTES;
|
} CPD_EXT_MODULE_ATTRIBUTES;
|
||||||
|
|
||||||
|
static const size_t CpdExtModuleImageHashOffset = sizeof(CPD_EXT_MODULE_ATTRIBUTES);
|
||||||
|
|
||||||
#define CPD_EXT_MODULE_COMPRESSION_TYPE_UNCOMPRESSED 0
|
#define CPD_EXT_MODULE_COMPRESSION_TYPE_UNCOMPRESSED 0
|
||||||
#define CPD_EXT_MODULE_COMPRESSION_TYPE_HUFFMAN 1
|
#define CPD_EXT_MODULE_COMPRESSION_TYPE_HUFFMAN 1
|
||||||
#define CPD_EXT_MODULE_COMPRESSION_TYPE_LZMA 2
|
#define CPD_EXT_MODULE_COMPRESSION_TYPE_LZMA 2
|
||||||
|
@ -5170,11 +5170,11 @@ USTATUS FfsParser::parseCpdExtensionsArea(const UModelIndex & index)
|
|||||||
// Parse Module Attributes a bit further
|
// Parse Module Attributes a bit further
|
||||||
else if (extHeader->Type == CPD_EXT_TYPE_MODULE_ATTRIBUTES) {
|
else if (extHeader->Type == CPD_EXT_TYPE_MODULE_ATTRIBUTES) {
|
||||||
const CPD_EXT_MODULE_ATTRIBUTES* attrHeader = (const CPD_EXT_MODULE_ATTRIBUTES*)partition.constData();
|
const CPD_EXT_MODULE_ATTRIBUTES* attrHeader = (const CPD_EXT_MODULE_ATTRIBUTES*)partition.constData();
|
||||||
int hashSize = partition.size() - offsetof(CPD_EXT_MODULE_ATTRIBUTES, ImageHash);
|
int hashSize = partition.size() - CpdExtModuleImageHashOffset;
|
||||||
|
|
||||||
// This hash is stored reversed
|
// This hash is stored reversed
|
||||||
// Need to reverse it back to normal
|
// Need to reverse it back to normal
|
||||||
UByteArray hash((const char*)&attrHeader->ImageHash, hashSize);
|
UByteArray hash((const char*)attrHeader + CpdExtModuleImageHashOffset, hashSize);
|
||||||
std::reverse(hash.begin(), hash.end());
|
std::reverse(hash.begin(), hash.end());
|
||||||
|
|
||||||
info = usprintf("Full size: %" PRIXQ "h (%" PRIuQ ")\nType: %Xh\n"
|
info = usprintf("Full size: %" PRIXQ "h (%" PRIuQ ")\nType: %Xh\n"
|
||||||
@ -5226,12 +5226,12 @@ USTATUS FfsParser::parseSignedPackageInfoData(const UModelIndex & index)
|
|||||||
const CPD_EXT_SIGNED_PACKAGE_INFO_MODULE* moduleHeader = (const CPD_EXT_SIGNED_PACKAGE_INFO_MODULE*)(body.constData() + offset);
|
const CPD_EXT_SIGNED_PACKAGE_INFO_MODULE* moduleHeader = (const CPD_EXT_SIGNED_PACKAGE_INFO_MODULE*)(body.constData() + offset);
|
||||||
if (sizeof(CPD_EXT_SIGNED_PACKAGE_INFO_MODULE) <= ((UINT32)body.size() - offset)) {
|
if (sizeof(CPD_EXT_SIGNED_PACKAGE_INFO_MODULE) <= ((UINT32)body.size() - offset)) {
|
||||||
// TODO: check sanity of moduleHeader->HashSize
|
// TODO: check sanity of moduleHeader->HashSize
|
||||||
UByteArray module((const char*)moduleHeader, sizeof(CPD_EXT_SIGNED_PACKAGE_INFO_MODULE) - sizeof(moduleHeader->MetadataHash) + moduleHeader->HashSize);
|
UByteArray module((const char*)moduleHeader, CpdExtSignedPkgMetadataHashOffset + moduleHeader->HashSize);
|
||||||
UString name = usprintf("%.12s", moduleHeader->Name);
|
UString name = usprintf("%.12s", moduleHeader->Name);
|
||||||
|
|
||||||
// This hash is stored reversed
|
// This hash is stored reversed
|
||||||
// Need to reverse it back to normal
|
// Need to reverse it back to normal
|
||||||
UByteArray hash((const char*)&moduleHeader->MetadataHash, moduleHeader->HashSize);
|
UByteArray hash((const char*)moduleHeader + CpdExtSignedPkgMetadataHashOffset, moduleHeader->HashSize);
|
||||||
std::reverse(hash.begin(), hash.end());
|
std::reverse(hash.begin(), hash.end());
|
||||||
|
|
||||||
UString info = usprintf("Full size: %" PRIXQ "h (%" PRIuQ ")\nType: %Xh\nHash algorithm: %Xh\nHash size: %Xh (%u)\nMetadata size: %Xh (%u)\nMetadata hash: ",
|
UString info = usprintf("Full size: %" PRIXQ "h (%" PRIuQ ")\nType: %Xh\nHash algorithm: %Xh\nHash size: %Xh (%u)\nMetadata size: %Xh (%u)\nMetadata hash: ",
|
||||||
|
Loading…
Reference in New Issue
Block a user