diff options
author | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-08-27 14:00:15 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avg.com> | 2014-08-27 14:00:15 +0200 |
commit | d740634db4313d7adde780fbd3daae2bb9b9d520 (patch) | |
tree | 6bc23cf6a35a60b76d5d60050d1286e394661cbf /src/SFileOpenArchive.cpp | |
parent | d0e8db518d33913c54b96886808bcf2c1dd683e9 (diff) |
+ Added support for signing MPQ archive (weak signature).v9.10
+ Added test cases for signature support
+ Release 9.10
Diffstat (limited to 'src/SFileOpenArchive.cpp')
-rw-r--r-- | src/SFileOpenArchive.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp index 98d8766..15c395c 100644 --- a/src/SFileOpenArchive.cpp +++ b/src/SFileOpenArchive.cpp @@ -388,7 +388,7 @@ bool WINAPI SFileOpenArchive( // Load the internal listfile and include it to the file table if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_LISTFILE) == 0) { - // Save the flags for (listfile) + // Quick check for (listfile) pFileEntry = GetFileEntryLocale(ha, LISTFILE_NAME, LANG_NEUTRAL); if(pFileEntry != NULL) { @@ -401,7 +401,7 @@ bool WINAPI SFileOpenArchive( // Load the "(attributes)" file and merge it to the file table if(nError == ERROR_SUCCESS && (dwFlags & MPQ_OPEN_NO_ATTRIBUTES) == 0) { - // Save the flags for (attributes) + // Quick check for (attributes) pFileEntry = GetFileEntryLocale(ha, ATTRIBUTES_NAME, LANG_NEUTRAL); if(pFileEntry != NULL) { @@ -411,6 +411,19 @@ bool WINAPI SFileOpenArchive( } } + // Remember whether the archive has weak signature. Only for MPQs format 1.0. + if(nError == ERROR_SUCCESS) + { + // Quick check for (signature) + pFileEntry = GetFileEntryLocale(ha, SIGNATURE_NAME, LANG_NEUTRAL); + if(pFileEntry != NULL) + { + // Just remember that the archive is weak-signed + assert(pFileEntry->dwFlags == MPQ_FILE_EXISTS); + ha->dwFileFlags3 = pFileEntry->dwFlags; + } + } + // Cleanup and exit if(nError != ERROR_SUCCESS) { @@ -469,6 +482,14 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) // Indicate that we are saving MPQ internal structures ha->dwFlags |= MPQ_FLAG_SAVING_TABLES; + // If the (signature) has been invalidated, save it + if(ha->dwFlags & MPQ_FLAG_SIGNATURE_INVALID) + { + nError = SSignFileCreate(ha); + if(nError != ERROR_SUCCESS) + nResultError = nError; + } + // If the (listfile) has been invalidated, save it if(ha->dwFlags & MPQ_FLAG_LISTFILE_INVALID) { @@ -488,9 +509,18 @@ bool WINAPI SFileFlushArchive(HANDLE hMpq) // Save HET table, BET table, hash table, block table, hi-block table if(ha->dwFlags & MPQ_FLAG_CHANGED) { + // Save all MPQ tables first nError = SaveMPQTables(ha); if(nError != ERROR_SUCCESS) nResultError = nError; + + // If the archive has weak signature, we need to finish it + if(ha->dwFileFlags3 != 0) + { + nError = SSignFileFinish(ha); + if(nError != ERROR_SUCCESS) + nResultError = nError; + } } // We are no longer saving internal MPQ structures |