MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / DecodeFileFrame

Function DecodeFileFrame

src/External/CascLib/src/CascReadFile.cpp:540–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

538}
539
540static DWORD DecodeFileFrame(
541 TCascFile * hf,
542 PCASC_CKEY_ENTRY pCKeyEntry,
543 PCASC_FILE_FRAME pFrame,
544 LPBYTE pbEncoded,
545 LPBYTE pbDecoded,
546 DWORD FrameIndex)
547{
548 TCascStorage * hs = hf->hs;
549 LPBYTE pbWorkBuffer = NULL;
550 DWORD cbDecodedExpected = 0;
551 DWORD cbWorkBuffer = 0;
552 DWORD dwStepCount = 0;
553 DWORD dwErrCode = ERROR_SUCCESS;
554 DWORD cbEncoded = pFrame->EncodedSize;
555 DWORD cbDecoded = pFrame->ContentSize;
556 bool bWorkComplete = false;
557
558 //if(pFrame->EncodedSize == 0xda001)
559 //{
560 // FILE * fp = fopen("E:\\frame-da001-002.dat", "wb");
561 // fwrite(pbEncoded, 1, pFrame->EncodedSize, fp);
562 // fclose(fp);
563 //}
564
565 // If this is a file span with plain data, just copy the data
566 if(pCKeyEntry->Flags & CASC_CE_PLAIN_DATA)
567 {
568 assert(pCKeyEntry->ContentSize == pCKeyEntry->EncodedSize);
569 assert(pCKeyEntry->ContentSize == pFrame->ContentSize);
570 assert(pFrame->ContentSize == pFrame->EncodedSize);
571 memcpy(pbDecoded, pbEncoded, pCKeyEntry->ContentSize);
572 return ERROR_SUCCESS;
573 }
574
575 // Shall we verify the frame integrity?
576 if(hf->bVerifyIntegrity)
577 {
578 if(!CascVerifyDataBlockHash(pbEncoded, pFrame->EncodedSize, pFrame->FrameHash.Value))
579 return ERROR_FILE_CORRUPT;
580 }
581
582 // Perform the loop
583 while(bWorkComplete == false)
584 {
585 // There should never be a 3rd step
586 assert(dwStepCount < 2);
587
588 // Perform the operation specific by the first byte
589 switch(pbEncoded[0])
590 {
591 case 'E': // Encrypted files
592
593 // The work buffer should not have been allocated by any step
594 assert(pbWorkBuffer == NULL && cbWorkBuffer == 0);
595
596 // Allocate temporary buffer to decrypt into
597 // Example storage: "2016 - WoW/23420", File: "4ee6bc9c6564227f1748abd0b088e950"

Callers 2

ReadFile_WholeFileFunction · 0.85
ReadFile_FrameCachedFunction · 0.85

Calls 5

CascVerifyDataBlockHashFunction · 0.85
CascDecryptFunction · 0.85
CascDecompressFunction · 0.85
CascDirectCopyFunction · 0.85
CASC_FREEFunction · 0.85

Tested by

no test coverage detected