public bool CheckStructure()
        {
            const int kNumCodersMax = 32; // don't change it
            const int kMaskSize     = 32; // it must be >= kNumCodersMax
            const int kNumBindsMax  = 32;

            if (Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
            {
                return(false);
            }

            {
                var v = new BitVector(BindPairs.Count + PackStreams.Count);

                for (int i = 0; i < BindPairs.Count; i++)
                {
                    if (v.GetAndSet(BindPairs[i].InIndex))
                    {
                        return(false);
                    }
                }

                for (int i = 0; i < PackStreams.Count; i++)
                {
                    if (v.GetAndSet(PackStreams[i]))
                    {
                        return(false);
                    }
                }
            }

            {
                var v = new BitVector(UnpackSizes.Count);
                for (int i = 0; i < BindPairs.Count; i++)
                {
                    if (v.GetAndSet(BindPairs[i].OutIndex))
                    {
                        return(false);
                    }
                }
            }

            uint[] mask = new uint[kMaskSize];

            {
                List <int> inStreamToCoder  = new List <int>();
                List <int> outStreamToCoder = new List <int>();
                for (int i = 0; i < Coders.Count; i++)
                {
                    CCoderInfo coder = Coders[i];
                    for (int j = 0; j < coder.NumInStreams; j++)
                    {
                        inStreamToCoder.Add(i);
                    }
                    for (int j = 0; j < coder.NumOutStreams; j++)
                    {
                        outStreamToCoder.Add(i);
                    }
                }

                for (int i = 0; i < BindPairs.Count; i++)
                {
                    CBindPair bp = BindPairs[i];
                    mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
                }
            }

            for (int i = 0; i < kMaskSize; i++)
            {
                for (int j = 0; j < kMaskSize; j++)
                {
                    if (((1u << j) & mask[i]) != 0)
                    {
                        mask[i] |= mask[j];
                    }
                }
            }

            for (int i = 0; i < kMaskSize; i++)
            {
                if (((1u << i) & mask[i]) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public bool CheckStructure()
        {
            int num;
            int num2;

            if ((this.Coders.Count > 0x20) || (this.BindPairs.Count > 0x20))
            {
                return(false);
            }
            BitVector vector = new BitVector(this.BindPairs.Count + this.PackStreams.Count);

            for (num = 0; num < this.BindPairs.Count; num++)
            {
                if (vector.GetAndSet(this.BindPairs[num].InIndex))
                {
                    return(false);
                }
            }
            for (num = 0; num < this.PackStreams.Count; num++)
            {
                if (vector.GetAndSet(this.PackStreams[num]))
                {
                    return(false);
                }
            }
            vector = new BitVector(this.UnpackSizes.Count);
            for (num = 0; num < this.BindPairs.Count; num++)
            {
                if (vector.GetAndSet(this.BindPairs[num].OutIndex))
                {
                    return(false);
                }
            }
            uint[]     numArray = new uint[0x20];
            List <int> list     = new List <int>();
            List <int> list2    = new List <int>();

            for (num = 0; num < this.Coders.Count; num++)
            {
                CCoderInfo info = this.Coders[num];
                num2 = 0;
                while (num2 < info.NumInStreams)
                {
                    list.Add(num);
                    num2++;
                }
                num2 = 0;
                while (num2 < info.NumOutStreams)
                {
                    list2.Add(num);
                    num2++;
                }
            }
            for (num = 0; num < this.BindPairs.Count; num++)
            {
                CBindPair pair = this.BindPairs[num];
                numArray[list[pair.InIndex]] |= ((uint)1) << list2[pair.OutIndex];
            }
            for (num = 0; num < 0x20; num++)
            {
                for (num2 = 0; num2 < 0x20; num2++)
                {
                    if (((((int)1) << num2) & numArray[num]) != 0)
                    {
                        numArray[num] |= numArray[num2];
                    }
                }
            }
            for (num = 0; num < 0x20; num++)
            {
                if (((((int)1) << num) & numArray[num]) != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        private void GetNextFolderItem(CFolder folder)
        {
            #if DEBUG
            Log.WriteLine("-- GetNextFolderItem --");
            Log.PushIndent();
            #endif
            try
            {
                int numCoders = ReadNum();
            #if DEBUG
                Log.WriteLine("NumCoders: " + numCoders);
            #endif
                folder.Coders = new List<CCoderInfo>(numCoders);
                int numInStreams = 0;
                int numOutStreams = 0;
                for (int i = 0; i < numCoders; i++)
                {
            #if DEBUG
                    Log.WriteLine("-- Coder --");
                    Log.PushIndent();
            #endif
                    try
                    {
                        CCoderInfo coder = new CCoderInfo();
                        folder.Coders.Add(coder);

                        byte mainByte = ReadByte();
                        int idSize = (mainByte & 0xF);
                        byte[] longID = new byte[idSize];
                        ReadBytes(longID, 0, idSize);
            #if DEBUG
                        Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longID[x].ToString("x2")).ToArray()));
            #endif
                        if (idSize > 8)
                            throw new NotSupportedException();
                        ulong id = 0;
                        for (int j = 0; j < idSize; j++)
                            id |= (ulong)longID[idSize - 1 - j] << (8 * j);
                        coder.MethodId = new CMethodId(id);

                        if ((mainByte & 0x10) != 0)
                        {
                            coder.NumInStreams = ReadNum();
                            coder.NumOutStreams = ReadNum();
            #if DEBUG
                            Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams + ")");
            #endif
                        }
                        else
                        {
            #if DEBUG
                            Log.WriteLine("Simple Stream (In: 1 - Out: 1)");
            #endif
                            coder.NumInStreams = 1;
                            coder.NumOutStreams = 1;
                        }

                        if ((mainByte & 0x20) != 0)
                        {
                            int propsSize = ReadNum();
                            coder.Props = new byte[propsSize];
                            ReadBytes(coder.Props, 0, propsSize);
            #if DEBUG
                            Log.WriteLine("Settings: " + String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
            #endif
                        }

                        if ((mainByte & 0x80) != 0)
                            throw new NotSupportedException();

                        numInStreams += coder.NumInStreams;
                        numOutStreams += coder.NumOutStreams;
                    }
                    finally
                    {
            #if DEBUG
                        Log.PopIndent();
            #endif
                    }
                }

                int numBindPairs = numOutStreams - 1;
                folder.BindPairs = new List<CBindPair>(numBindPairs);
            #if DEBUG
                Log.WriteLine("BindPairs: " + numBindPairs);
                Log.PushIndent();
            #endif
                for (int i = 0; i < numBindPairs; i++)
                {
                    CBindPair bp = new CBindPair();
                    bp.InIndex = ReadNum();
                    bp.OutIndex = ReadNum();
                    folder.BindPairs.Add(bp);
            #if DEBUG
                    Log.WriteLine("#" + i + " - In: " + bp.InIndex + " - Out: " + bp.OutIndex);
            #endif
                }
            #if DEBUG
                Log.PopIndent();
            #endif

                if (numInStreams < numBindPairs)
                    throw new NotSupportedException();

                int numPackStreams = numInStreams - numBindPairs;
                //folder.PackStreams.Reserve(numPackStreams);
                if (numPackStreams == 1)
                {
                    for (int i = 0; i < numInStreams; i++)
                    {
                        if (folder.FindBindPairForInStream(i) < 0)
                        {
            #if DEBUG
                            Log.WriteLine("Single PackStream: #" + i);
            #endif
                            folder.PackStreams.Add(i);
                            break;
                        }
                    }

                    if (folder.PackStreams.Count != 1)
                        throw new NotSupportedException();
                }
                else
                {
            #if DEBUG
                    Log.WriteLine("Multiple PackStreams ...");
                    Log.PushIndent();
            #endif
                    for (int i = 0; i < numPackStreams; i++)
                    {
                        var num = ReadNum();
            #if DEBUG
                        Log.WriteLine("#" + i + " - " + num);
            #endif
                        folder.PackStreams.Add(num);
                    }
            #if DEBUG
                    Log.PopIndent();
            #endif
                }
            }
            finally
            {
            #if DEBUG
                Log.PopIndent();
            #endif
            }
        }
Пример #4
0
 private void GetNextFolderItem(CFolder folder)
 {
     SharpCompress.Compressor.LZMA.Log.WriteLine("-- GetNextFolderItem --");
     SharpCompress.Compressor.LZMA.Log.PushIndent("  ");
     try
     {
         int num4;
         int capacity = this.ReadNum();
         SharpCompress.Compressor.LZMA.Log.WriteLine("NumCoders: " + capacity);
         folder.Coders = new List<CCoderInfo>(capacity);
         int num2 = 0;
         int num3 = 0;
         for (num4 = 0; num4 < capacity; num4++)
         {
             SharpCompress.Compressor.LZMA.Log.WriteLine("-- Coder --");
             SharpCompress.Compressor.LZMA.Log.PushIndent("  ");
             try
             {
                 CCoderInfo item = new CCoderInfo();
                 folder.Coders.Add(item);
                 byte num5 = this.ReadByte();
                 int length = num5 & 15;
                 byte[] longID = new byte[length];
                 this.ReadBytes(longID, 0, length);
                 SharpCompress.Compressor.LZMA.Log.WriteLine("MethodId: " + string.Join("", Enumerable.ToArray<string>(Enumerable.Select<int, string>(Enumerable.Range(0, length), delegate (int x) {
                     return longID[x].ToString("x2");
                 }))));
                 if (length > 8)
                 {
                     throw new NotSupportedException();
                 }
                 ulong id = 0L;
                 for (int i = 0; i < length; i++)
                 {
                     id |= (ulong)longID[(length - 1) - i] << (8 * i);
                 }
                 item.MethodId = new CMethodId(id);
                 if ((num5 & 0x10) != 0)
                 {
                     item.NumInStreams = this.ReadNum();
                     item.NumOutStreams = this.ReadNum();
                     SharpCompress.Compressor.LZMA.Log.WriteLine(string.Concat(new object[] { "Complex Stream (In: ", item.NumInStreams, " - Out: ", item.NumOutStreams, ")" }));
                 }
                 else
                 {
                     SharpCompress.Compressor.LZMA.Log.WriteLine("Simple Stream (In: 1 - Out: 1)");
                     item.NumInStreams = 1;
                     item.NumOutStreams = 1;
                 }
                 if ((num5 & 0x20) != 0)
                 {
                     int num9 = this.ReadNum();
                     item.Props = new byte[num9];
                     this.ReadBytes(item.Props, 0, num9);
                     SharpCompress.Compressor.LZMA.Log.WriteLine("Settings: " + string.Join("", Enumerable.ToArray<string>(Enumerable.Select<byte, string>(item.Props, delegate (byte bt) {
                         return bt.ToString("x2");
                     }))));
                 }
                 if ((num5 & 0x80) != 0)
                 {
                     throw new NotSupportedException();
                 }
                 num2 += item.NumInStreams;
                 num3 += item.NumOutStreams;
             }
             finally
             {
                 SharpCompress.Compressor.LZMA.Log.PopIndent();
             }
         }
         int num10 = num3 - 1;
         folder.BindPairs = new List<CBindPair>(num10);
         SharpCompress.Compressor.LZMA.Log.WriteLine("BindPairs: " + num10);
         SharpCompress.Compressor.LZMA.Log.PushIndent("  ");
         for (num4 = 0; num4 < num10; num4++)
         {
             CBindPair pair = new CBindPair();
             pair.InIndex = this.ReadNum();
             pair.OutIndex = this.ReadNum();
             folder.BindPairs.Add(pair);
             SharpCompress.Compressor.LZMA.Log.WriteLine(string.Concat(new object[] { "#", num4, " - In: ", pair.InIndex, " - Out: ", pair.OutIndex }));
         }
         SharpCompress.Compressor.LZMA.Log.PopIndent();
         if (num2 < num10)
         {
             throw new NotSupportedException();
         }
         int num11 = num2 - num10;
         if (num11 == 1)
         {
             for (num4 = 0; num4 < num2; num4++)
             {
                 if (folder.FindBindPairForInStream(num4) < 0)
                 {
                     SharpCompress.Compressor.LZMA.Log.WriteLine("Single PackStream: #" + num4);
                     folder.PackStreams.Add(num4);
                     break;
                 }
             }
             if (folder.PackStreams.Count != 1)
             {
                 throw new NotSupportedException();
             }
         }
         else
         {
             SharpCompress.Compressor.LZMA.Log.WriteLine("Multiple PackStreams ...");
             SharpCompress.Compressor.LZMA.Log.PushIndent("  ");
             for (num4 = 0; num4 < num11; num4++)
             {
                 int num12 = this.ReadNum();
                 SharpCompress.Compressor.LZMA.Log.WriteLine(string.Concat(new object[] { "#", num4, " - ", num12 }));
                 folder.PackStreams.Add(num12);
             }
             SharpCompress.Compressor.LZMA.Log.PopIndent();
         }
     }
     finally
     {
         SharpCompress.Compressor.LZMA.Log.PopIndent();
     }
 }