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

Method AddVMCode

Libraries/unrar/unpack30.cpp:361–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359
360
361bool Unpack::AddVMCode(uint FirstByte,byte *Code,uint CodeSize)
362{
363 VMCodeInp.InitBitInput();
364 memcpy(VMCodeInp.InBuf,Code,Min(BitInput::MAX_SIZE,CodeSize));
365 VM.Init();
366
367 uint FiltPos;
368 if ((FirstByte & 0x80)!=0)
369 {
370 FiltPos=RarVM::ReadData(VMCodeInp);
371 if (FiltPos==0)
372 InitFilters30(false);
373 else
374 FiltPos--;
375 }
376 else
377 FiltPos=LastFilter; // Use the same filter as last time.
378
379 if (FiltPos>Filters30.Size() || FiltPos>OldFilterLengths.Size())
380 return false;
381 LastFilter=FiltPos;
382 bool NewFilter=(FiltPos==Filters30.Size());
383
384 UnpackFilter30 *StackFilter=new UnpackFilter30; // New filter for PrgStack.
385
386 UnpackFilter30 *Filter;
387 if (NewFilter) // New filter code, never used before since VM reset.
388 {
389 if (FiltPos>MAX3_UNPACK_FILTERS)
390 {
391 // Too many different filters, corrupt archive.
392 delete StackFilter;
393 return false;
394 }
395
396 Filters30.Add(1);
397 Filters30[Filters30.Size()-1]=Filter=new UnpackFilter30;
398 StackFilter->ParentFilter=(uint)(Filters30.Size()-1);
399
400 // Reserve one item to store the data block length of our new filter
401 // entry. We'll set it to real block length below, after reading it.
402 // But we need to initialize it now, because when processing corrupt
403 // data, we can access this item even before we set it to real value.
404 OldFilterLengths.Push(0);
405 }
406 else // Filter was used in the past.
407 {
408 Filter=Filters30[FiltPos];
409 StackFilter->ParentFilter=FiltPos;
410 }
411
412 uint EmptyCount=0;
413 for (uint I=0;I<PrgStack.Size();I++)
414 {
415 PrgStack[I-EmptyCount]=PrgStack[I];
416 if (PrgStack[I]==NULL)
417 EmptyCount++;
418 if (EmptyCount>0)

Callers

nothing calls this directly

Calls 9

InitBitInputMethod · 0.80
AddMethod · 0.80
PushMethod · 0.80
fgetbitsMethod · 0.80
faddbitsMethod · 0.80
OverflowMethod · 0.80
PrepareMethod · 0.80
InitMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected