MPQ_V4: Byteswap header after md5 is verified

This commit is contained in:
GaryOderNichts
2023-01-07 21:53:35 +01:00
parent 646c87e5b7
commit d760fe6d41

View File

@@ -651,7 +651,6 @@ DWORD ConvertMpqHeaderToFormat4(
// Verify header MD5. Header MD5 is calculated from the MPQ header since the 'MPQ\x1A'
// signature until the position of header MD5 at offset 0xC0
BSWAP_TMPQHEADER(pHeader, MPQ_FORMAT_VERSION_4);
// Apparently, Starcraft II only accepts MPQ headers where the MPQ header hash matches
// If MD5 doesn't match, we ignore this offset. We also ignore it if there's no MD5 at all
@@ -660,6 +659,9 @@ DWORD ConvertMpqHeaderToFormat4(
if(!VerifyDataBlockHash(pHeader, MPQ_HEADER_SIZE_V4 - MD5_DIGEST_SIZE, pHeader->MD5_MpqHeader))
return ERROR_FAKE_MPQ_HEADER;
// Byteswap after header MD5 is verified
BSWAP_TMPQHEADER(pHeader, MPQ_FORMAT_VERSION_4);
// HiBlockTable must be 0 for archives under 4GB
if((pHeader->ArchiveSize64 >> 0x20) == 0 && pHeader->HiBlockTablePos64 != 0)
return ERROR_FAKE_MPQ_HEADER;