diff options
-rw-r--r-- | dep/CascLib/CMakeLists.txt | 4 | ||||
-rw-r--r-- | dep/CascLib/src/CascCommon.h | 1 | ||||
-rw-r--r-- | dep/CascLib/src/CascDecrypt.cpp | 3 | ||||
-rw-r--r-- | dep/CascLib/src/CascLib.h | 44 | ||||
-rw-r--r-- | dep/CascLib/src/CascOpenFile.cpp | 5 | ||||
-rw-r--r-- | dep/CascLib/src/CascReadFile.cpp | 10 | ||||
-rw-r--r-- | dep/CascLib/src/CascRootFile_MNDX.cpp (renamed from dep/CascLib/src/CascRootFile_Mndx.cpp) | 0 | ||||
-rw-r--r-- | dep/CascLib/src/common/Common.cpp | 29 | ||||
-rw-r--r-- | dep/CascLib/src/common/Common.h | 9 | ||||
-rw-r--r-- | dep/CascLib/src/common/Csv.h | 2 | ||||
-rw-r--r-- | dep/PackageList.txt | 2 | ||||
-rw-r--r-- | src/tools/extractor_common/CascHandles.cpp | 16 | ||||
-rw-r--r-- | src/tools/extractor_common/CascHandles.h | 4 | ||||
-rw-r--r-- | src/tools/extractor_common/DB2CascFileSource.cpp | 8 | ||||
-rw-r--r-- | src/tools/extractor_common/DB2CascFileSource.h | 1 | ||||
-rw-r--r-- | src/tools/map_extractor/System.cpp | 16 |
16 files changed, 80 insertions, 74 deletions
diff --git a/dep/CascLib/CMakeLists.txt b/dep/CascLib/CMakeLists.txt index 84de80aa89c..e64c92bb735 100644 --- a/dep/CascLib/CMakeLists.txt +++ b/dep/CascLib/CMakeLists.txt @@ -33,7 +33,7 @@ set(SRC_FILES src/CascReadFile.cpp src/CascRootFile_Diablo3.cpp src/CascRootFile_Install.cpp - src/CascRootFile_Mndx.cpp + src/CascRootFile_MNDX.cpp src/CascRootFile_Text.cpp src/CascRootFile_TVFS.cpp src/CascRootFile_OW.cpp @@ -52,7 +52,7 @@ target_include_directories(casc PRIVATE ${CMAKE_SOURCE_DIR}/dep) -target_compile_definitions(casc PUBLIC -D__SYS_ZLIB) +target_compile_definitions(casc PUBLIC -D__SYS_ZLIB -DCASCLIB_NO_AUTO_LINK_LIBRARY) target_link_libraries(casc PRIVATE diff --git a/dep/CascLib/src/CascCommon.h b/dep/CascLib/src/CascCommon.h index 3ce527061c2..f32be935352 100644 --- a/dep/CascLib/src/CascCommon.h +++ b/dep/CascLib/src/CascCommon.h @@ -342,6 +342,7 @@ struct TCascFile DWORD bVerifyIntegrity:1; // If true, then the data are validated more strictly when read DWORD bDownloadFileIf:1; // If true, then the data will be downloaded from the online storage if missing DWORD bLocalFileStream:1; // If true, then the file stream is a local file + DWORD bOvercomeEncrypted:1; // If true, then CascReadFile will fill the part that is encrypted (and key was not found) with zeros LPBYTE pbFileCache; // Pointer to file cache DWORD cbFileCache; // Size of the file cache diff --git a/dep/CascLib/src/CascDecrypt.cpp b/dep/CascLib/src/CascDecrypt.cpp index 043d8effa66..42bf3084801 100644 --- a/dep/CascLib/src/CascDecrypt.cpp +++ b/dep/CascLib/src/CascDecrypt.cpp @@ -480,6 +480,9 @@ int CascDirectCopy(LPBYTE pbOutBuffer, PDWORD pcbOutBuffer, LPBYTE pbInBuffer, D return ERROR_SUCCESS; } +//----------------------------------------------------------------------------- +// Public functions + bool WINAPI CascAddEncryptionKey(HANDLE hStorage, ULONGLONG KeyName, LPBYTE Key) { PCASC_ENCRYPTION_KEY pEncKey; diff --git a/dep/CascLib/src/CascLib.h b/dep/CascLib/src/CascLib.h index 9695ad7429a..52451ac8f20 100644 --- a/dep/CascLib/src/CascLib.h +++ b/dep/CascLib/src/CascLib.h @@ -27,6 +27,49 @@ extern "C" { #endif //----------------------------------------------------------------------------- +// Use the apropriate library +// +// The library type is encoded in the library name as the following +// CascLibXYZ.lib +// +// X - D for Debug version, R for Release version +// Y - A for ANSI version, U for Unicode version +// Z - S for static-linked CRT library, D for multithreaded DLL CRT library +// +#if defined(_MSC_VER) && !defined(__CASCLIB_SELF__) && !defined(CASCLIB_NO_AUTO_LINK_LIBRARY) + + #ifdef _DEBUG // DEBUG VERSIONS + #ifndef _UNICODE + #ifdef _DLL + #pragma comment(lib, "CascLibDAD.lib") // Debug Ansi CRT-DLL version + #else + #pragma comment(lib, "CascLibDAS.lib") // Debug Ansi CRT-LIB version + #endif + #else + #ifdef _DLL + #pragma comment(lib, "CascLibDUD.lib") // Debug Unicode CRT-DLL version + #else + #pragma comment(lib, "CascLibDUS.lib") // Debug Unicode CRT-LIB version + #endif + #endif + #else // RELEASE VERSIONS + #ifndef _UNICODE + #ifdef _DLL + #pragma comment(lib, "CascLibRAD.lib") // Release Ansi CRT-DLL version + #else + #pragma comment(lib, "CascLibRAS.lib") // Release Ansi CRT-LIB version + #endif + #else + #ifdef _DLL + #pragma comment(lib, "CascLibRUD.lib") // Release Unicode CRT-DLL version + #else + #pragma comment(lib, "CascLibRUS.lib") // Release Unicode CRT-LIB version + #endif + #endif + #endif + +#endif +//----------------------------------------------------------------------------- // Defines #define CASCLIB_VERSION 0x0132 // Current version of CascLib (1.50) @@ -40,6 +83,7 @@ extern "C" { #define CASC_OPEN_TYPE_MASK 0x0000000F // The mask which gets open type from the dwFlags #define CASC_OPEN_FLAGS_MASK 0xFFFFFFF0 // The mask which gets open type from the dwFlags #define CASC_STRICT_DATA_CHECK 0x00000010 // Verify all data read from a file +#define CASC_OVERCOME_ENCRYPTED 0x00000020 // When CascReadFile encounters a block encrypted with a key that is missing, the block is filled with zeros and returned as success #define CASC_LOCALE_ALL 0xFFFFFFFF #define CASC_LOCALE_NONE 0x00000000 diff --git a/dep/CascLib/src/CascOpenFile.cpp b/dep/CascLib/src/CascOpenFile.cpp index 741ab1e1005..45d10bc18f1 100644 --- a/dep/CascLib/src/CascOpenFile.cpp +++ b/dep/CascLib/src/CascOpenFile.cpp @@ -36,8 +36,9 @@ bool OpenFileByCKeyEntry(TCascStorage * hs, PCASC_CKEY_ENTRY pCKeyEntry, DWORD d // Create the file handle structure if((hf = new TCascFile(hs, pCKeyEntry)) != NULL) { - hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false; - hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false; + hf->bVerifyIntegrity = (dwOpenFlags & CASC_STRICT_DATA_CHECK) ? true : false; + hf->bDownloadFileIf = (hs->dwFeatures & CASC_FEATURE_ONLINE) ? true : false; + hf->bOvercomeEncrypted = (dwOpenFlags & CASC_OVERCOME_ENCRYPTED) ? true : false; nError = ERROR_SUCCESS; } else diff --git a/dep/CascLib/src/CascReadFile.cpp b/dep/CascLib/src/CascReadFile.cpp index 2720d6d5adb..2f444d0d80f 100644 --- a/dep/CascLib/src/CascReadFile.cpp +++ b/dep/CascLib/src/CascReadFile.cpp @@ -791,6 +791,16 @@ bool WINAPI CascReadFile(HANDLE hFile, void * pvBuffer, DWORD dwBytesToRead, PDW pbEncodedFrame, pFrame->EncodedSize, (DWORD)(pFrame - hf->pFrames)); + + // Some people find it handy to extract data from partially encrypted file, + // even at the cost producing files that are corrupt. + // We overcome missing decryption key by zeroing the encrypted portions + if(nError == ERROR_FILE_ENCRYPTED && hf->bOvercomeEncrypted) + { + memset(pbDecodedFrame, 0, pFrame->ContentSize); + nError = ERROR_SUCCESS; + } + if (nError == ERROR_SUCCESS) { // Mark the frame as loaded diff --git a/dep/CascLib/src/CascRootFile_Mndx.cpp b/dep/CascLib/src/CascRootFile_MNDX.cpp index 9dca8d30eb4..9dca8d30eb4 100644 --- a/dep/CascLib/src/CascRootFile_Mndx.cpp +++ b/dep/CascLib/src/CascRootFile_MNDX.cpp diff --git a/dep/CascLib/src/common/Common.cpp b/dep/CascLib/src/common/Common.cpp index d545f52f84a..fafa00e7739 100644 --- a/dep/CascLib/src/common/Common.cpp +++ b/dep/CascLib/src/common/Common.cpp @@ -79,35 +79,6 @@ void SetLastError(DWORD dwErrCode) #endif //----------------------------------------------------------------------------- -// Overloaded "new" and "delete" operators - -void * operator new(size_t size) -{ - return CASC_ALLOC(BYTE, size); -} - -void * operator new[](size_t size) -{ - return CASC_ALLOC(BYTE, size); -} - -void operator delete(void * ptr) -{ - CASC_FREE(ptr); -} - -void operator delete[](void * ptr) -{ - CASC_FREE(ptr); -} - -// For some reason, VS2015 needs this -void operator delete(void * ptr, size_t) -{ - CASC_FREE(ptr); -} - -//----------------------------------------------------------------------------- // Linear data stream manipulation LPBYTE CaptureInteger32(LPBYTE pbDataPtr, LPBYTE pbDataEnd, PDWORD PtrValue) diff --git a/dep/CascLib/src/common/Common.h b/dep/CascLib/src/common/Common.h index c7f189b91ac..705777b7b0b 100644 --- a/dep/CascLib/src/common/Common.h +++ b/dep/CascLib/src/common/Common.h @@ -123,15 +123,6 @@ void CASC_FREE(T *& ptr) } //----------------------------------------------------------------------------- -// Overloaded "new" and "delete" operators - -void * operator new(size_t size); -void * operator new[](size_t size); -void operator delete(void * ptr); -void operator delete[](void * ptr); -void operator delete(void * ptr, size_t); // For some reason, VS2015 needs this - -//----------------------------------------------------------------------------- // Big endian number manipulation inline DWORD ConvertBytesToInteger_2(LPBYTE ValueAsBytes) diff --git a/dep/CascLib/src/common/Csv.h b/dep/CascLib/src/common/Csv.h index 2138255e74e..bf1a7413e13 100644 --- a/dep/CascLib/src/common/Csv.h +++ b/dep/CascLib/src/common/Csv.h @@ -16,7 +16,7 @@ #define CSV_INVALID_INDEX ((size_t)(-1)) #define CSV_ZERO ((size_t)(0)) // Use Csv[0][CSV_ZERO] instead of ambiguous Csv[0][0] -#define CSV_MAX_COLUMNS 0x10 +#define CSV_MAX_COLUMNS 0x20 #define CSV_HASH_TABLE_SIZE 0x80 //----------------------------------------------------------------------------- diff --git a/dep/PackageList.txt b/dep/PackageList.txt index e539385e789..21b81f357f4 100644 --- a/dep/PackageList.txt +++ b/dep/PackageList.txt @@ -62,7 +62,7 @@ recastnavigation (Recast is state of the art navigation mesh construction toolse CascLib (An open-source implementation of library for reading CASC storage from Blizzard games since 2014) https://github.com/ladislav-zezula/CascLib - Version: a1197edf0b3bd4d52c3f39be7fa7b44bb0b98012 + Version: 03a3bcaed285ab0d8ff0845a65ffe7d1fa653960 rapidjson (A fast JSON parser/generator for C++ with both SAX/DOM style API http://rapidjson.org/) https://github.com/miloyip/rapidjson diff --git a/src/tools/extractor_common/CascHandles.cpp b/src/tools/extractor_common/CascHandles.cpp index eb84a084a11..baed5e61b7a 100644 --- a/src/tools/extractor_common/CascHandles.cpp +++ b/src/tools/extractor_common/CascHandles.cpp @@ -104,10 +104,14 @@ bool CASC::HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup) return CascFindEncryptionKey(storage.get(), keyLookup) != nullptr; } -CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/) +CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) { + DWORD openFlags = CASC_OPEN_BY_NAME; + if (zerofillEncryptedParts) + openFlags |= CASC_OVERCOME_ENCRYPTED; + HANDLE handle = nullptr; - if (!::CascOpenFile(storage.get(), fileName, localeMask, CASC_OPEN_BY_NAME, &handle)) + if (!::CascOpenFile(storage.get(), fileName, localeMask, openFlags, &handle)) { DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close* if (printErrors) @@ -121,10 +125,14 @@ CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, char const* fileNa return FileHandle(handle); } -CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors /*= false*/) +CASC::FileHandle CASC::OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors /*= false*/, bool zerofillEncryptedParts /*= false*/) { + DWORD openFlags = CASC_OPEN_BY_FILEID; + if (zerofillEncryptedParts) + openFlags |= CASC_OVERCOME_ENCRYPTED; + HANDLE handle = nullptr; - if (!::CascOpenFile(storage.get(), CASC_FILE_DATA_ID(fileDataId), localeMask, CASC_OPEN_BY_FILEID, &handle)) + if (!::CascOpenFile(storage.get(), CASC_FILE_DATA_ID(fileDataId), localeMask, openFlags, &handle)) { DWORD lastError = GetLastError(); // support checking error set by *Open* call, not the next *Close* if (printErrors) diff --git a/src/tools/extractor_common/CascHandles.h b/src/tools/extractor_common/CascHandles.h index 9feafdbf4af..4f536ce9ecc 100644 --- a/src/tools/extractor_common/CascHandles.h +++ b/src/tools/extractor_common/CascHandles.h @@ -53,8 +53,8 @@ namespace CASC DWORD GetInstalledLocalesMask(StorageHandle const& storage); bool HasTactKey(StorageHandle const& storage, ULONGLONG keyLookup); - FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false); - FileHandle OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors = false); + FileHandle OpenFile(StorageHandle const& storage, char const* fileName, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false); + FileHandle OpenFile(StorageHandle const& storage, DWORD fileDataId, DWORD localeMask, bool printErrors = false, bool zerofillEncryptedParts = false); DWORD GetFileSize(FileHandle const& file, PDWORD fileSizeHigh); DWORD GetFilePointer(FileHandle const& file); bool SetFilePointer(FileHandle const& file, LONGLONG position); diff --git a/src/tools/extractor_common/DB2CascFileSource.cpp b/src/tools/extractor_common/DB2CascFileSource.cpp index 58f8567dda3..c697b01b7fc 100644 --- a/src/tools/extractor_common/DB2CascFileSource.cpp +++ b/src/tools/extractor_common/DB2CascFileSource.cpp @@ -19,15 +19,9 @@ #include "StringFormat.h" #include <CascLib.h> -DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName, bool printErrors /*= true*/) -{ - _fileHandle = CASC::OpenFile(storage, fileName.c_str(), CASC_LOCALE_NONE, printErrors); - _fileName = std::move(fileName); -} - DB2CascFileSource::DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors /*= true*/) { - _fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors); + _fileHandle = CASC::OpenFile(storage, fileDataId, CASC_LOCALE_NONE, printErrors, true); _fileName = Trinity::StringFormat("FileDataId: %u", fileDataId); } diff --git a/src/tools/extractor_common/DB2CascFileSource.h b/src/tools/extractor_common/DB2CascFileSource.h index 80559ff8d41..f5686a802c8 100644 --- a/src/tools/extractor_common/DB2CascFileSource.h +++ b/src/tools/extractor_common/DB2CascFileSource.h @@ -24,7 +24,6 @@ struct DB2CascFileSource : public DB2FileSource { - DB2CascFileSource(CASC::StorageHandle const& storage, std::string fileName, bool printErrors = true); DB2CascFileSource(CASC::StorageHandle const& storage, uint32 fileDataId, bool printErrors = true); bool IsOpen() const override; bool Read(void* buffer, std::size_t numBytes) override; diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index dcbbc0547d0..ff05df3119c 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -1251,22 +1251,6 @@ bool ExtractDB2File(uint32 fileDataId, char const* cascFileName, int locale, boo readBytes = 0; if (!CASC::ReadFile(source.GetHandle(), buffer, std::min<DWORD>(fileSize, readBatchSize), &readBytes)) { - if (GetLastError() == ERROR_FILE_ENCRYPTED) - { - // shrink block size to read as much unencrypted data as possible - if (readBatchSize != 1) - { - readBatchSize = std::max<DWORD>(1, readBatchSize / 2); - continue; - } - - uint8 zero = 0; - --fileSize; - fwrite(&zero, 1, 1, output); - source.SetPosition(source.GetPosition() + 1); - continue; - } - printf("Can't read file '%s'\n", outputFileName.c_str()); fclose(output); boost::filesystem::remove(outputPath); |