Example #1
0
 public BinHexHeader(MacBinaryHeader header)
 {
     if (63 < header.FileNameLength || 1 > header.FileNameLength)
     {
         throw new ByteEncoderException(EncodersStrings.BinHexHeaderBadFileNameLength);
     }
     this.FileName           = header.FileName;
     this.version            = 0;
     this.fileType           = header.FileType;
     this.fileCreator        = header.FileCreator;
     this.finderFlags        = 0;
     this.dataForkLength     = header.DataForkLength;
     this.resourceForkLength = header.ResourceForkLength;
     this.GetBytes();
 }
Example #2
0
        public sealed override void Convert(byte[] input, int inputIndex, int inputSize, byte[] output, int outputIndex, int outputSize, bool flush, out int inputUsed, out int outputUsed, out bool completed)
        {
            if (inputSize != 0)
            {
                if (input == null)
                {
                    throw new ArgumentNullException("input");
                }
                if (inputIndex < 0 || inputIndex >= input.Length)
                {
                    throw new ArgumentOutOfRangeException("inputIndex");
                }
                if (inputSize < 0 || inputSize > input.Length - inputIndex)
                {
                    throw new ArgumentOutOfRangeException("inputSize");
                }
            }
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (outputIndex < 0 || outputIndex >= output.Length)
            {
                throw new ArgumentOutOfRangeException("outputIndex");
            }
            if (outputSize < 1 || outputSize > output.Length - outputIndex)
            {
                throw new ArgumentOutOfRangeException("outputSize");
            }
            inputUsed  = inputIndex;
            outputUsed = outputIndex;
            int num = 0;

            if (this.encodedSize != 0)
            {
                int num2 = Math.Min(this.encodedSize, outputSize);
                Buffer.BlockCopy(this.encoded, this.encodedIndex, output, outputIndex, num2);
                outputSize       -= num2;
                outputIndex      += num2;
                this.encodedSize -= num2;
                if (this.encodedSize != 0)
                {
                    this.encodedIndex += num2;
                    outputUsed         = outputIndex - outputUsed;
                    inputUsed          = 0;
                    completed          = false;
                    return;
                }
                this.encodedIndex = 0;
            }
            bool flag = true;

            while (flag)
            {
                int num3 = 0;
                flag = false;
                switch (this.state)
                {
                case BinHexUtils.State.Starting:
                    Buffer.BlockCopy(BinHexEncoder.BinHexPrefix, 0, this.decoded, 0, BinHexEncoder.BinHexPrefix.Length);
                    this.decodedIndex = 0;
                    this.decodedSize  = BinHexEncoder.BinHexPrefix.Length;
                    this.state        = BinHexUtils.State.Prefix;
                    goto IL_182;

                case BinHexUtils.State.Prefix:
                    goto IL_182;

                case BinHexUtils.State.Header:
                    goto IL_284;

                case BinHexUtils.State.Data:
                    num3 = Math.Min(this.decodedSize, inputSize);
                    if (num3 != 0)
                    {
                        flag = true;
                        this.CompressAndEncode(input, ref inputIndex, ref inputSize, ref this.decodedSize, ref num3, true, output, ref outputIndex, ref outputSize);
                    }
                    break;

                case BinHexUtils.State.DataCRC:
                    if (this.macbinHeaderSize != 0)
                    {
                        BinHexEncoder.IgnoreChunkFromInput(ref this.macbinHeaderSize, ref inputIndex, ref inputSize);
                        if (this.macbinHeaderSize != 0)
                        {
                            break;
                        }
                    }
                    num3 = this.decodedSize;
                    if (num3 != 0)
                    {
                        flag = true;
                        this.CompressAndEncode(this.decoded, ref this.decodedIndex, ref this.decodedSize, ref num, ref num3, false, output, ref outputIndex, ref outputSize);
                    }
                    break;

                case BinHexUtils.State.Resource:
                    num3 = Math.Min(this.decodedSize, inputSize);
                    if (num3 != 0)
                    {
                        flag = true;
                        this.CompressAndEncode(input, ref inputIndex, ref inputSize, ref this.decodedSize, ref num3, true, output, ref outputIndex, ref outputSize);
                    }
                    break;

                case BinHexUtils.State.ResourceCRC:
                    if (this.macbinHeaderSize != 0)
                    {
                        BinHexEncoder.IgnoreChunkFromInput(ref this.macbinHeaderSize, ref inputIndex, ref inputSize);
                        if (this.macbinHeaderSize != 0)
                        {
                            break;
                        }
                    }
                    num3 = this.decodedSize;
                    if (num3 != 0)
                    {
                        flag = true;
                        this.CompressAndEncode(this.decoded, ref this.decodedIndex, ref this.decodedSize, ref num, ref num3, false, output, ref outputIndex, ref outputSize);
                    }
                    break;

                case BinHexUtils.State.Ending:
                {
                    int num4 = Math.Min(this.decodedSize, outputSize);
                    Buffer.BlockCopy(this.decoded, this.decodedIndex, output, outputIndex, num4);
                    outputSize       -= num4;
                    outputIndex      += num4;
                    this.decodedSize -= num4;
                    if (this.decodedSize == 0)
                    {
                        this.decodedIndex = 0;
                        this.state        = BinHexUtils.State.Ended;
                        goto IL_4F5;
                    }
                    this.decodedIndex += num4;
                    break;
                }

                case BinHexUtils.State.Ended:
                    goto IL_4F5;
                }
IL_50B:
                if (this.encodedSize == 0)
                {
                    continue;
                }
                break;
IL_182:
                int num5 = Math.Min(this.decodedSize, outputSize);
                Buffer.BlockCopy(this.decoded, this.decodedIndex, output, outputIndex, num5);
                outputSize       -= num5;
                outputIndex      += num5;
                this.decodedSize -= num5;
                if (this.decodedSize != 0)
                {
                    this.decodedIndex += num5;
                    goto IL_50B;
                }
                this.decodedIndex = 0;
                this.previousByte = 256;
                this.repeatCount  = 0;
                this.accumCount   = 0;
                this.lineOffset   = 1;
                this.lines        = 0;
                this.checksum     = 0;
                if (this.header != null)
                {
                    byte[] bytes = this.header.GetBytes();
                    Buffer.BlockCopy(bytes, 0, this.decoded, 0, bytes.Length);
                    this.decodedSize      = bytes.Length;
                    this.decodedIndex     = 0;
                    this.macbinHeaderSize = 0;
                }
                else
                {
                    this.macbinHeader       = new byte[128];
                    this.macbinHeaderOffset = 0;
                    this.macbinHeaderSize   = this.macbinHeader.Length;
                }
                this.state = BinHexUtils.State.Header;
IL_284:
                if (this.macbinHeaderSize != 0)
                {
                    int num6 = Math.Min(this.macbinHeaderSize, inputSize);
                    Buffer.BlockCopy(input, inputIndex, this.macbinHeader, this.macbinHeaderOffset, num6);
                    this.macbinHeaderOffset += num6;
                    this.macbinHeaderSize   -= num6;
                    inputIndex += num6;
                    inputSize  -= num6;
                    if (this.macbinHeaderSize != 0)
                    {
                        goto IL_50B;
                    }
                    MacBinaryHeader macBinaryHeader = new MacBinaryHeader(this.macbinHeader);
                    this.macbinHeader = null;
                    this.header       = new BinHexHeader(macBinaryHeader);
                    byte[] bytes2 = this.header.GetBytes();
                    Buffer.BlockCopy(bytes2, 0, this.decoded, 0, bytes2.Length);
                    this.decodedSize  = bytes2.Length;
                    this.decodedIndex = 0;
                }
                num3 = this.decodedSize;
                if (num3 != 0)
                {
                    flag = true;
                    this.CompressAndEncode(this.decoded, ref this.decodedIndex, ref this.decodedSize, ref num, ref num3, false, output, ref outputIndex, ref outputSize);
                    goto IL_50B;
                }
                goto IL_50B;
IL_4F5:
                this.macbinHeaderSize = inputSize;
                BinHexEncoder.IgnoreChunkFromInput(ref this.macbinHeaderSize, ref inputIndex, ref inputSize);
                goto IL_50B;
            }
            if (flush && inputSize == 0 && this.state != BinHexUtils.State.Ended && outputSize != 0)
            {
                throw new ByteEncoderException(EncodersStrings.BinHexEncoderDataCorruptCannotFinishEncoding);
            }
            outputUsed = outputIndex - outputUsed;
            inputUsed  = inputIndex - inputUsed;
            completed  = (inputSize == 0 && (!flush || this.state == BinHexUtils.State.Ended));
            if (flush && completed)
            {
                this.state = BinHexUtils.State.Starting;
            }
        }
Example #3
0
 public BinHexEncoder(MacBinaryHeader header)
 {
     this.MacBinaryHeader = header;
 }