| 436 | } |
| 437 | |
| 438 | static DWORD LoadEncodingManifest(TCascStorage * hs) |
| 439 | { |
| 440 | CASC_CKEY_ENTRY & CKeyEntry = hs->EncodingCKey; |
| 441 | CASC_BLOB EncodingFile; |
| 442 | DWORD dwErrCode = ERROR_SUCCESS; |
| 443 | |
| 444 | // Inform the user about what we are doing |
| 445 | if(InvokeProgressCallback(hs, "Loading ENCODING manifest", NULL, 0, 0)) |
| 446 | return ERROR_CANCELLED; |
| 447 | |
| 448 | // Fill-in the information from the index entry and insert it to the file tree |
| 449 | if(!CopyEKeyEntry(hs, &CKeyEntry)) |
| 450 | return ERROR_FILE_NOT_FOUND; |
| 451 | InsertCKeyEntry(hs, CKeyEntry); |
| 452 | |
| 453 | // Load the entire encoding file to memory |
| 454 | dwErrCode = LoadInternalFileToMemory(hs, &hs->EncodingCKey, EncodingFile); |
| 455 | if(dwErrCode == ERROR_SUCCESS && EncodingFile.cbData != 0) |
| 456 | { |
| 457 | CASC_ENCODING_HEADER EnHeader; |
| 458 | |
| 459 | // Capture the header of the ENCODING file |
| 460 | dwErrCode = CaptureEncodingHeader(EnHeader, EncodingFile.pbData, EncodingFile.cbData); |
| 461 | if(dwErrCode == ERROR_SUCCESS) |
| 462 | { |
| 463 | // Get the CKey page header and the first page |
| 464 | PFILE_CKEY_PAGE pPageHeader = (PFILE_CKEY_PAGE)(EncodingFile.pbData + sizeof(FILE_ENCODING_HEADER) + EnHeader.ESpecBlockSize); |
| 465 | LPBYTE pbEncodingEnd = EncodingFile.pbData + EncodingFile.cbData; |
| 466 | LPBYTE pbCKeyPage = (LPBYTE)(pPageHeader + EnHeader.CKeyPageCount); |
| 467 | |
| 468 | // Go through all CKey pages and verify them |
| 469 | for(DWORD i = 0; i < EnHeader.CKeyPageCount; i++) |
| 470 | { |
| 471 | // Check if there is enough space in the buffer |
| 472 | if((pbCKeyPage + EnHeader.CKeyPageSize) > pbEncodingEnd) |
| 473 | { |
| 474 | dwErrCode = ERROR_FILE_CORRUPT; |
| 475 | break; |
| 476 | } |
| 477 | |
| 478 | // Check the hash of the entire segment |
| 479 | // Note that verifying takes considerable time of the storage loading |
| 480 | // if(!VerifyDataBlockHash(pbCKeyPage, EnHeader.CKeyPageSize, pEncodingSegment->SegmentHash)) |
| 481 | // { |
| 482 | // dwErrCode = ERROR_FILE_CORRUPT; |
| 483 | // break; |
| 484 | // } |
| 485 | |
| 486 | // Check if the CKey matches with the expected first value |
| 487 | if(memcmp(((PFILE_CKEY_ENTRY)pbCKeyPage)->CKey, pPageHeader[i].FirstKey, MD5_HASH_SIZE)) |
| 488 | { |
| 489 | dwErrCode = ERROR_FILE_CORRUPT; |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | // Load the entire page of CKey entries. |
| 494 | // This operation will never fail, because all memory is already pre-allocated |
| 495 | dwErrCode = LoadEncodingCKeyPage(hs, EnHeader, pbCKeyPage, pbCKeyPage + EnHeader.CKeyPageSize); |
no test coverage detected