コード例 #1
0
        // Token: 0x060005DD RID: 1501 RVA: 0x0002102C File Offset: 0x0001F22C
        private void OutputChunk(byte[] bytes, ref int index, ref int size)
        {
            int num = Math.Min(this.bytesNeeded, this.repeatCount);

            num = Math.Min(size, num);
            if (bytes != null)
            {
                for (int i = 0; i < num; i++)
                {
                    bytes[index++] = this.decodedByte;
                }
                size -= num;
            }
            this.runningCRC   = BinHexUtils.CalculateCrc(this.decodedByte, num, this.runningCRC);
            this.bytesNeeded -= num;
            this.repeatCount -= num;
        }
コード例 #2
0
        private void CompressAndEncode(byte[] input, ref int inputOffset, ref int inputSize, ref int inputTotal, ref int inputMax, bool inputIsCRC, byte[] output, ref int outputOffset, ref int outputSize)
        {
            byte[] bytes = null;
            int    index = 0;
            int    num   = 0;

            if (inputIsCRC)
            {
                bytes = input;
                index = inputOffset;
                num   = inputMax;
            }
            int num5;

            for (;;)
            {
                int num2 = (int)input[inputOffset++];
                inputSize--;
                inputTotal--;
                inputMax--;
                if (num2 != this.previousByte || this.repeatCount >= 254)
                {
                    goto IL_74;
                }
                this.repeatCount++;
                if (this.state >= BinHexUtils.State.ResourceCRC && inputMax == 0)
                {
                    num2 = 257;
                    goto IL_74;
                }
IL_3D5:
                if (inputMax == 0)
                {
                    goto IL_3DD;
                }
                continue;
IL_74:
                byte[] array = new byte[5];
                int    num3  = 0;
                if (this.repeatCount >= 2)
                {
                    this.repeatCount++;
                    array[num3++]    = 144;
                    array[num3++]    = (byte)this.repeatCount;
                    this.repeatCount = 0;
                }
                else if (this.repeatCount != 0)
                {
                    array[num3++] = (byte)this.previousByte;
                    if (this.previousByte == 144)
                    {
                        array[num3++] = 0;
                    }
                    this.repeatCount = 0;
                }
                if (num2 <= 255)
                {
                    array[num3++] = (byte)num2;
                    if (num2 == 144)
                    {
                        array[num3++] = 0;
                    }
                }
                bool flag = false;
                if (this.state == BinHexUtils.State.ResourceCRC && inputMax == 0 && (this.accumCount + num3) % 3 != 0)
                {
                    array[num3++] = 0;
                    flag          = true;
                }
                this.previousByte = num2;
                int num4 = 0;
                while (num3 != 0)
                {
                    this.accumValue <<= 8;
                    this.accumValue  |= (int)array[num4];
                    this.accumCount++;
                    switch (this.accumCount)
                    {
                    case 1:
                        this.encoded[this.encodedSize++] = BinHexEncoder.Table[this.accumValue >> 2 & 63];
                        this.lineOffset++;
                        break;

                    case 2:
                        this.encoded[this.encodedSize++] = BinHexEncoder.Table[this.accumValue >> 4 & 63];
                        this.lineOffset++;
                        break;

                    case 3:
                        this.encoded[this.encodedSize++] = BinHexEncoder.Table[this.accumValue >> 6 & 63];
                        this.lineOffset++;
                        if (!flag || 1 != num3)
                        {
                            if (this.lineOffset == 64)
                            {
                                this.encoded[this.encodedSize++] = 13;
                                this.encoded[this.encodedSize++] = 10;
                                this.lineOffset = 0;
                                this.lines++;
                            }
                            this.encoded[this.encodedSize++] = BinHexEncoder.Table[this.accumValue & 63];
                            this.lineOffset++;
                        }
                        this.accumCount = 0;
                        break;
                    }
                    if (this.lineOffset == 64)
                    {
                        this.encoded[this.encodedSize++] = 13;
                        this.encoded[this.encodedSize++] = 10;
                        this.lineOffset = 0;
                        this.lines++;
                    }
                    num3--;
                    num4++;
                }
                num5 = Math.Min(this.encodedSize, outputSize);
                if (output != null)
                {
                    Buffer.BlockCopy(this.encoded, this.encodedIndex, output, outputOffset, num5);
                    outputSize -= num5;
                }
                outputOffset     += num5;
                this.encodedSize -= num5;
                if (this.encodedSize != 0)
                {
                    break;
                }
                this.encodedIndex = 0;
                goto IL_3D5;
            }
            this.encodedIndex += num5;
IL_3DD:
            switch (this.state)
            {
            case BinHexUtils.State.Header:
                if (this.decodedSize != 0)
                {
                    return;
                }
                this.checksum = 0;
                if (0L != this.header.DataForkLength)
                {
                    this.decodedSize = (int)this.header.DataForkLength;
                    this.state       = BinHexUtils.State.Data;
                    return;
                }
                this.macbinHeaderSize = 0;
                this.checksum         = BinHexUtils.CalculateCrc(this.checksum);
                this.decodedSize      = BinHexUtils.MarshalUInt16(this.decoded, 0, this.checksum);
                this.decodedIndex     = 0;
                this.state            = BinHexUtils.State.DataCRC;
                return;

            case BinHexUtils.State.Data:
                num          -= inputMax;
                this.checksum = BinHexUtils.CalculateCrc(bytes, index, num, this.checksum);
                if (this.decodedSize == 0)
                {
                    if (0L < this.header.ResourceForkLength)
                    {
                        this.macbinHeaderSize = ((this.header.DataForkLength % 128L != 0L) ? ((int)(128L - this.header.DataForkLength % 128L)) : 0);
                    }
                    else
                    {
                        this.macbinHeaderSize = 0;
                    }
                    this.checksum     = BinHexUtils.CalculateCrc(this.checksum);
                    this.decodedSize  = BinHexUtils.MarshalUInt16(this.decoded, 0, this.checksum);
                    this.decodedIndex = 0;
                    this.state        = BinHexUtils.State.DataCRC;
                    return;
                }
                return;

            case BinHexUtils.State.DataCRC:
                if (this.decodedSize != 0)
                {
                    return;
                }
                this.checksum = 0;
                if (0L != this.header.ResourceForkLength)
                {
                    this.decodedSize = (int)this.header.ResourceForkLength;
                    this.state       = BinHexUtils.State.Resource;
                    return;
                }
                this.macbinHeaderSize = 0;
                this.checksum         = BinHexUtils.CalculateCrc(this.checksum);
                this.decodedSize      = BinHexUtils.MarshalUInt16(this.decoded, 0, this.checksum);
                this.decodedIndex     = 0;
                this.state            = BinHexUtils.State.ResourceCRC;
                return;

            case BinHexUtils.State.Resource:
                num          -= inputMax;
                this.checksum = BinHexUtils.CalculateCrc(bytes, index, num, this.checksum);
                if (this.decodedSize == 0)
                {
                    this.macbinHeaderSize = ((this.header.ResourceForkLength % 128L != 0L) ? ((int)(128L - this.header.ResourceForkLength % 128L)) : 0);
                    this.checksum         = BinHexUtils.CalculateCrc(this.checksum);
                    this.decodedSize      = BinHexUtils.MarshalUInt16(this.decoded, 0, this.checksum);
                    this.decodedIndex     = 0;
                    this.state            = BinHexUtils.State.ResourceCRC;
                    return;
                }
                return;

            case BinHexUtils.State.ResourceCRC:
                if (this.decodedSize == 0)
                {
                    Buffer.BlockCopy(BinHexEncoder.BinHexSuffix, 0, this.decoded, 0, BinHexEncoder.BinHexSuffix.Length);
                    this.decodedIndex = 0;
                    this.decodedSize  = BinHexEncoder.BinHexSuffix.Length;
                    this.state        = BinHexUtils.State.Ending;
                    return;
                }
                return;
            }
            throw new Exception(EncodersStrings.BinHexEncoderInternalError);
        }
コード例 #3
0
 // Token: 0x060005FD RID: 1533 RVA: 0x00022904 File Offset: 0x00020B04
 internal static ushort CalculateCrc(ushort seed)
 {
     byte[] array  = new byte[2];
     byte[] array2 = array;
     return(BinHexUtils.CalculateCrc(array2, 0, array2.Length, seed));
 }
コード例 #4
0
        // Token: 0x060005DF RID: 1503 RVA: 0x00021250 File Offset: 0x0001F450
        private void TransitionState()
        {
            switch (this.state)
            {
            case BinHexUtils.State.HdrFileSize:
                if (this.scratch[0] > 63)
                {
                    throw new ByteEncoderException(EncodersStrings.BinHexDecoderFileNameTooLong);
                }
                this.state       = BinHexUtils.State.Header;
                this.bytesNeeded = (int)(this.scratch[0] + 21);
                return;

            case BinHexUtils.State.Header:
                this.header = new BinHexHeader(this.scratch);
                if (!this.dataForkOnly)
                {
                    byte[] bytes = this.header.GetBytes();
                    Buffer.BlockCopy(bytes, 0, this.extra, 0, bytes.Length);
                    this.extraIndex = 0;
                    this.extraSize  = bytes.Length;
                }
                if (0L != this.header.DataForkLength)
                {
                    this.state       = BinHexUtils.State.Data;
                    this.bytesNeeded = (int)this.header.DataForkLength;
                    this.runningCRC  = 0;
                    return;
                }
                this.checksum     = this.runningCRC;
                this.checksum     = BinHexUtils.CalculateCrc(this.checksum);
                this.state        = BinHexUtils.State.DataCRC;
                this.bytesNeeded  = 2;
                this.scratchSize  = this.scratch.Length;
                this.scratchIndex = 0;
                return;

            case BinHexUtils.State.Data:
                this.checksum     = this.runningCRC;
                this.checksum     = BinHexUtils.CalculateCrc(this.checksum);
                this.state        = BinHexUtils.State.DataCRC;
                this.bytesNeeded  = 2;
                this.scratchSize  = this.scratch.Length;
                this.scratchIndex = 0;
                return;

            case BinHexUtils.State.DataCRC:
            {
                if ((this.checksum & 65280) >> 8 != (int)this.scratch[0] || (this.checksum & 255) != (ushort)this.scratch[1])
                {
                    throw new ByteEncoderException(EncodersStrings.BinHexDecoderBadCrc);
                }
                if (this.dataForkOnly)
                {
                    this.state       = BinHexUtils.State.Ending;
                    this.repeatCount = 0;
                    this.encodedSize = 0;
                    this.lineReady   = false;
                    return;
                }
                int num = (this.header.DataForkLength % 128L != 0L) ? ((int)(128L - this.header.DataForkLength % 128L)) : 0;
                if (num != 0)
                {
                    Array.Clear(this.extra, 0, num);
                    this.extraSize = num;
                }
                if (this.header.ResourceForkLength > 0L)
                {
                    this.state       = BinHexUtils.State.Resource;
                    this.bytesNeeded = (int)this.header.ResourceForkLength;
                    this.runningCRC  = 0;
                    return;
                }
                this.checksum     = 0;
                this.checksum     = BinHexUtils.CalculateCrc(this.checksum);
                this.state        = BinHexUtils.State.ResourceCRC;
                this.bytesNeeded  = 2;
                this.scratchSize  = this.scratch.Length;
                this.scratchIndex = 0;
                return;
            }

            case BinHexUtils.State.Resource:
                this.checksum     = this.runningCRC;
                this.checksum     = BinHexUtils.CalculateCrc(this.checksum);
                this.state        = BinHexUtils.State.ResourceCRC;
                this.bytesNeeded  = 2;
                this.scratchSize  = this.scratch.Length;
                this.scratchIndex = 0;
                return;

            case BinHexUtils.State.ResourceCRC:
            {
                if ((this.checksum & 65280) >> 8 != (int)this.scratch[0] || (this.checksum & 255) != (ushort)this.scratch[1])
                {
                    throw new ByteEncoderException(EncodersStrings.BinHexDecoderBadResourceForkCrc);
                }
                int num = (this.header.ResourceForkLength % 128L != 0L) ? ((int)(128L - this.header.ResourceForkLength % 128L)) : 0;
                if (num != 0)
                {
                    Array.Clear(this.extra, 0, num);
                    this.extraSize = num;
                }
                this.state       = BinHexUtils.State.Ending;
                this.repeatCount = 0;
                this.encodedSize = 0;
                this.lineReady   = false;
                return;
            }
            }
            throw new Exception(EncodersStrings.BinHexDecoderInternalError);
        }