From 7597fe1702e4f27faf51d201b566139e17ad4342 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Mon, 11 Jul 2016 22:52:11 +0200 Subject: + Yet another protector solved --- src/SBaseCommon.cpp | 15 +++++++++++++++ src/SFileOpenFileEx.cpp | 2 +- test/StormTest.cpp | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/SBaseCommon.cpp b/src/SBaseCommon.cpp index 95bdeb4..5483f55 100644 --- a/src/SBaseCommon.cpp +++ b/src/SBaseCommon.cpp @@ -255,6 +255,21 @@ DWORD HashStringLower(const char * szFileName, DWORD dwHashType) //----------------------------------------------------------------------------- // Calculates the hash table size for a given amount of files +// Returns the nearest higher power of two. +// If the value is already a power of two, returns the same value +//static DWORD GetNearestPowerOfTwo(DWORD dwValue) +//{ +// dwValue --; +// +// dwValue |= dwValue >> 1; +// dwValue |= dwValue >> 2; +// dwValue |= dwValue >> 4; +// dwValue |= dwValue >> 8; +// dwValue |= dwValue >> 16; +// +// return dwValue + 1; +//} + DWORD GetHashTableSizeForFileCount(DWORD dwFileCount) { DWORD dwPowerOfTwo = HASH_TABLE_SIZE_MIN; diff --git a/src/SFileOpenFileEx.cpp b/src/SFileOpenFileEx.cpp index afbfc78..9ce0ae2 100644 --- a/src/SFileOpenFileEx.cpp +++ b/src/SFileOpenFileEx.cpp @@ -30,7 +30,7 @@ static DWORD FindHashIndex(TMPQArchive * ha, DWORD dwFileIndex) pHashTableEnd = ha->pHashTable + ha->pHeader->dwHashTableSize; for(pHash = ha->pHashTable; pHash < pHashTableEnd; pHash++) { - if(pHash->dwBlockIndex == dwFileIndex) + if(MPQ_BLOCK_INDEX(pHash) == dwFileIndex) { // Duplicate hash entry found if(dwFirstIndex != HASH_ENTRY_FREE) diff --git a/test/StormTest.cpp b/test/StormTest.cpp index e19d7c3..2d957b0 100644 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -4405,7 +4405,7 @@ int main(int argc, char * argv[]) // Open a partial MPQ with compressed hash table if(nError == ERROR_SUCCESS) nError = TestOpenArchive("part-file://MPQ_2010_v2_HashTableCompressed.MPQ.part"); -*/ + if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPQ_2002_v1_ProtectedMap_HashTable_FakeValid.w3x"); @@ -4467,6 +4467,9 @@ int main(int argc, char * argv[]) if(nError == ERROR_SUCCESS) nError = TestOpenArchive("MPQ_2016_v1_SP_(4)Adrenaline.w3x"); +*/ + if(nError == ERROR_SUCCESS) + nError = TestOpenArchive("MPQ_2016_v1_ProtectedMap_1.4.w3x"); /* // Open the multi-file archive with wrong prefix to see how StormLib deals with it if(nError == ERROR_SUCCESS) -- cgit v1.2.3