From d760fe6d41d6a9403c7e80d4a69f8808bdd29c25 Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Sat, 7 Jan 2023 21:53:35 +0100 Subject: MPQ_V4: Byteswap header after md5 is verified --- src/SBaseFileTable.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SBaseFileTable.cpp b/src/SBaseFileTable.cpp index a579fbd..2fd717b 100644 --- a/src/SBaseFileTable.cpp +++ b/src/SBaseFileTable.cpp @@ -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; -- cgit v1.2.3