internal VMStandardFilterSignature(int length, uint crc, VMStandardFilters type)
 {
     this.Length = length;
     CRC = crc;
     this.Type = type;
 }
Esempio n. 2
0
        private void ExecuteStandardFilter(VMStandardFilters filterType)
        {
            switch (filterType)
            {

                case VMStandardFilters.VMSF_E8:
                case VMStandardFilters.VMSF_E8E9:
                    {
                        int dataSize = R[4];
                        long fileOffset = R[6] & unchecked((int)0xFFffFFff);

                        if (dataSize >= VM_GLOBALMEMADDR)
                        {
                            break;
                        }
                        int fileSize = 0x1000000;
                        byte cmpByte2 = (byte)((filterType == VMStandardFilters.VMSF_E8E9) ? 0xe9 : 0xe8);
                        for (int curPos = 0; curPos < dataSize - 4; )
                        {
                            byte curByte = Mem[curPos++];
                            if (curByte == 0xe8 || curByte == cmpByte2)
                            {
                                //		#ifdef PRESENT_INT32
                                //		            sint32 Offset=CurPos+FileOffset;
                                //		            sint32 Addr=GET_VALUE(false,Data);
                                //		            if (Addr<0)
                                //		            {
                                //		              if (Addr+Offset>=0)
                                //		                SET_VALUE(false,Data,Addr+FileSize);
                                //		            }
                                //		            else
                                //		              if (Addr<FileSize)
                                //		                SET_VALUE(false,Data,Addr-Offset);
                                //		#else
                                long offset = curPos + fileOffset;
                                long Addr = GetValue(false, Mem, curPos);
                                if ((Addr & unchecked((int)0x80000000)) != 0)
                                {
                                    if (((Addr + offset) & unchecked((int)0x80000000)) == 0)
                                        SetValue(false, Mem, curPos, (int)Addr + fileSize);
                                }
                                else
                                {
                                    if (((Addr - fileSize) & unchecked((int)0x80000000)) != 0)
                                    {
                                        SetValue(false, Mem, curPos, (int)(Addr - offset));
                                    }
                                }
                                //		#endif
                                curPos += 4;
                            }
                        }
                    }
                    break;

                case VMStandardFilters.VMSF_ITANIUM:
                    {

                        int dataSize = R[4];
                        long fileOffset = R[6] & unchecked((int)0xFFffFFff);

                        if (dataSize >= VM_GLOBALMEMADDR)
                        {
                            break;
                        }
                        int curPos = 0;
                        //UPGRADE_NOTE: Final was removed from the declaration of 'Masks '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                        byte[] Masks = new byte[] { 4, 4, 6, 6, 0, 0, 7, 7, 4, 4, 0, 0, 4, 4, 0, 0 };
                        fileOffset = Utilities.URShift(fileOffset, 4);

                        while (curPos < dataSize - 21)
                        {
                            int Byte = (Mem[curPos] & 0x1f) - 0x10;
                            if (Byte >= 0)
                            {

                                byte cmdMask = Masks[Byte];
                                if (cmdMask != 0)
                                    for (int i = 0; i <= 2; i++)
                                        if ((cmdMask & (1 << i)) != 0)
                                        {
                                            int startPos = i * 41 + 5;
                                            int opType = filterItanium_GetBits(curPos, startPos + 37, 4);
                                            if (opType == 5)
                                            {
                                                int offset = filterItanium_GetBits(curPos, startPos + 13, 20);
                                                filterItanium_SetBits(curPos, (int)(offset - fileOffset) & 0xfffff, startPos + 13, 20);
                                            }
                                        }
                            }
                            curPos += 16;
                            fileOffset++;
                        }
                    }
                    break;

                case VMStandardFilters.VMSF_DELTA:
                    {
                        int dataSize = R[4] & unchecked((int)0xFFffFFff);
                        int channels = R[0] & unchecked((int)0xFFffFFff);
                        int srcPos = 0;
                        int border = (dataSize * 2) & unchecked((int)0xFFffFFff);
                        SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, (int)dataSize);
                        if (dataSize >= VM_GLOBALMEMADDR / 2)
                        {
                            break;
                        }
                        //		 bytes from same channels are grouped to continual data blocks,
                        //		 so we need to place them back to their interleaving positions

                        for (int curChannel = 0; curChannel < channels; curChannel++)
                        {
                            byte PrevByte = 0;
                            for (int destPos = dataSize + curChannel; destPos < border; destPos += channels)
                            {
                                Mem[destPos] = (PrevByte = (byte)(PrevByte - Mem[srcPos++]));
                            }
                        }
                    }
                    break;

                case VMStandardFilters.VMSF_RGB:
                    {
                        // byte *SrcData=Mem,*DestData=SrcData+DataSize;
                        int dataSize = R[4], width = R[0] - 3, posR = R[1];
                        int channels = 3;
                        int srcPos = 0;
                        int destDataPos = dataSize;
                        SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize);
                        if (dataSize >= VM_GLOBALMEMADDR / 2 || posR < 0)
                        {
                            break;
                        }
                        for (int curChannel = 0; curChannel < channels; curChannel++)
                        {
                            long prevByte = 0;

                            for (int i = curChannel; i < dataSize; i += channels)
                            {
                                long predicted;
                                int upperPos = i - width;
                                if (upperPos >= 3)
                                {
                                    int upperDataPos = destDataPos + upperPos;
                                    int upperByte = Mem[(int)upperDataPos] & 0xff;
                                    int upperLeftByte = Mem[upperDataPos - 3] & 0xff;
                                    predicted = prevByte + upperByte - upperLeftByte;
                                    int pa = System.Math.Abs((int)(predicted - prevByte));
                                    int pb = System.Math.Abs((int)(predicted - upperByte));
                                    int pc = System.Math.Abs((int)(predicted - upperLeftByte));
                                    if (pa <= pb && pa <= pc)
                                    {
                                        predicted = prevByte;
                                    }
                                    else
                                    {
                                        if (pb <= pc)
                                        {
                                            predicted = upperByte;
                                        }
                                        else
                                        {
                                            predicted = upperLeftByte;
                                        }
                                    }
                                }
                                else
                                {
                                    predicted = prevByte;
                                }

                                prevByte = (predicted - Mem[srcPos++] & 0xff) & 0xff;
                                Mem[destDataPos + i] = (byte)(prevByte & 0xff);
                            }
                        }
                        for (int i = posR, border = dataSize - 2; i < border; i += 3)
                        {
                            byte G = Mem[destDataPos + i + 1];
                            Mem[destDataPos + i] = (byte)(Mem[destDataPos + i] + G);
                            Mem[destDataPos + i + 2] = (byte)(Mem[destDataPos + i + 2] + G);
                        }
                    }
                    break;

                case VMStandardFilters.VMSF_AUDIO:
                    {
                        int dataSize = R[4], channels = R[0];
                        int srcPos = 0;
                        int destDataPos = dataSize;
                        //byte *SrcData=Mem,*DestData=SrcData+DataSize;
                        SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize);
                        if (dataSize >= VM_GLOBALMEMADDR / 2)
                        {
                            break;
                        }
                        for (int curChannel = 0; curChannel < channels; curChannel++)
                        {
                            long prevByte = 0;
                            long prevDelta = 0;
                            long[] Dif = new long[7];
                            int D1 = 0, D2 = 0, D3;
                            int K1 = 0, K2 = 0, K3 = 0;

                            for (int i = curChannel, byteCount = 0; i < dataSize; i += channels, byteCount++)
                            {
                                D3 = D2;
                                D2 = (int)prevDelta - D1;
                                D1 = (int)prevDelta;

                                long predicted = 8 * prevByte + K1 * D1 + K2 * D2 + K3 * D3;
                                predicted = (Utilities.URShift(predicted, 3)) & 0xff;

                                long curByte = Mem[srcPos++] & 0xff;

                                predicted = (predicted - curByte) & UINT_MASK;
                                Mem[destDataPos + i] = (byte)predicted;
                                prevDelta = (byte)(predicted - prevByte);
                                prevByte = predicted;

                                int D = ((byte)curByte) << 3;

                                Dif[0] += System.Math.Abs(D);
                                Dif[1] += System.Math.Abs(D - D1);
                                Dif[2] += System.Math.Abs(D + D1);
                                Dif[3] += System.Math.Abs(D - D2);
                                Dif[4] += System.Math.Abs(D + D2);
                                Dif[5] += System.Math.Abs(D - D3);
                                Dif[6] += System.Math.Abs(D + D3);

                                if ((byteCount & 0x1f) == 0)
                                {
                                    long minDif = Dif[0], numMinDif = 0;
                                    Dif[0] = 0;
                                    for (int j = 1; j < Dif.Length; j++)
                                    {
                                        if (Dif[j] < minDif)
                                        {
                                            minDif = Dif[j];
                                            numMinDif = j;
                                        }
                                        Dif[j] = 0;
                                    }
                                    switch ((int)numMinDif)
                                    {

                                        case 1:
                                            if (K1 >= -16)
                                                K1--;
                                            break;

                                        case 2:
                                            if (K1 < 16)
                                                K1++;
                                            break;

                                        case 3:
                                            if (K2 >= -16)
                                                K2--;
                                            break;

                                        case 4:
                                            if (K2 < 16)
                                                K2++;
                                            break;

                                        case 5:
                                            if (K3 >= -16)
                                                K3--;
                                            break;

                                        case 6:
                                            if (K3 < 16)
                                                K3++;
                                            break;
                                    }
                                }
                            }
                        }
                    }
                    break;

                case VMStandardFilters.VMSF_UPCASE:
                    {
                        int dataSize = R[4], srcPos = 0, destPos = dataSize;
                        if (dataSize >= VM_GLOBALMEMADDR / 2)
                        {
                            break;
                        }
                        while (srcPos < dataSize)
                        {
                            byte curByte = Mem[srcPos++];
                            if (curByte == 2 && (curByte = Mem[srcPos++]) != 2)
                            {
                                curByte = (byte)(curByte - 32);
                            }
                            Mem[destPos++] = curByte;
                        }
                        SetValue(false, Mem, VM_GLOBALMEMADDR + 0x1c, destPos - dataSize);
                        SetValue(false, Mem, VM_GLOBALMEMADDR + 0x20, dataSize);
                    }
                    break;
            }
        }
Esempio n. 3
0
 internal VMStandardFilterSignature(int length, uint crc, VMStandardFilters type)
 {
     this.Length = length;
     this.CRC    = crc;
     this.Type   = type;
 }
 internal VMStandardFilterSignature(int length, uint crc, VMStandardFilters type)
 {
     Length = length;
     CRC    = crc;
     Type   = type;
 }
Esempio n. 5
0
        //private bool ExecuteCode(List<VMPreparedCommand> preparedCode, int cmdCount)
        //{
        //    VMFlags flags;
        //    VMFlags flags2;
        //    int num3;
        //    int num4;
        //    int num5;
        //    int num6;
        //    int num7;
        //    int num9;
        //    bool flag2;
        //    this.maxOpCount = 0x17d7840;
        //    this.codeSize = cmdCount;
        //    this.IP = 0;
        //Label_10B0:
        //    flag2 = true;
        //    VMPreparedCommand command = preparedCode[this.IP];
        //    int operand = this.GetOperand(command.Op1);
        //    int offset = this.GetOperand(command.Op2);
        //    switch (command.OpCode)
        //    {
        //        case VMCommands.VM_MOV:
        //            this.SetValue(command.IsByteMode, this.Mem, operand, this.GetValue(command.IsByteMode, this.Mem, offset));
        //            break;
        //        case VMCommands.VM_CMP:
        //            flags = (VMFlags) this.GetValue(command.IsByteMode, this.Mem, operand);
        //            flags2 = flags - this.GetValue(command.IsByteMode, this.Mem, offset);
        //            if (flags2 != VMFlags.None)
        //            {
        //                this.flags = (flags2 > flags) ? VMFlags.VM_FC : (flags2 & VMFlags.VM_FS);
        //                break;
        //            }
        //            this.flags = VMFlags.VM_FZ;
        //            break;
        //        case VMCommands.VM_ADD:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num4 = (num3 + this.GetValue(command.IsByteMode, this.Mem, offset)) & ((int) (-1L));
        //            if (!command.IsByteMode)
        //            {
        //                this.flags = (num4 < num3) ? VMFlags.VM_FC : ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS));
        //            }
        //            else
        //            {
        //                num4 &= 0xff;
        //                this.flags = (num4 < num3) ? VMFlags.VM_FC : ((num4 == 0) ? VMFlags.VM_FZ : (((num4 & 0x80) != 0) ? VMFlags.VM_FS : VMFlags.None));
        //            }
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_SUB:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num4 = (int)(((long)num3 & (0xffffffffL - (long)this.GetValue(command.IsByteMode, this.Mem, offset))) & unchecked((int)0xFFffFFff));
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : ((num4 > num3) ? VMFlags.VM_FC : (((VMFlags) num4) & VMFlags.VM_FS));
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_JZ:
        //            if ((this.flags & VMFlags.VM_FZ) == VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JNZ:
        //            if ((this.flags & VMFlags.VM_FZ) != VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_INC:
        //            num4 = (int)((long)GetValue(command.IsByteMode, this.Mem, operand) & 0xFFffFFffL + 1L);//this.GetValue(command.IsByteMode, this.Mem, operand) & ((int) 0x100000000L);
        //            if (command.IsByteMode)
        //            {
        //                num4 &= 0xff;
        //            }
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            break;
        //        case VMCommands.VM_DEC:
        //            num4 = (int)((long)this.GetValue(command.IsByteMode, Mem, operand) & 0xFFffFFff - 1);//this.GetValue(command.IsByteMode, this.Mem, operand) & ((int) 0xfffffffeL);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            break;
        //        case VMCommands.VM_JMP:
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_XOR:
        //            num4 = this.GetValue(command.IsByteMode, this.Mem, operand) ^ this.GetValue(command.IsByteMode, this.Mem, offset);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_AND:
        //            num4 = this.GetValue(command.IsByteMode, this.Mem, operand) & this.GetValue(command.IsByteMode, this.Mem, offset);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_OR:
        //            num4 = this.GetValue(command.IsByteMode, this.Mem, operand) | this.GetValue(command.IsByteMode, this.Mem, offset);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_TEST:
        //            num4 = this.GetValue(command.IsByteMode, this.Mem, operand) & this.GetValue(command.IsByteMode, this.Mem, offset);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS);
        //            break;
        //        case VMCommands.VM_JS:
        //            if ((this.flags & VMFlags.VM_FS) == VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JNS:
        //            if ((this.flags & VMFlags.VM_FS) != VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JB:
        //            if ((this.flags & VMFlags.VM_FC) == VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JBE:
        //            if ((this.flags & (VMFlags.VM_FZ | VMFlags.VM_FC)) == VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JA:
        //            if ((this.flags & (VMFlags.VM_FZ | VMFlags.VM_FC)) != VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_JAE:
        //            if ((this.flags & VMFlags.VM_FC) != VMFlags.None)
        //            {
        //                break;
        //            }
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_PUSH:
        //            this.R[7] -= 4;
        //            this.SetValue(false, this.Mem, this.R[7] & VM_MEMMASK, this.GetValue(false, this.Mem, operand));
        //            break;
        //        case VMCommands.VM_POP:
        //            this.SetValue(false, this.Mem, operand, this.GetValue(false, this.Mem, this.R[7] & VM_MEMMASK));
        //            this.R[7] += 4;
        //            break;
        //        case VMCommands.VM_CALL:
        //            this.R[7] -= 4;
        //            this.SetValue(false, this.Mem, this.R[7] & VM_MEMMASK, this.IP + 1);
        //            this.setIP(this.GetValue(false, this.Mem, operand));
        //            goto Label_10B0;
        //        case VMCommands.VM_RET:
        //            if (this.R[7] < 0x40000)
        //            {
        //                this.setIP(this.GetValue(false, this.Mem, this.R[7] & VM_MEMMASK));
        //                this.R[7] += 4;
        //                goto Label_10B0;
        //            }
        //            return true;
        //        case VMCommands.VM_NOT:
        //            this.SetValue(command.IsByteMode, this.Mem, operand, ~this.GetValue(command.IsByteMode, this.Mem, operand));
        //            break;
        //        case VMCommands.VM_SHL:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num5 = this.GetValue(command.IsByteMode, this.Mem, offset);
        //            num4 = num3 << num5;
        //            this.flags = ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS)) | ((((num3 << (num5 - 1)) & -2147483648) != 0) ? VMFlags.VM_FC : VMFlags.None);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_SHR:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num5 = this.GetValue(command.IsByteMode, this.Mem, offset);
        //            num4 = Utility.URShift(num3, num5);
        //            this.flags = ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS)) | (((VMFlags) Utility.URShift(num3, (int) (num5 - 1))) & VMFlags.VM_FC);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_SAR:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num5 = this.GetValue(command.IsByteMode, this.Mem, offset);
        //            num4 = num3 >> num5;
        //            this.flags = ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS)) | (((VMFlags) (num3 >> (num5 - 1))) & VMFlags.VM_FC);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_NEG:
        //            num4 = -this.GetValue(command.IsByteMode, this.Mem, operand);
        //            this.flags = (num4 == 0) ? VMFlags.VM_FZ : (VMFlags.VM_FC | (((VMFlags) num4) & VMFlags.VM_FS));
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_PUSHA:
        //            num6 = 0;
        //            for (num7 = this.R[7] - 4; num6 < 8; num7 -= 4)
        //            {
        //                this.SetValue(false, this.Mem, num7 & VM_MEMMASK, this.R[num6]);
        //                num6++;
        //            }
        //            this.R[7] -= 0x20;
        //            break;
        //        case VMCommands.VM_POPA:
        //            num6 = 0;
        //            for (num7 = this.R[7]; num6 < 8; num7 += 4)
        //            {
        //                this.R[7 - num6] = this.GetValue(false, this.Mem, num7 & VM_MEMMASK);
        //                num6++;
        //            }
        //            break;
        //        case VMCommands.VM_PUSHF:
        //            this.R[7] -= 4;
        //            this.SetValue(false, this.Mem, this.R[7] & VM_MEMMASK, (int) this.flags);
        //            break;
        //        case VMCommands.VM_POPF:
        //            this.flags = (VMFlags) this.GetValue(false, this.Mem, this.R[7] & VM_MEMMASK);
        //            this.R[7] += 4;
        //            break;
        //        case VMCommands.VM_MOVZX:
        //            this.SetValue(false, this.Mem, operand, this.GetValue(true, this.Mem, offset));
        //            break;
        //        case VMCommands.VM_MOVSX:
        //            this.SetValue(false, this.Mem, operand, (byte) this.GetValue(true, this.Mem, offset));
        //            break;
        //        case VMCommands.VM_XCHG:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, this.GetValue(command.IsByteMode, this.Mem, offset));
        //            this.SetValue(command.IsByteMode, this.Mem, offset, num3);
        //            break;
        //        case VMCommands.VM_MUL:
        //            num4 = (int) (((this.GetValue(command.IsByteMode, this.Mem, operand) & (0xffffffffL * this.GetValue(command.IsByteMode, this.Mem, offset))) & ulong.MaxValue) & ulong.MaxValue);
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_DIV:
        //        {
        //            int num8 = this.GetValue(command.IsByteMode, this.Mem, offset);
        //            if (num8 != 0)
        //            {
        //                num4 = this.GetValue(command.IsByteMode, this.Mem, operand) / num8;
        //                this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            }
        //            break;
        //        }
        //        case VMCommands.VM_ADC:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num9 = ((int) this.flags) & 1;
        //            num4 = (int) (((num3 & (0xffffffffL + this.GetValue(command.IsByteMode, this.Mem, offset))) & (0xffffffffL + num9)) & ulong.MaxValue);
        //            if (command.IsByteMode)
        //            {
        //                num4 &= 0xff;
        //            }
        //            this.flags = ((num4 < num3) || ((num4 == num3) && (num9 != 0))) ? VMFlags.VM_FC : ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS));
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_SBB:
        //            num3 = this.GetValue(command.IsByteMode, this.Mem, operand);
        //            num9 = ((int) this.flags) & 1;
        //            num4 = (int) (((num3 & (0xffffffffL - this.GetValue(command.IsByteMode, this.Mem, offset))) & (0xffffffffL - num9)) & ulong.MaxValue);
        //            if (command.IsByteMode)
        //            {
        //                num4 &= 0xff;
        //            }
        //            this.flags = ((num4 > num3) || ((num4 == num3) && (num9 != 0))) ? VMFlags.VM_FC : ((num4 == 0) ? VMFlags.VM_FZ : (((VMFlags) num4) & VMFlags.VM_FS));
        //            this.SetValue(command.IsByteMode, this.Mem, operand, num4);
        //            break;
        //        case VMCommands.VM_MOVB:
        //            this.SetValue(true, this.Mem, operand, this.GetValue(true, this.Mem, offset));
        //            break;
        //        case VMCommands.VM_MOVD:
        //            this.SetValue(false, this.Mem, operand, this.GetValue(false, this.Mem, offset));
        //            break;
        //        case VMCommands.VM_CMPB:
        //            flags = (VMFlags) this.GetValue(true, this.Mem, operand);
        //            flags2 = flags - this.GetValue(true, this.Mem, offset);
        //            if (flags2 != VMFlags.None)
        //            {
        //                this.flags = (flags2 > flags) ? VMFlags.VM_FC : (flags2 & VMFlags.VM_FS);
        //                break;
        //            }
        //            this.flags = VMFlags.VM_FZ;
        //            break;
        //        case VMCommands.VM_CMPD:
        //            flags = (VMFlags) this.GetValue(false, this.Mem, operand);
        //            flags2 = flags - this.GetValue(false, this.Mem, offset);
        //            if (flags2 != VMFlags.None)
        //            {
        //                this.flags = (flags2 > flags) ? VMFlags.VM_FC : (flags2 & VMFlags.VM_FS);
        //                break;
        //            }
        //            this.flags = VMFlags.VM_FZ;
        //            break;
        //        case VMCommands.VM_ADDB:
        //            this.SetValue(true, this.Mem, operand, (int) ((this.GetValue(true, this.Mem, operand) & (0xffffffffL + this.GetValue(true, this.Mem, offset))) & ulong.MaxValue));
        //            break;
        //        case VMCommands.VM_ADDD:
        //            this.SetValue(false, this.Mem, operand, (int) ((this.GetValue(false, this.Mem, operand) & (0xffffffffL + this.GetValue(false, this.Mem, offset))) & ulong.MaxValue));
        //            break;
        //        case VMCommands.VM_SUBB:
        //            this.SetValue(true, this.Mem, operand, (int) ((this.GetValue(true, this.Mem, operand) & (0xffffffffL - this.GetValue(true, this.Mem, offset))) & ulong.MaxValue));
        //            break;
        //        case VMCommands.VM_SUBD:
        //            this.SetValue(false, this.Mem, operand, (int) ((this.GetValue(false, this.Mem, operand) & (0xffffffffL - this.GetValue(false, this.Mem, offset))) & ulong.MaxValue));
        //            break;
        //        case VMCommands.VM_INCB:
        //            this.SetValue(true, this.Mem, operand, this.GetValue(true, this.Mem, operand) & ((int) 0x100000000L));
        //            break;
        //        case VMCommands.VM_INCD:
        //            this.SetValue(false, this.Mem, operand, this.GetValue(false, this.Mem, operand) & ((int) 0x100000000L));
        //            break;
        //        case VMCommands.VM_DECB:
        //            this.SetValue(true, this.Mem, operand, this.GetValue(true, this.Mem, operand) & ((int) 0xfffffffeL));
        //            break;
        //        case VMCommands.VM_DECD:
        //            this.SetValue(false, this.Mem, operand, this.GetValue(false, this.Mem, operand) & ((int) 0xfffffffeL));
        //            break;
        //        case VMCommands.VM_NEGB:
        //            this.SetValue(true, this.Mem, operand, -this.GetValue(true, this.Mem, operand));
        //            break;
        //        case VMCommands.VM_NEGD:
        //            this.SetValue(false, this.Mem, operand, -this.GetValue(false, this.Mem, operand));
        //            break;
        //        case VMCommands.VM_STANDARD:
        //            this.ExecuteStandardFilter((VMStandardFilters) command.Op1.Data);
        //            break;
        //    }
        //    this.IP++;
        //    this.maxOpCount--;
        //    goto Label_10B0;
        //}
        private void ExecuteStandardFilter(VMStandardFilters filterType)
        {
            int num;
            long num2;
            int num5;
            byte num6;
            int num11;
            int num15;
            int num16;
            int num17;
            int num18;
            int num20;
            int num23;
            long num24;
            long num25;
            switch (filterType)
            {
                case VMStandardFilters.VMSF_E8:
                case VMStandardFilters.VMSF_E8E9:
                    num = this.R[4];
                    num2 = this.R[6] & -1;
                    if (num < 0x3c000)
                    {
                        int num3 = 0x1000000;
                        byte num4 = (filterType == VMStandardFilters.VMSF_E8E9) ? ((byte) 0xe9) : ((byte) 0xe8);
                        num5 = 0;
                        while (num5 < (num - 4))
                        {
                            num6 = this.Mem[num5++];
                            if ((num6 == 0xe8) || (num6 == num4))
                            {
                                long num7 = num5 + num2;
                                long num8 = this.GetValue(false, this.Mem, num5);
                                if ((num8 & -2147483648L) != 0L)
                                {
                                    if (((num8 + num7) & -2147483648L) == 0L)
                                    {
                                        this.SetValue(false, this.Mem, num5, ((int) num8) + num3);
                                    }
                                }
                                else if (((num8 - num3) & -2147483648L) != 0L)
                                {
                                    this.SetValue(false, this.Mem, num5, (int) (num8 - num7));
                                }
                                num5 += 4;
                            }
                        }
                        break;
                    }
                    break;

                case VMStandardFilters.VMSF_ITANIUM:
                    num = this.R[4];
                    num2 = this.R[6] & -1;
                    if (num < 0x3c000)
                    {
                        num5 = 0;
                        byte[] buffer = new byte[] { 4, 4, 6, 6, 0, 0, 7, 7, 4, 4, 0, 0, 4, 4, 0, 0 };
                        for (num2 = Utility.URShift(num2, 4); num5 < (num - 0x15); num2 += 1L)
                        {
                            int index = (this.Mem[num5] & 0x1f) - 0x10;
                            if (index >= 0)
                            {
                                byte num10 = buffer[index];
                                if (num10 != 0)
                                {
                                    num11 = 0;
                                    while (num11 <= 2)
                                    {
                                        if ((num10 & (((int) 1) << num11)) != 0)
                                        {
                                            int num12 = (num11 * 0x29) + 5;
                                            if (this.filterItanium_GetBits(num5, num12 + 0x25, 4) == 5)
                                            {
                                                int num14 = this.filterItanium_GetBits(num5, num12 + 13, 20);
                                                this.filterItanium_SetBits(num5, (num14 - ((int) num2)) & 0xfffff, num12 + 13, 20);
                                            }
                                        }
                                        num11++;
                                    }
                                }
                            }
                            num5 += 0x10;
                        }
                        break;
                    }
                    break;

                case VMStandardFilters.VMSF_RGB:
                {
                    num = this.R[4];
                    int num21 = this.R[0] - 3;
                    int num22 = this.R[1];
                    num15 = 3;
                    num16 = 0;
                    num23 = num;
                    this.SetValue(false, this.Mem, 0x3c020, num);
                    if ((num < 0x1e000) && (num22 >= 0))
                    {
                        num18 = 0;
                        while (num18 < num15)
                        {
                            num24 = 0L;
                            for (num11 = num18; num11 < num; num11 += num15)
                            {
                                int num26 = num11 - num21;
                                if (num26 >= 3)
                                {
                                    int num27 = num23 + num26;
                                    int num28 = this.Mem[num27] & 0xff;
                                    int num29 = this.Mem[num27 - 3] & 0xff;
                                    num25 = (num24 + num28) - num29;
                                    int num30 = Math.Abs((int) (num25 - num24));
                                    int num31 = Math.Abs((int) (((int) num25) - num28));
                                    int num32 = Math.Abs((int) (((int) num25) - num29));
                                    if ((num30 <= num31) && (num30 <= num32))
                                    {
                                        num25 = num24;
                                    }
                                    else if (num31 <= num32)
                                    {
                                        num25 = num28;
                                    }
                                    else
                                    {
                                        num25 = num29;
                                    }
                                }
                                else
                                {
                                    num25 = num24;
                                }
                                num24 = (num25 - this.Mem[num16++]) & 0xffL;
                                this.Mem[num23 + num11] = (byte) (num24 & 0xffL);
                            }
                            num18++;
                        }
                        num11 = num22;
                        num17 = num - 2;
                        while (num11 < num17)
                        {
                            byte num33 = this.Mem[(num23 + num11) + 1];
                            this.Mem[num23 + num11] = (byte) (this.Mem[num23 + num11] + num33);
                            this.Mem[(num23 + num11) + 2] = (byte) (this.Mem[(num23 + num11) + 2] + num33);
                            num11 += 3;
                        }
                        break;
                    }
                    break;
                }
                case VMStandardFilters.VMSF_AUDIO:
                    num = this.R[4];
                    num15 = this.R[0];
                    num16 = 0;
                    num23 = num;
                    this.SetValue(false, this.Mem, 0x3c020, num);
                    if (num < 0x1e000)
                    {
                        num18 = 0;
                        while (num18 < num15)
                        {
                            num24 = 0L;
                            long num34 = 0L;
                            long[] numArray = new long[7];
                            int num35 = 0;
                            int num36 = 0;
                            int num38 = 0;
                            int num39 = 0;
                            int num40 = 0;
                            num11 = num18;
                            for (int i = 0; num11 < num; i++)
                            {
                                int num37 = num36;
                                num36 = ((int) num34) - num35;
                                num35 = (int) num34;
                                num25 = (((8L * num24) + (num38 * num35)) + (num39 * num36)) + (num40 * num37);
                                num25 = Utility.URShift(num25, 3) & 0xffL;
                                long num42 = this.Mem[num16++];
                                num25 -= num42;
                                this.Mem[num23 + num11] = (byte) num25;
                                num34 = (byte) (num25 - num24);
                                if (num34 >= 0x80L)
                                {
                                    num34 = -(0x100L - num34);
                                }
                                num24 = num25;
                                if (num42 >= 0x80L)
                                {
                                    num42 = -(0x100L - num42);
                                }
                                int num43 = ((int) num42) << 3;
                                numArray[0] += Math.Abs(num43);
                                numArray[1] += Math.Abs((int) (num43 - num35));
                                numArray[2] += Math.Abs((int) (num43 + num35));
                                numArray[3] += Math.Abs((int) (num43 - num36));
                                numArray[4] += Math.Abs((int) (num43 + num36));
                                numArray[5] += Math.Abs((int) (num43 - num37));
                                numArray[6] += Math.Abs((int) (num43 + num37));
                                if ((i & 0x1f) == 0)
                                {
                                    long num44 = numArray[0];
                                    long num45 = 0L;
                                    numArray[0] = 0L;
                                    for (int j = 1; j < numArray.Length; j++)
                                    {
                                        if (numArray[j] < num44)
                                        {
                                            num44 = numArray[j];
                                            num45 = j;
                                        }
                                        numArray[j] = 0L;
                                    }
                                    switch (((int) num45))
                                    {
                                        case 1:
                                            if (num38 >= -16)
                                            {
                                                num38--;
                                            }
                                            break;

                                        case 2:
                                            if (num38 < 0x10)
                                            {
                                                num38++;
                                            }
                                            break;

                                        case 3:
                                            if (num39 >= -16)
                                            {
                                                num39--;
                                            }
                                            break;

                                        case 4:
                                            if (num39 < 0x10)
                                            {
                                                num39++;
                                            }
                                            break;

                                        case 5:
                                            if (num40 >= -16)
                                            {
                                                num40--;
                                            }
                                            break;

                                        case 6:
                                            if (num40 < 0x10)
                                            {
                                                num40++;
                                            }
                                            break;
                                    }
                                }
                                num11 += num15;
                            }
                            num18++;
                        }
                        break;
                    }
                    break;

                case VMStandardFilters.VMSF_DELTA:
                    num = this.R[4] & -1;
                    num15 = this.R[0] & -1;
                    num16 = 0;
                    num17 = (num * 2) & -1;
                    this.SetValue(false, this.Mem, 0x3c020, num);
                    if (num < 0x1e000)
                    {
                        for (num18 = 0; num18 < num15; num18++)
                        {
                            byte num19 = 0;
                            for (num20 = num + num18; num20 < num17; num20 += num15)
                            {
                                this.Mem[num20] = num19 = (byte) (num19 - this.Mem[num16++]);
                            }
                        }
                        break;
                    }
                    break;

                case VMStandardFilters.VMSF_UPCASE:
                    num = this.R[4];
                    num16 = 0;
                    num20 = num;
                    if (num < 0x1e000)
                    {
                        while (num16 < num)
                        {
                            num6 = this.Mem[num16++];
                            if ((num6 == 2) && ((num6 = this.Mem[num16++]) != 2))
                            {
                                num6 = (byte) (num6 - 0x20);
                            }
                            this.Mem[num20++] = num6;
                        }
                        this.SetValue(false, this.Mem, 0x3c01c, num20 - num);
                        this.SetValue(false, this.Mem, 0x3c020, num);
                        break;
                    }
                    break;
            }
        }