Exemplo n.º 1
0
 private void ExecuteCode(VMPreparedProgram Prg)
 {
     if (Prg.GlobalData.Count > 0)
     {
         Prg.InitR[6] = (int)this.writtenFileSize;
         this.rarVM.SetLowEndianValue(Prg.GlobalData, 0x24, (int)this.writtenFileSize);
         this.rarVM.SetLowEndianValue(Prg.GlobalData, 40, (int)Utility.URShift(this.writtenFileSize, 0x20));
         this.rarVM.execute(Prg);
     }
 }
Exemplo n.º 2
0
 private void ExecuteCode(VMPreparedProgram Prg)
 {
     if (Prg.GlobalData.Count > 0)
     {
         // Prg->InitR[6]=int64to32(WrittenFileSize);
         Prg.InitR[6] = (int)(writtenFileSize);
         // rarVM.SetLowEndianValue((uint
         // *)&Prg->GlobalData[0x24],int64to32(WrittenFileSize));
         rarVM.SetLowEndianValue(Prg.GlobalData, 0x24, (int)writtenFileSize);
         // rarVM.SetLowEndianValue((uint
         // *)&Prg->GlobalData[0x28],int64to32(WrittenFileSize>>32));
         rarVM.SetLowEndianValue(Prg.GlobalData, 0x28, (int)(Utility.URShift(writtenFileSize, 32)));
         rarVM.execute(Prg);
     }
 }
Exemplo n.º 3
0
        private void UnpWriteBuf()
        {
            int WrittenBorder = wrPtr;
            int WriteSize     = (unpPtr - WrittenBorder) & Compress.MAXWINMASK;

            for (int I = 0; I < prgStack.Count; I++)
            {
                UnpackFilter flt = prgStack[I];
                if (flt == null)
                {
                    continue;
                }
                if (flt.NextWindow)
                {
                    flt.NextWindow = false; // ->NextWindow=false;
                    continue;
                }
                int BlockStart  = flt.BlockStart;  // ->BlockStart;
                int BlockLength = flt.BlockLength; // ->BlockLength;
                if (((BlockStart - WrittenBorder) & Compress.MAXWINMASK) < WriteSize)
                {
                    if (WrittenBorder != BlockStart)
                    {
                        UnpWriteArea(WrittenBorder, BlockStart);
                        WrittenBorder = BlockStart;
                        WriteSize     = (unpPtr - WrittenBorder) & Compress.MAXWINMASK;
                    }
                    if (BlockLength <= WriteSize)
                    {
                        int BlockEnd = (BlockStart + BlockLength) & Compress.MAXWINMASK;
                        if (BlockStart < BlockEnd || BlockEnd == 0)
                        {
                            // VM.SetMemory(0,Window+BlockStart,BlockLength);
                            rarVM.setMemory(0, window, BlockStart, BlockLength);
                        }
                        else
                        {
                            int FirstPartLength = Compress.MAXWINSIZE - BlockStart;
                            // VM.SetMemory(0,Window+BlockStart,FirstPartLength);
                            rarVM.setMemory(0, window, BlockStart, FirstPartLength);
                            // VM.SetMemory(FirstPartLength,Window,BlockEnd);
                            rarVM.setMemory(FirstPartLength, window, 0, BlockEnd);
                        }

                        VMPreparedProgram ParentPrg = filters[flt.ParentFilter].Program;
                        VMPreparedProgram Prg       = flt.Program;

                        if (ParentPrg.GlobalData.Count > RarVM.VM_FIXEDGLOBALSIZE)
                        {
                            // copy global data from previous script execution if
                            // any
                            // Prg->GlobalData.Alloc(ParentPrg->GlobalData.Size());
                            // memcpy(&Prg->GlobalData[VM_FIXEDGLOBALSIZE],&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],ParentPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE);
                            Prg.GlobalData.Clear();
                            for (int i = 0; i < ParentPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++)
                            {
                                Prg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i];
                            }
                        }

                        ExecuteCode(Prg);

                        if (Prg.GlobalData.Count > RarVM.VM_FIXEDGLOBALSIZE)
                        {
                            // save global data for next script execution
                            if (ParentPrg.GlobalData.Count < Prg.GlobalData.Count)
                            {
                                //ParentPrg.GlobalData.Clear(); // ->GlobalData.Alloc(Prg->GlobalData.Size());
                                ParentPrg.GlobalData.SetSize(Prg.GlobalData.Count);
                            }
                            // memcpy(&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],&Prg->GlobalData[VM_FIXEDGLOBALSIZE],Prg->GlobalData.Size()-VM_FIXEDGLOBALSIZE);
                            for (int i = 0; i < Prg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++)
                            {
                                ParentPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = Prg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i];
                            }
                        }
                        else
                        {
                            ParentPrg.GlobalData.Clear();
                        }

                        int    FilteredDataOffset = Prg.FilteredDataOffset;
                        int    FilteredDataSize   = Prg.FilteredDataSize;
                        byte[] FilteredData       = new byte[FilteredDataSize];

                        for (int i = 0; i < FilteredDataSize; i++)
                        {
                            FilteredData[i] = rarVM.Mem[FilteredDataOffset + i]; // Prg.GlobalData.get(FilteredDataOffset
                            // +
                            // i);
                        }

                        prgStack[I] = null;
                        while (I + 1 < prgStack.Count)
                        {
                            UnpackFilter NextFilter = prgStack[I + 1];
                            if (NextFilter == null || NextFilter.BlockStart != BlockStart || NextFilter.BlockLength != FilteredDataSize || NextFilter.NextWindow)
                            {
                                break;
                            }
                            // apply several filters to same data block

                            rarVM.setMemory(0, FilteredData, 0, FilteredDataSize); // .SetMemory(0,FilteredData,FilteredDataSize);

                            VMPreparedProgram pPrg    = filters[NextFilter.ParentFilter].Program;
                            VMPreparedProgram NextPrg = NextFilter.Program;

                            if (pPrg.GlobalData.Count > RarVM.VM_FIXEDGLOBALSIZE)
                            {
                                // copy global data from previous script execution
                                // if any
                                // NextPrg->GlobalData.Alloc(ParentPrg->GlobalData.Size());
                                NextPrg.GlobalData.SetSize(pPrg.GlobalData.Count);
                                // memcpy(&NextPrg->GlobalData[VM_FIXEDGLOBALSIZE],&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],ParentPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE);
                                for (int i = 0; i < pPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++)
                                {
                                    NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i];
                                }
                            }

                            ExecuteCode(NextPrg);

                            if (NextPrg.GlobalData.Count > RarVM.VM_FIXEDGLOBALSIZE)
                            {
                                // save global data for next script execution
                                if (pPrg.GlobalData.Count < NextPrg.GlobalData.Count)
                                {
                                    pPrg.GlobalData.SetSize(NextPrg.GlobalData.Count);
                                }
                                // memcpy(&ParentPrg->GlobalData[VM_FIXEDGLOBALSIZE],&NextPrg->GlobalData[VM_FIXEDGLOBALSIZE],NextPrg->GlobalData.Size()-VM_FIXEDGLOBALSIZE);
                                for (int i = 0; i < NextPrg.GlobalData.Count - RarVM.VM_FIXEDGLOBALSIZE; i++)
                                {
                                    pPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i] = NextPrg.GlobalData[RarVM.VM_FIXEDGLOBALSIZE + i];
                                }
                            }
                            else
                            {
                                pPrg.GlobalData.Clear();
                            }
                            FilteredDataOffset = NextPrg.FilteredDataOffset;
                            FilteredDataSize   = NextPrg.FilteredDataSize;

                            FilteredData = new byte[FilteredDataSize];
                            for (int i = 0; i < FilteredDataSize; i++)
                            {
                                FilteredData[i] = NextPrg.GlobalData[FilteredDataOffset + i];
                            }

                            I++;
                            prgStack[I] = null;
                        }
                        writeStream.Write(FilteredData, 0, FilteredDataSize);
                        unpSomeRead      = true;
                        writtenFileSize += FilteredDataSize;
                        destUnpSize     -= FilteredDataSize;
                        WrittenBorder    = BlockEnd;
                        WriteSize        = (unpPtr - WrittenBorder) & Compress.MAXWINMASK;
                    }
                    else
                    {
                        for (int J = I; J < prgStack.Count; J++)
                        {
                            UnpackFilter filt = prgStack[J];
                            if (filt != null && filt.NextWindow)
                            {
                                filt.NextWindow = false;
                            }
                        }
                        wrPtr = WrittenBorder;
                        return;
                    }
                }
            }

            UnpWriteArea(WrittenBorder, unpPtr);
            wrPtr = unpPtr;
        }
Exemplo n.º 4
0
 internal UnpackFilter()
 {
     Program = new VMPreparedProgram();
 }
Exemplo n.º 5
0
        private void UnpWriteBuf()
        {
            int wrPtr = base.wrPtr;
            int num2  = (base.unpPtr - wrPtr) & Compress.MAXWINMASK;

            for (int i = 0; i < this.prgStack.Count; i++)
            {
                UnpackFilter filter = this.prgStack[i];
                if (filter != null)
                {
                    if (filter.NextWindow)
                    {
                        filter.NextWindow = false;
                        continue;
                    }
                    int blockStart  = filter.BlockStart;
                    int blockLength = filter.BlockLength;
                    if (((blockStart - wrPtr) & Compress.MAXWINMASK) < num2)
                    {
                        if (wrPtr != blockStart)
                        {
                            this.UnpWriteArea(wrPtr, blockStart);
                            wrPtr = blockStart;
                            num2  = (base.unpPtr - wrPtr) & Compress.MAXWINMASK;
                        }
                        if (blockLength <= num2)
                        {
                            int num8;
                            int dataSize = (blockStart + blockLength) & Compress.MAXWINMASK;
                            if ((blockStart < dataSize) || (dataSize == 0))
                            {
                                this.rarVM.setMemory(0, base.window, blockStart, blockLength);
                            }
                            else
                            {
                                int num7 = 0x400000 - blockStart;
                                this.rarVM.setMemory(0, base.window, blockStart, num7);
                                this.rarVM.setMemory(num7, base.window, 0, dataSize);
                            }
                            VMPreparedProgram program = this.filters[filter.ParentFilter].Program;
                            VMPreparedProgram prg     = filter.Program;
                            if (program.GlobalData.Count > 0x40)
                            {
                                prg.GlobalData.Clear();
                                num8 = 0;
                                while (num8 < (program.GlobalData.Count - 0x40))
                                {
                                    prg.GlobalData[0x40 + num8] = program.GlobalData[0x40 + num8];
                                    num8++;
                                }
                            }
                            this.ExecuteCode(prg);
                            if (prg.GlobalData.Count > 0x40)
                            {
                                if (program.GlobalData.Count < prg.GlobalData.Count)
                                {
                                    Utility.SetSize(program.GlobalData, prg.GlobalData.Count);
                                }
                                num8 = 0;
                                while (num8 < (prg.GlobalData.Count - 0x40))
                                {
                                    program.GlobalData[0x40 + num8] = prg.GlobalData[0x40 + num8];
                                    num8++;
                                }
                            }
                            else
                            {
                                program.GlobalData.Clear();
                            }
                            int    filteredDataOffset = prg.FilteredDataOffset;
                            int    filteredDataSize   = prg.FilteredDataSize;
                            byte[] data = new byte[filteredDataSize];
                            num8 = 0;
                            while (num8 < filteredDataSize)
                            {
                                data[num8] = this.rarVM.Mem[filteredDataOffset + num8];
                                num8++;
                            }
                            this.prgStack[i] = null;
                            while ((i + 1) < this.prgStack.Count)
                            {
                                UnpackFilter filter2 = this.prgStack[i + 1];
                                if ((((filter2 == null) || (filter2.BlockStart != blockStart)) || (filter2.BlockLength != filteredDataSize)) || filter2.NextWindow)
                                {
                                    break;
                                }
                                this.rarVM.setMemory(0, data, 0, filteredDataSize);
                                VMPreparedProgram program3 = this.filters[filter2.ParentFilter].Program;
                                VMPreparedProgram program4 = filter2.Program;
                                if (program3.GlobalData.Count > 0x40)
                                {
                                    Utility.SetSize(program4.GlobalData, program3.GlobalData.Count);
                                    num8 = 0;
                                    while (num8 < (program3.GlobalData.Count - 0x40))
                                    {
                                        program4.GlobalData[0x40 + num8] = program3.GlobalData[0x40 + num8];
                                        num8++;
                                    }
                                }
                                this.ExecuteCode(program4);
                                if (program4.GlobalData.Count > 0x40)
                                {
                                    if (program3.GlobalData.Count < program4.GlobalData.Count)
                                    {
                                        Utility.SetSize(program3.GlobalData, program4.GlobalData.Count);
                                    }
                                    num8 = 0;
                                    while (num8 < (program4.GlobalData.Count - 0x40))
                                    {
                                        program3.GlobalData[0x40 + num8] = program4.GlobalData[0x40 + num8];
                                        num8++;
                                    }
                                }
                                else
                                {
                                    program3.GlobalData.Clear();
                                }
                                filteredDataOffset = program4.FilteredDataOffset;
                                filteredDataSize   = program4.FilteredDataSize;
                                data = new byte[filteredDataSize];
                                for (num8 = 0; num8 < filteredDataSize; num8++)
                                {
                                    data[num8] = program4.GlobalData[filteredDataOffset + num8];
                                }
                                i++;
                                this.prgStack[i] = null;
                            }
                            base.writeStream.Write(data, 0, filteredDataSize);
                            base.unpSomeRead      = true;
                            this.writtenFileSize += filteredDataSize;
                            base.destUnpSize     -= filteredDataSize;
                            wrPtr = dataSize;
                            num2  = (base.unpPtr - wrPtr) & Compress.MAXWINMASK;
                            continue;
                        }
                        for (int j = i; j < this.prgStack.Count; j++)
                        {
                            UnpackFilter filter3 = this.prgStack[j];
                            if ((filter3 != null) && filter3.NextWindow)
                            {
                                filter3.NextWindow = false;
                            }
                        }
                        base.wrPtr = wrPtr;
                        return;
                    }
                }
            }
            this.UnpWriteArea(wrPtr, base.unpPtr);
            base.wrPtr = base.unpPtr;
        }