示例#1
0
        // Token: 0x06000641 RID: 1601 RVA: 0x0002342C File Offset: 0x0002162C
        internal byte[] GetBytes()
        {
            int num = 0;

            byte[] array = new byte[128];
            array[num++] = 0;
            array[num++] = (byte)this.fileNameLength;
            byte[] src = this.FileNameAsByteArray();
            Buffer.BlockCopy(src, 0, array, num, this.fileNameLength);
            num            = 65;
            num           += BinHexUtils.MarshalInt32(array, num, (long)this.fileType);
            num           += BinHexUtils.MarshalInt32(array, num, (long)this.fileCreator);
            array[num++]   = (byte)((65280 & this.finderFlags) >> 8);
            array[num++]   = 0;
            num           += BinHexUtils.MarshalUInt16(array, num, (ushort)this.iconXOffset);
            num           += BinHexUtils.MarshalUInt16(array, num, (ushort)this.iconYOffset);
            num           += BinHexUtils.MarshalUInt16(array, num, 0);
            array[num++]   = (this.fileProtected ? 1 : 0);
            array[num++]   = 0;
            num           += BinHexUtils.MarshalInt32(array, num, this.dataForkLength);
            num           += BinHexUtils.MarshalInt32(array, num, this.resourceForkLength);
            num           += BinHexUtils.MarshalInt32(array, num, 0L);
            num           += BinHexUtils.MarshalInt32(array, num, 0L);
            num           += BinHexUtils.MarshalUInt16(array, num, (ushort)this.commentLength);
            array[num++]   = (byte)(255 & this.finderFlags);
            num           += 18;
            num           += BinHexUtils.MarshalUInt16(array, num, (ushort)this.secondaryHeaderLength);
            array[num++]   = (byte)this.version;
            array[num++]   = (byte)this.minimumVersion;
            this.headerCRC = BinHexUtils.CalculateHeaderCrc(array, 124);
            num           += BinHexUtils.MarshalUInt16(array, num, this.headerCRC);
            array[num++]   = 0;
            array[num++]   = 0;
            return(array);
        }
示例#2
0
 // Token: 0x0600061B RID: 1563 RVA: 0x0002312C File Offset: 0x0002132C
 public MacBinaryHeader(byte[] bytes)
 {
     if (bytes == null)
     {
         throw new ArgumentNullException("bytes");
     }
     if (bytes.Length != 128)
     {
         throw new ArgumentException(EncodersStrings.MacBinHeaderMustBe128Long, "bytes");
     }
     if (bytes[0] != 0 || bytes[74] != 0 || bytes[82] != 0)
     {
         throw new ByteEncoderException(EncodersStrings.MacBinInvalidData);
     }
     if (bytes[1] > 63)
     {
         throw new ByteEncoderException(EncodersStrings.MacBinInvalidData);
     }
     this.fileNameLength     = (int)bytes[1];
     this.fileName           = CTSGlobals.AsciiEncoding.GetString(bytes, 2, this.fileNameLength);
     this.fileType           = BinHexUtils.UnmarshalInt32(bytes, 65);
     this.fileCreator        = BinHexUtils.UnmarshalInt32(bytes, 69);
     this.finderFlags        = (int)bytes[73];
     this.iconXOffset        = (int)BinHexUtils.UnmarshalUInt16(bytes, 75);
     this.iconYOffset        = (int)BinHexUtils.UnmarshalUInt16(bytes, 77);
     this.fileProtected      = (1 == bytes[81]);
     this.dataForkLength     = (long)BinHexUtils.UnmarshalInt32(bytes, 83);
     this.resourceForkLength = (long)BinHexUtils.UnmarshalInt32(bytes, 87);
     this.version            = (int)bytes[122];
     this.minimumVersion     = (int)bytes[123];
 }
示例#3
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;
        }
示例#4
0
        public byte[] GetBytes()
        {
            int num  = 0;
            int num2 = 1 + this.FileNameLength + 1 + 4 + 4 + 2 + 4 + 4 + 2;

            byte[] array = new byte[num2];
            array[num++] = (byte)this.fileNameLength;
            Buffer.BlockCopy(this.fileName, 0, array, num, this.fileNameLength);
            num           += this.FileNameLength;
            array[num++]   = (byte)this.version;
            num           += BinHexUtils.MarshalInt32(array, num, (long)this.fileType);
            num           += BinHexUtils.MarshalInt32(array, num, (long)this.fileCreator);
            num           += BinHexUtils.MarshalUInt16(array, num, (ushort)this.finderFlags);
            num           += BinHexUtils.MarshalInt32(array, num, this.dataForkLength);
            num           += BinHexUtils.MarshalInt32(array, num, this.resourceForkLength);
            this.headerCRC = BinHexUtils.CalculateHeaderCrc(array, num);
            num           += BinHexUtils.MarshalUInt16(array, num, this.headerCRC);
            return(array);
        }
示例#5
0
        public BinHexHeader(byte[] header)
        {
            if (header.Length < 23)
            {
                throw new ArgumentException(EncodersStrings.BinHexHeaderTooSmall, "header");
            }
            int num = (int)header[0];

            if (header.Length - 22 < num)
            {
                throw new ByteEncoderException(EncodersStrings.BinHexHeaderIncomplete);
            }
            if (63 < num || 1 > num)
            {
                throw new ByteEncoderException(EncodersStrings.BinHexHeaderInvalidNameLength);
            }
            int    num2 = 2 + num;
            ushort num3 = BinHexUtils.CalculateHeaderCrc(header, num2 + 18);
            ushort num4 = BinHexUtils.UnmarshalUInt16(header, num2 + 18);

            if (num3 != num4)
            {
                throw new ByteEncoderException(EncodersStrings.BinHexHeaderInvalidCrc);
            }
            if (header[1 + num] != 0)
            {
                throw new ByteEncoderException(EncodersStrings.BinHexHeaderUnsupportedVersion);
            }
            this.fileNameLength = num;
            this.fileName       = new byte[num];
            Buffer.BlockCopy(header, 1, this.fileName, 0, this.fileNameLength);
            this.version            = (int)header[this.fileNameLength + 1];
            this.fileType           = BinHexUtils.UnmarshalInt32(header, num2);
            this.fileCreator        = BinHexUtils.UnmarshalInt32(header, num2 + 4);
            this.finderFlags        = (int)BinHexUtils.UnmarshalUInt16(header, num2 + 8);
            this.dataForkLength     = (long)BinHexUtils.UnmarshalInt32(header, num2 + 10);
            this.resourceForkLength = (long)BinHexUtils.UnmarshalInt32(header, num2 + 14);
            this.headerCRC          = num4;
        }
示例#6
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);
        }
示例#7
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));
 }
示例#8
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);
        }