diff options
author | Ladislav Zezula <ladislav.zezula@avast.com> | 2022-05-12 15:44:15 +0200 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avast.com> | 2022-05-12 15:44:15 +0200 |
commit | 4321c59d8431eaf72d7b36c047859b72bca02318 (patch) | |
tree | 2f7a46599df9b7526d3c92ce319c6aeb6954bd4f /storm_dll/storm_test.cpp | |
parent | 460354d98bc266507befe517f9f246d3b952abc9 (diff) |
Added implementation of Srarctaft I BETA ADPCM decompression
Diffstat (limited to 'storm_dll/storm_test.cpp')
-rw-r--r-- | storm_dll/storm_test.cpp | 196 |
1 files changed, 175 insertions, 21 deletions
diff --git a/storm_dll/storm_test.cpp b/storm_dll/storm_test.cpp index 397c4dd..0ac2c67 100644 --- a/storm_dll/storm_test.cpp +++ b/storm_dll/storm_test.cpp @@ -11,6 +11,7 @@ #define _CRT_NON_CONFORMING_SWPRINTFS #define _CRT_SECURE_NO_DEPRECATE #include <stdio.h> +#include <windows.h> #ifdef _MSC_VER #include <crtdbg.h> @@ -20,8 +21,141 @@ #include "storm.h" // Header file for Storm.dll //----------------------------------------------------------------------------- +// List of files + +const char * IntToHexChar = "0123456789ABCDEF"; + +LPCSTR ListFile[] = +{ + "music\\tdefeat.wav", + "setupdat\\inst.vis", + "setupdat\\audio\\mouseover.wav", + "files\\font\\font12.fnt", + "music\\zvict.wav", + "files\\readme.txt", + "music\\zerg2.wav", + "music\\zerg1.wav", + "setupdat\\inst_regs.ins", + "files\\font\\font50.fnt", + "files\\msv2all.vxp", + "setupdat\\scr_options.vis", + "setupdat\\font\\font16x.fnt", + "setupdat\\setup.vis", + "maps\\128x128_wasteland4.scm", + "setupdat\\scr_main.vis", + "music\\pvict.wav", + "music\\zdefeat.wav", + "files\\font\\font16x.fnt", + "setupdat\\nt\\comctl32.dll", + "setupdat\\debug.ins", + "setupdat\\inst.ins", + "music\\pdefeat.wav", + "files\\smackw32.dll", + "music\\tvict.wav", + "setupdat\\optvox.vis", + "setupdat\\gen\\maps.lst", + "files\\font\\font8.fnt", + "files\\mvoice.vxp", + "files\\font\\font14.fnt", + "files\\battle.snp", + "files\\storm.dll", + "maps\\128x128_ash4.scm", + "files\\font\\font32.fnt", + "setupdat\\normal.ins", + "files\\font\\font16.fnt", + "setupdat\\mainplay.vis", + "setupdat\\gendefs.ins", + "setupdat\\audio\\installermusic.wav", + "setupdat\\templates.ins", + "music\\terran1.wav", + "maps\\96x96_ash4.scm", + "setupdat\\defaults.vis", + "music\\prdyroom.wav", + "setupdat\\scr_blizzard.vis", + "setupdat\\scr_isp.vis", + "setupdat\\95\\comctl32.dll", + "files\\font\\font10.fnt", + "files\\local.dll", + "music\\terran3.wav", + "music\\terran2.wav", + "setupdat\\audio\\battlenetclick.wav", + "music\\zrdyroom.wav", + "setupdat\\starunin.exe", + "files\\vct32150.dll", + "maps\\96x96_wasteland4.scm", + "setupdat\\inst_sys.ins", + "music\\zerg3.wav", + "setupdat\\license.txt", + "music\\protoss2.wav", + "files\\starcraft.exe", + "music\\trdyroom.wav", + "maps\\96x96_space4.scm", + "files\\vfonts.vxp", + "setupdat\\installed.ins", + "music\\protoss1.wav", + "files\\stardat.mpq", + "setupdat\\font\\font16.fnt", + "smk\\starintr.smk", + "files\\vadagc.vxp", + "setupdat\\strings.ins", + "music\\title.wav", + "setupdat\\font\\font32.fnt", + "setupdat\\inst_files.ins", + "setupdat\\images\\install.pcx", + "files\\report bugs.url", + "setupdat\\single.ins", + "maps\\128x128_space4.scm", + "setupdat\\audio\\mousedown.wav", + NULL +}; + +//----------------------------------------------------------------------------- // Main +static void CalculateMD5(LPBYTE md5_digest, LPBYTE pbData, DWORD cbData) +{ + HCRYPTPROV hCryptProv = NULL; + HCRYPTHASH hCryptHash = NULL; + + if(CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) + { + if(CryptCreateHash(hCryptProv, CALG_MD5, NULL, 0, &hCryptHash)) + { + DWORD dwHashLen = 0x10; + + CryptHashData(hCryptHash, pbData, cbData, 0); + CryptGetHashParam(hCryptHash, HP_HASHVAL, md5_digest, &dwHashLen, 0); + CryptDestroyHash(hCryptHash); + } + + CryptReleaseContext(hCryptProv, 0); + } +} + +template <typename XCHAR> +DWORD BinaryToString(XCHAR * szBuffer, size_t cchBuffer, LPCVOID pvBinary, size_t cbBinary) +{ + LPCBYTE pbBinary = (LPCBYTE)pvBinary; + + // The size of the string must be enough to hold the binary + EOS + if(cchBuffer < ((cbBinary * 2) + 1)) + return ERROR_INSUFFICIENT_BUFFER; + + // Convert the string to the array of MD5 + // Copy the blob data as text + for(size_t i = 0; i < cbBinary; i++) + { + *szBuffer++ = IntToHexChar[pbBinary[0] >> 0x04]; + *szBuffer++ = IntToHexChar[pbBinary[0] & 0x0F]; + pbBinary++; + } + + // Terminate the string + *szBuffer = 0; + return ERROR_SUCCESS; +} + + int main(int argc, char * argv[]) { LPCSTR szArchiveName; @@ -29,10 +163,12 @@ int main(int argc, char * argv[]) LPCSTR szFormat; HANDLE hMpq = NULL; HANDLE hFile = NULL; - BYTE Buffer[0x100]; + LPBYTE pbBuffer = NULL; DWORD dwBytesRead = 0; DWORD dwFileSize = 0; BOOL bResult; + BYTE md5_digest[0x10]; + char md5_string[0x40]; // Check parameters if(argc != 3) @@ -46,34 +182,52 @@ int main(int argc, char * argv[]) szArchiveName = argv[1]; szFileName = argv[2]; + // Break for kernel debugger + //__debugbreak(); + // Put Storm.dll to the current folder before running this - printf("[*] Opening archive '%s' ...\n", szArchiveName); + //printf("[*] Opening archive '%s' ...\n", szArchiveName); if(StormOpenArchive(szArchiveName, 0, 0, &hMpq)) { - printf("[*] Opening file '%s' ...\n", szFileName); - if(StormOpenFileEx(hMpq, "staredit\\scenario.chk", 0, &hFile)) + for(size_t i = 0; ListFile[i] != NULL; i++) { - printf("[*] Retrieving file size ... "); - dwFileSize = StormGetFileSize(hFile, NULL); - szFormat = (dwFileSize == INVALID_FILE_SIZE) ? ("(invalid)\n") : ("(%u bytes)\n"); - printf(szFormat, dwFileSize); - - printf("[*] Moving to begin of the file ...\n"); - StormSetFilePointer(hFile, 0, NULL, FILE_BEGIN); - - printf("[*] Reading file ... "); - bResult = StormReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead, NULL); - szFormat = (bResult == FALSE) ? ("(error %u)\n") : ("(OK)\n"); - printf(szFormat, GetLastError()); - - printf("[*] Closing file ...\n"); - StormCloseFile(hFile); + //printf("[*] Opening file '%s' ...\n", ListFile[i]); + if(StormOpenFileEx(hMpq, ListFile[i], 0, &hFile)) + { + //printf("[*] Retrieving file size ... "); + dwFileSize = StormGetFileSize(hFile, NULL); + szFormat = (dwFileSize == INVALID_FILE_SIZE) ? ("(invalid)\n") : ("(%u bytes)\n"); + //printf(szFormat, dwFileSize); + + // Allocate the buffer for the entire file + //printf("[*] Allocating buffer ...\n"); + if((pbBuffer = new BYTE[dwFileSize]) != NULL) + { + //printf("[*] Moving to begin of the file ...\n"); + StormSetFilePointer(hFile, 0, NULL, FILE_BEGIN); + + //printf("[*] Reading file ... "); + bResult = StormReadFile(hFile, pbBuffer, dwFileSize, &dwBytesRead, NULL); + szFormat = (bResult != FALSE && dwBytesRead == dwFileSize) ? ("(OK)\n") : ("(error %u)\n"); + //printf(szFormat, GetLastError()); + + //printf("[*] Calculating MD5 ... "); + CalculateMD5(md5_digest, pbBuffer, dwFileSize); + BinaryToString(md5_string, _countof(md5_string), md5_digest, sizeof(md5_digest)); + printf("%s *%s\n", md5_string, ListFile[i]); + + delete[] pbBuffer; + } + + //printf("[*] Closing file ...\n"); + StormCloseFile(hFile); + } } - printf("[*] Closing archive ...\n"); + //printf("[*] Closing archive ...\n"); StormCloseArchive(hMpq); } - printf("Done.\n\n"); + //printf("Done.\n\n"); return 0; } |