MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / UnpWriteBuf30

Method UnpWriteBuf30

Libraries/unrar/unpack30.cpp:519–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

517
518
519void Unpack::UnpWriteBuf30()
520{
521 uint WrittenBorder=(uint)WrPtr;
522 uint WriteSize=(uint)((UnpPtr-WrittenBorder)&MaxWinMask);
523 for (size_t I=0;I<PrgStack.Size();I++)
524 {
525 // Here we apply filters to data which we need to write.
526 // We always copy data to virtual machine memory before processing.
527 // We cannot process them just in place in Window buffer, because
528 // these data can be used for future string matches, so we must
529 // preserve them in original form.
530
531 UnpackFilter30 *flt=PrgStack[I];
532 if (flt==NULL)
533 continue;
534 if (flt->NextWindow)
535 {
536 flt->NextWindow=false;
537 continue;
538 }
539 unsigned int BlockStart=flt->BlockStart;
540 unsigned int BlockLength=flt->BlockLength;
541 if (((BlockStart-WrittenBorder)&MaxWinMask)<WriteSize)
542 {
543 if (WrittenBorder!=BlockStart)
544 {
545 UnpWriteArea(WrittenBorder,BlockStart);
546 WrittenBorder=BlockStart;
547 WriteSize=(uint)((UnpPtr-WrittenBorder)&MaxWinMask);
548 }
549 if (BlockLength<=WriteSize)
550 {
551 uint BlockEnd=(BlockStart+BlockLength)&MaxWinMask;
552 if (BlockStart<BlockEnd || BlockEnd==0)
553 VM.SetMemory(0,Window+BlockStart,BlockLength);
554 else
555 {
556 uint FirstPartLength=uint(MaxWinSize-BlockStart);
557 VM.SetMemory(0,Window+BlockStart,FirstPartLength);
558 VM.SetMemory(FirstPartLength,Window,BlockEnd);
559 }
560
561 VM_PreparedProgram *ParentPrg=&Filters30[flt->ParentFilter]->Prg;
562 VM_PreparedProgram *Prg=&flt->Prg;
563
564 ExecuteCode(Prg);
565
566 byte *FilteredData=Prg->FilteredData;
567 unsigned int FilteredDataSize=Prg->FilteredDataSize;
568
569 delete PrgStack[I];
570 PrgStack[I]=NULL;
571 while (I+1<PrgStack.Size())
572 {
573 UnpackFilter30 *NextFilter=PrgStack[I+1];
574 // It is required to check NextWindow here.
575 if (NextFilter==NULL || NextFilter->BlockStart!=BlockStart ||
576 NextFilter->BlockLength!=FilteredDataSize || NextFilter->NextWindow)

Callers

nothing calls this directly

Calls 3

SetMemoryMethod · 0.80
UnpWriteMethod · 0.80
SizeMethod · 0.45

Tested by

no test coverage detected