diff options
Diffstat (limited to 'dep/CascLib/src/CascDumpData.cpp')
-rw-r--r-- | dep/CascLib/src/CascDumpData.cpp | 334 |
1 files changed, 85 insertions, 249 deletions
diff --git a/dep/CascLib/src/CascDumpData.cpp b/dep/CascLib/src/CascDumpData.cpp index 5dc9110b6cd..3c0e385ac07 100644 --- a/dep/CascLib/src/CascDumpData.cpp +++ b/dep/CascLib/src/CascDumpData.cpp @@ -11,14 +11,14 @@ #define __CASCLIB_SELF__ #include "CascLib.h" #include "CascCommon.h" -#include "CascMndxRoot.h" +#include "CascMndx.h" -#ifdef _DEBUG // The entire file is only valid for debug purposes +#ifdef _DEBUG // The entire feature is only valid for debug purposes //----------------------------------------------------------------------------- // Forward definitions -LPBYTE VerifyLocaleBlock(PROOT_BLOCK_INFO pBlockInfo, LPBYTE pbFilePointer, LPBYTE pbFileEnd); +//LPBYTE VerifyLocaleBlock(PROOT_BLOCK_INFO pBlockInfo, LPBYTE pbFilePointer, LPBYTE pbFileEnd); //----------------------------------------------------------------------------- // Sort compare functions @@ -50,160 +50,6 @@ static int CompareIndexEntries_FilePos(const void *, const void * pvIndexEntry1, } //----------------------------------------------------------------------------- -// Local functions - -static char * StringFromMD5(LPBYTE md5, char * szBuffer) -{ - return StringFromBinary(md5, MD5_HASH_SIZE, szBuffer); -} - -static char * FormatFileName(const char * szFormat, TCascStorage * hs) -{ - char * szFileName; - char * szSrc; - char * szTrg; - - // Create copy of the file name - szFileName = szSrc = szTrg = NewStr(szFormat, 0); - if(szFileName != NULL) - { - // Format the file name - while(szSrc[0] != 0) - { - if(szSrc[0] == '%') - { - // Replace "%build%" with a build number - if(!strncmp(szSrc, "%build%", 7)) - { - szTrg += sprintf(szTrg, "%u", hs->dwBuildNumber); - szSrc += 7; - continue; - } - } - - // Just copy the character - *szTrg++ = *szSrc++; - } - - // Terminate the target file name - szTrg[0] = 0; - } - - return szFileName; -} - -FILE * CreateDumpFile(const char * szFormat, TCascStorage * hs) -{ - FILE * fp = NULL; - char * szFileName; - - // Validate the storage handle - if(hs != NULL) - { - // Format the real file name - szFileName = FormatFileName(szFormat, hs); - if(szFileName != NULL) - { - // Create the dump file - fp = fopen(szFileName, "wt"); - CASC_FREE(szFileName); - } - } - - return fp; -} - -static void DumpIndexKey( - FILE * fp, - TCascStorage * hs, - LPBYTE pbIndexKey, - int nDumpLevel) -{ - PCASC_INDEX_ENTRY pIndexEntry; - TCascFile * hf; - QUERY_KEY QueryKey; - HANDLE hFile; - BYTE HeaderArea[MAX_HEADER_AREA_SIZE]; - char szBuffer[0x20]; - - QueryKey.pbData = pbIndexKey; - QueryKey.cbData = MD5_HASH_SIZE; - pIndexEntry = FindIndexEntry(hs, &QueryKey); - if(pIndexEntry != NULL) - { - ULONGLONG FileOffset = ConvertBytesToInteger_5(pIndexEntry->FileOffsetBE); - DWORD ArchIndex = (DWORD)(FileOffset >> 0x1E); - DWORD FileSize = ConvertBytesToInteger_4_LE(pIndexEntry->FileSizeLE); - - // Mask the file offset - FileOffset &= 0x3FFFFFFF; - fprintf(fp, " data.%03u at 0x%08x (0x%lx bytes)\n", - ArchIndex, - (DWORD)FileOffset, - FileSize); - - if(nDumpLevel > 2) - { - QueryKey.pbData = pIndexEntry->IndexKey; - QueryKey.cbData = MD5_HASH_SIZE; - if(CascOpenFileByIndexKey((HANDLE)hs, &QueryKey, 0, &hFile)) - { - // Make sure that the data file is open and frame header loaded - CascGetFileSize(hFile, NULL); - hf = IsValidFileHandle(hFile); - assert(hf->pStream != NULL); - - // Read the header area - FileOffset = hf->HeaderOffset - BLTE_HEADER_DELTA; - FileStream_Read(hf->pStream, &FileOffset, HeaderArea, sizeof(HeaderArea)); - CascCloseFile(hFile); - - // Dump the header area - fprintf(fp, " FileSize: %X Rest: %s\n", - ConvertBytesToInteger_4_LE(&HeaderArea[0x10]), - StringFromBinary(&HeaderArea[0x14], 10, szBuffer)); - } - } - } - else - { - fprintf(fp, " NO INDEX ENTRY\n"); - } -} - -static void DumpEncodingEntry( - FILE * fp, - TCascStorage * hs, - PCASC_ENCODING_ENTRY pEncodingEntry, - int nDumpLevel) -{ - LPBYTE pbIndexKey; - char szMd5[MD5_STRING_SIZE]; - - // If the encoding key exists - if(pEncodingEntry != NULL) - { - fprintf(fp, " Size %lx Key Count: %u\n", - ConvertBytesToInteger_4(pEncodingEntry->FileSizeBE), - pEncodingEntry->KeyCount); - - // Dump all index keys - pbIndexKey = pEncodingEntry->EncodingKey + MD5_HASH_SIZE; - for(DWORD j = 0; j < pEncodingEntry->KeyCount; j++) - { - fprintf(fp, " %s\n", StringFromMD5(pbIndexKey, szMd5)); - DumpIndexKey(fp, hs, pbIndexKey, nDumpLevel); - pbIndexKey += MD5_HASH_SIZE; - } - - } - else - { - fprintf(fp, " NO ENCODING KEYS\n"); - } -} - -//----------------------------------------------------------------------------- // Public functions void CascDumpSparseArray(const char * szFileName, void * pvSparseArray) @@ -323,27 +169,92 @@ void CascDumpFileNames(const char * szFileName, void * pvMarFile) Struct1C.FreeStruct40(); } -void CascDumpMndxRoot(const char * szFileName, PCASC_MNDX_INFO pMndxInfo) +void CascDumpIndexEntry( + TCascStorage * /* hs */, + TDumpContext * dc, + PCASC_INDEX_ENTRY pIndexEntry, + int /* nDumpLevel */) { - PCASC_ROOT_ENTRY_MNDX pRootEntry; - FILE * fp; - char szMd5[MD5_STRING_SIZE]; + if(pIndexEntry != NULL) + { + ULONGLONG FileOffset = ConvertBytesToInteger_5(pIndexEntry->FileOffsetBE); + DWORD ArchIndex = (DWORD)(FileOffset >> 0x1E); + DWORD FileSize = ConvertBytesToInteger_4_LE(pIndexEntry->FileSizeLE); - // Create the dump file - fp = fopen(szFileName, "wt"); - if(fp != NULL) + // Mask the file offset + FileOffset &= 0x3FFFFFFF; + dump_print(dc, " data.%03u at 0x%08x (0x%lx bytes)\n", + ArchIndex, + (DWORD)FileOffset, + FileSize); + + //if(nDumpLevel > 2) + //{ + // QueryKey.pbData = pIndexEntry->IndexKey; + // QueryKey.cbData = MD5_HASH_SIZE; + // if(CascOpenFileByIndexKey((HANDLE)hs, &QueryKey, 0, &hFile)) + // { + // // Make sure that the data file is open and frame header loaded + // CascGetFileSize(hFile, NULL); + // hf = IsValidFileHandle(hFile); + // assert(hf->pStream != NULL); + + // // Read the header area + // FileOffset = hf->HeaderOffset - BLTE_HEADER_DELTA; + // FileStream_Read(hf->pStream, &FileOffset, HeaderArea, sizeof(HeaderArea)); + // CascCloseFile(hFile); + + // // Dump the header area + // dump_print(dc, " FileSize: %X Rest: %s\n", + // ConvertBytesToInteger_4_LE(&HeaderArea[0x10]), + // StringFromBinary(&HeaderArea[0x14], 10, szBuffer)); + // } + //} + } + else { - fprintf(fp, "Indx Fl+Asset EncodingKey FileSize\n==== ======== ================================ ========\n"); - for(DWORD i = 0; i < pMndxInfo->MndxEntriesValid; i++) - { - pRootEntry = pMndxInfo->ppValidEntries[i]; + dump_print(dc, " NO INDEX ENTRY\n"); + } +} + +void CascDumpEncodingEntry( + TCascStorage * hs, + TDumpContext * dc, + PCASC_ENCODING_ENTRY pEncodingEntry, + int nDumpLevel) +{ + PCASC_INDEX_ENTRY pIndexEntry; + QUERY_KEY QueryKey; + LPBYTE pbIndexKey; + char szMd5[MD5_STRING_SIZE+1]; - fprintf(fp, "%04X %08X %s %08X\n", i, - pRootEntry->Flags, - StringFromMD5(pRootEntry->EncodingKey, szMd5), - pRootEntry->FileSize); + // If the encoding key exists + if(pEncodingEntry != NULL) + { + dump_print(dc, " Size %lx Key Count: %u\n", + ConvertBytesToInteger_4(pEncodingEntry->FileSizeBE), + pEncodingEntry->KeyCount); + + // Dump all index keys + pbIndexKey = pEncodingEntry->EncodingKey + MD5_HASH_SIZE; + for(DWORD j = 0; j < pEncodingEntry->KeyCount; j++, pbIndexKey += MD5_HASH_SIZE) + { + // Dump the index key + dump_print(dc, " %s\n", StringFromMD5(pbIndexKey, szMd5)); + + // Dump the index entry as well + if(nDumpLevel >= DUMP_LEVEL_INDEX_ENTRIES) + { + QueryKey.pbData = pbIndexKey; + QueryKey.cbData = MD5_HASH_SIZE; + pIndexEntry = FindIndexEntry(hs, &QueryKey); + CascDumpIndexEntry(hs, dc, pIndexEntry, nDumpLevel); + } } - fclose(fp); + } + else + { + dump_print(dc, " NO ENCODING KEYS\n"); } } @@ -380,7 +291,7 @@ void CascDumpIndexEntries(const char * szFileName, TCascStorage * hs) FileSize = ConvertBytesToInteger_4_LE(pIndexEntry->FileSizeLE); ArchOffset &= 0x3FFFFFFF; - fprintf(fp, " %02X %08X %08X %s\n", ArchIndex, ArchOffset, FileSize, StringFromBinary(pIndexEntry->IndexKey, CASC_FILE_KEY_SIZE, szIndexKey)); + fprintf(fp, " %02X %08X %08X %s\n", ArchIndex, (DWORD)ArchOffset, FileSize, StringFromBinary(pIndexEntry->IndexKey, CASC_FILE_KEY_SIZE, szIndexKey)); } CASC_FREE(ppIndexEntries); @@ -390,81 +301,6 @@ void CascDumpIndexEntries(const char * szFileName, TCascStorage * hs) } } -void CascDumpRootFile( - TCascStorage * hs, - LPBYTE pbRootFile, - DWORD cbRootFile, - const char * szFormat, - const TCHAR * szListFile, - int nDumpLevel) -{ - PCASC_ENCODING_ENTRY pEncodingEntry; - ROOT_BLOCK_INFO BlockInfo; - PLISTFILE_MAP pListMap; - QUERY_KEY EncodingKey; - LPBYTE pbRootFileEnd = pbRootFile + cbRootFile; - LPBYTE pbFilePointer; - FILE * fp; - char szOneLine[0x100]; - DWORD i; - - // This function only dumps WoW-style root file - assert(*(PDWORD)pbRootFile != CASC_MNDX_SIGNATURE); - - // Create the dump file - fp = CreateDumpFile(szFormat, hs); - if(fp != NULL) - { - // Create the listfile map -// DWORD dwTickCount = GetTickCount(); - pListMap = ListFile_CreateMap(szListFile); -// dwTickCount = GetTickCount() - dwTickCount; - - // Dump the root entries as-is - for(pbFilePointer = pbRootFile; pbFilePointer <= pbRootFileEnd; ) - { - // Validate the root block - pbFilePointer = VerifyLocaleBlock(&BlockInfo, pbFilePointer, pbRootFileEnd); - if(pbFilePointer == NULL) - break; - - // Dump the locale block - fprintf(fp, "Flags: %08X Locales: %08X NumberOfFiles: %u\n" - "=========================================================\n", - BlockInfo.pLocaleBlockHdr->Flags, - BlockInfo.pLocaleBlockHdr->Locales, - BlockInfo.pLocaleBlockHdr->NumberOfFiles); - - // Dump the hashes and encoding keys - for(i = 0; i < BlockInfo.pLocaleBlockHdr->NumberOfFiles; i++) - { - // Dump the entry - fprintf(fp, "%08X %08X-%08X %s %s\n", - (DWORD)(BlockInfo.pInt32Array[i]), - (DWORD)(BlockInfo.pRootEntries[i].FileNameHash >> 0x20), - (DWORD)(BlockInfo.pRootEntries[i].FileNameHash), - StringFromMD5((LPBYTE)BlockInfo.pRootEntries[i].EncodingKey, szOneLine), - ListFile_FindName(pListMap, BlockInfo.pRootEntries[i].FileNameHash)); - - // Find the encoding entry in the encoding table - if(nDumpLevel > 1) - { - EncodingKey.pbData = (LPBYTE)BlockInfo.pRootEntries[i].EncodingKey; - EncodingKey.cbData = MD5_HASH_SIZE; - pEncodingEntry = FindEncodingEntry(hs, &EncodingKey, NULL); - DumpEncodingEntry(fp, hs, pEncodingEntry, nDumpLevel); - } - } - - // Put extra newline - fprintf(fp, "\n"); - } - - ListFile_FreeMap(pListMap); - fclose(fp); - } -} - void CascDumpFile(const char * szFileName, HANDLE hFile) { FILE * fp; |