Beispiel #1
0
        static unsafe Compression()
        {
            int index1 = 0;

            Compression.m_Tree = new UnpackLeaf(index1);
            UnpackLeaf[] unpackLeafArray = Compression.m_Leaves;
            int          index2          = index1;
            int          num1            = 1;
            int          index3          = index2 + num1;
            UnpackLeaf   unpackLeaf1     = Compression.m_Tree;

            unpackLeafArray[index2] = unpackLeaf1;
            fixed(short *numPtr1 = Compression._sourceTable)
            {
                short *numPtr2 = numPtr1;

                for (short index4 = 0; (int)index4 <= 256; ++index4)
                {
                    UnpackLeaf unpackLeaf2 = Compression.m_Tree;
                    int        num2        = (int)*numPtr2++;
                    int        num3        = num2 & 15;
                    int        num4        = num2 >> 4;
                    while (--num3 >= 0)
                    {
                        switch (num4 & 1)
                        {
                        case 0:
                            if (unpackLeaf2.m_Left == null)
                            {
                                unpackLeaf2.m_Left             = new UnpackLeaf(index3);
                                Compression.m_Leaves[index3++] = unpackLeaf2.m_Left;
                            }
                            unpackLeaf2 = unpackLeaf2.m_Left;
                            break;

                        case 1:
                            if (unpackLeaf2.m_Right == null)
                            {
                                unpackLeaf2.m_Right            = new UnpackLeaf(index3);
                                Compression.m_Leaves[index3++] = unpackLeaf2.m_Right;
                            }
                            unpackLeaf2 = unpackLeaf2.m_Right;
                            break;
                        }
                        num4 >>= 1;
                    }
                    unpackLeaf2.m_Value = index4;
                }
            }

            Compression._sourceTable = (short[])null;
        }
Beispiel #2
0
        public override unsafe int Decrypt(byte[] input, int inputStart, int count, byte[] output, int outputStart)
        {
            fixed(byte *numPtr1 = output)
            {
                byte *numPtr2 = numPtr1 + outputStart;
                byte *numPtr3 = numPtr1 + output.Length;

                fixed(UnpackCacheEntry *unpackCacheEntryPtr = Compression.m_CacheEntries)
                fixed(byte *numPtr4 = Compression.m_OutputBuffer)
                fixed(byte *numPtr5 = input)
                {
                    UnpackLeaf unpackLeaf = this.m_Leaf;

                    UnpackLeaf[] unpackLeafArray = Compression.m_Leaves;
                    byte *       numPtr6         = numPtr5;
                    byte *       numPtr7         = numPtr6 + count;

                    while (numPtr6 < numPtr7)
                    {
                        UnpackCacheEntry unpackCacheEntry = unpackCacheEntryPtr[unpackLeaf.m_Cache[(int)*numPtr6++]];
                        byte *           numPtr8          = numPtr4 + unpackCacheEntry.m_ByteIndex;
                        byte *           numPtr9          = numPtr2 + unpackCacheEntry.m_ByteCount;
                        if (numPtr9 > numPtr3)
                        {
                            throw new InternalBufferOverflowException("Network::Decompress(): Buffer overflow.");
                        }
                        while (numPtr2 < numPtr9)
                        {
                            *numPtr2++ = *numPtr8++;
                        }
                        unpackLeaf = unpackLeafArray[unpackCacheEntry.m_NextIndex];
                    }
                    this.m_Leaf = unpackLeaf;
                }
                return((int)(numPtr2 - outputStart - numPtr1));
            }
        }
Beispiel #3
0
        public static unsafe void LoadUnpackCache()
        {
            Compression.m_OutputBuffer = new byte[100725];
            Compression.m_CacheEntries = new UnpackCacheEntry[65536];
            fixed(UnpackCacheEntry *unpackCacheEntryPtr1 = Compression.m_CacheEntries)
            {
                UnpackCacheEntry *unpackCacheEntryPtr2 = unpackCacheEntryPtr1;

                fixed(byte *numPtr1 = Compression.m_OutputBuffer)
                {
                    Stack <UnpackLeaf> unpackLeafStack = new Stack <UnpackLeaf>();

                    unpackLeafStack.Push(Compression.m_Tree);
                    while (unpackLeafStack.Count > 0)
                    {
                        UnpackLeaf unpackLeaf1 = unpackLeafStack.Pop();
                        if (unpackLeaf1.m_Left != null)
                        {
                            unpackLeafStack.Push(unpackLeaf1.m_Left);
                        }
                        if (unpackLeaf1.m_Right != null)
                        {
                            unpackLeafStack.Push(unpackLeaf1.m_Right);
                        }
                        int[] numArray = new int[256];
label_21:
                        for (int index = 0; index < 256; ++index)
                        {
                            byte *     numPtr2     = numPtr1 + Compression.m_OutputIndex;
                            UnpackLeaf unpackLeaf2 = unpackLeaf1;
                            int        num1        = 0;
                            int        num2        = 8;
                            while (--num2 >= 0)
                            {
                                switch (index >> num2 & 1)
                                {
                                case 0:
                                    unpackLeaf2 = unpackLeaf2.m_Left;
                                    break;

                                case 1:
                                    unpackLeaf2 = unpackLeaf2.m_Right;
                                    break;
                                }
                                if (unpackLeaf2 != null)
                                {
                                    if ((int)unpackLeaf2.m_Value != -1)
                                    {
                                        switch ((int)unpackLeaf2.m_Value >> 8)
                                        {
                                        case 0:
                                            numPtr2[num1++] = (byte)unpackLeaf2.m_Value;
                                            break;

                                        case 1:
                                            num2 = 0;
                                            break;
                                        }
                                        unpackLeaf2 = Compression.m_Tree;
                                    }
                                }
                                else
                                {
                                    goto label_21;
                                }
                            }
                            unpackCacheEntryPtr2->m_NextIndex = (int)unpackLeaf2.m_Index;
                            unpackCacheEntryPtr2->m_ByteIndex = Compression.m_OutputIndex;
                            unpackCacheEntryPtr2->m_ByteCount = num1;
                            numArray[index] = (int)(unpackCacheEntryPtr2 - unpackCacheEntryPtr1);
                            ++unpackCacheEntryPtr2;
                            Compression.m_OutputIndex += num1;
                        }
                        unpackLeaf1.m_Cache = numArray;
                    }
                }
            }
        }
Beispiel #4
0
 protected override void InitKeys(uint seed)
 {
     this.m_Leaf = Compression.m_Tree;
 }