Example #1
0
 public RangeDecoder(ReaderNode stream)
 {
     mStream = stream;
     mBuffer = new byte[1];
     Range = 0xFFFFFFFF;
     for (int i = 0; i < 5; i++)
         Code = (Code << 8) | ReadByte();
 }
Example #2
0
        public override void SetInputStream(int index, ReaderNode stream, long length)
        {
            if (index != 0)
                throw new ArgumentOutOfRangeException(nameof(index));

            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            mInput = stream;
        }
Example #3
0
 public RangeDecoder(ReaderNode stream)
 {
     mStream = stream;
     mBuffer = new byte[1];
     Range   = 0xFFFFFFFF;
     for (int i = 0; i < 5; i++)
     {
         Code = (Code << 8) | ReadByte();
     }
 }
Example #4
0
        public override void SetInputStream(int index, ReaderNode stream, long length)
        {
            if (index != 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            mInput = stream;
        }
Example #5
0
            public void SetInput(ReaderNode stream, long length)
            {
                if (stream == null)
                {
                    throw new ArgumentNullException(nameof(stream));
                }

                if (mInput != null)
                {
                    throw new InvalidOperationException();
                }

                mInput       = stream;
                mInputLength = length;
            }
Example #6
0
        public override void SetInputStream(int index, ReaderNode stream, long length)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            switch (index)
            {
            case 0: mMainStream = stream; break;

            case 1: mCallStream = stream; break;

            case 2: mJumpStream = stream; break;

            case 3: mRangeDecoder = new RangeDecoder(stream); break;

            default: throw new ArgumentOutOfRangeException(nameof(index));
            }
        }
Example #7
0
        private static void SelectStream(
            ArchiveMetadata archiveMetadata,
            ArchiveDecoderSection sectionMetadata,
            DecoderInputMetadata selector,
            ReaderNode[] streams,
            DecoderNode[] decoders,
            out ReaderNode result,
            out long length)
        {
            var decoderIndex = selector.DecoderIndex;

            if (decoderIndex.HasValue)
            {
                length = sectionMetadata.Decoders[decoderIndex.Value].OutputStreams[selector.StreamIndex].Length;
                result = decoders[decoderIndex.Value].GetOutputStream(selector.StreamIndex);
            }
            else
            {
                length = archiveMetadata.FileSections[selector.StreamIndex].Length;
                result = streams[selector.StreamIndex];
            }
        }
Example #8
0
        public override void SetInputStream(int index, ReaderNode stream, long length)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            switch (index)
            {
                case 0: mMainStream = stream; break;
                case 1: mCallStream = stream; break;
                case 2: mJumpStream = stream; break;
                case 3: mRangeDecoder = new RangeDecoder(stream); break;
                default: throw new ArgumentOutOfRangeException(nameof(index));
            }
        }
Example #9
0
 public LzmaArchiveDecoder(ImmutableArray<byte> settings, long length)
 {
     mDecoder = new LZMA.Decoder(LZMA.DecoderSettings.CreateFrom(settings));
     mOutput = new OutputStream(this);
     mOutputLength = length;
 }
Example #10
0
 public abstract void SetInputStream(int index, ReaderNode stream, long length);
Example #11
0
        public ArchiveSectionDecoder(Stream stream, ArchiveMetadata metadata, int index, PasswordStorage password)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            if (!stream.CanRead)
            {
                throw new ArgumentException("Stream must be readable.", nameof(stream));
            }

            if (!stream.CanSeek)
            {
                throw new ArgumentException("Stream must be seekable.", nameof(stream));
            }

            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            if (index < 0 || index >= metadata.DecoderSections.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }

            var inputCoordinator = new StreamCoordinator(stream);
            var inputStreams     = new ReaderNode[metadata.FileSections.Length];

            for (int i = 0; i < inputStreams.Length; i++)
            {
                inputStreams[i] = new CoordinatedStream(inputCoordinator, metadata.FileSections[i].Offset, metadata.FileSections[i].Length);
            }

            var decoderSection     = metadata.DecoderSections[index];
            var decoderDefinitions = decoderSection.Decoders;
            var decoders           = new DecoderNode[decoderDefinitions.Length];

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoderDefinition = decoderDefinitions[i];
                decoders[i] = decoderDefinition.DecoderType.CreateDecoder(decoderDefinition.Settings, decoderDefinition.OutputStreams, password);
            }

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoder                 = decoders[i];
                var decoderDefinition       = decoderDefinitions[i];
                var decoderInputDefinitions = decoderDefinition.InputStreams;

                for (int j = 0; j < decoderInputDefinitions.Length; j++)
                {
                    ReaderNode inputStream;
                    long       inputLength;
                    SelectStream(metadata, decoderSection, decoderInputDefinitions[j], inputStreams, decoders, out inputStream, out inputLength);
                    decoder.SetInputStream(j, inputStream, inputLength);
                }
            }

            ReaderNode outputStream;
            long       outputLength;

            SelectStream(metadata, decoderSection, decoderSection.DecodedStream, inputStreams, decoders, out outputStream, out outputLength);

            mCoordinator  = inputCoordinator;
            mInputStreams = inputStreams;
            mDecoders     = decoders;
            mOutputStream = outputStream;
        }
 private static void SelectStream(
     ArchiveMetadata archiveMetadata,
     ArchiveDecoderSection sectionMetadata,
     DecoderInputMetadata selector,
     ReaderNode[] streams,
     DecoderNode[] decoders,
     out ReaderNode result,
     out long length)
 {
     var decoderIndex = selector.DecoderIndex;
     if (decoderIndex.HasValue)
     {
         length = sectionMetadata.Decoders[decoderIndex.Value].OutputStreams[selector.StreamIndex].Length;
         result = decoders[decoderIndex.Value].GetOutputStream(selector.StreamIndex);
     }
     else
     {
         length = archiveMetadata.FileSections[selector.StreamIndex].Length;
         result = streams[selector.StreamIndex];
     }
 }
 public abstract void SetInputStream(int index, ReaderNode stream, long length);
        public ArchiveSectionDecoder(Stream stream, ArchiveMetadata metadata, int index, PasswordStorage password)
        {
            if (stream == null)
                throw new ArgumentNullException(nameof(stream));

            if (!stream.CanRead)
                throw new ArgumentException("Stream must be readable.", nameof(stream));

            if (!stream.CanSeek)
                throw new ArgumentException("Stream must be seekable.", nameof(stream));

            if (metadata == null)
                throw new ArgumentNullException(nameof(metadata));

            if (index < 0 || index >= metadata.DecoderSections.Length)
                throw new ArgumentOutOfRangeException(nameof(index));

            var inputCoordinator = new StreamCoordinator(stream);
            var inputStreams = new ReaderNode[metadata.FileSections.Length];
            for (int i = 0; i < inputStreams.Length; i++)
                inputStreams[i] = new CoordinatedStream(inputCoordinator, metadata.FileSections[i].Offset, metadata.FileSections[i].Length);

            var decoderSection = metadata.DecoderSections[index];
            var decoderDefinitions = decoderSection.Decoders;
            var decoders = new DecoderNode[decoderDefinitions.Length];

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoderDefinition = decoderDefinitions[i];
                decoders[i] = decoderDefinition.DecoderType.CreateDecoder(decoderDefinition.Settings, decoderDefinition.OutputStreams, password);
            }

            for (int i = 0; i < decoders.Length; i++)
            {
                var decoder = decoders[i];
                var decoderDefinition = decoderDefinitions[i];
                var decoderInputDefinitions = decoderDefinition.InputStreams;

                for (int j = 0; j < decoderInputDefinitions.Length; j++)
                {
                    ReaderNode inputStream;
                    long inputLength;
                    SelectStream(metadata, decoderSection, decoderInputDefinitions[j], inputStreams, decoders, out inputStream, out inputLength);
                    decoder.SetInputStream(j, inputStream, inputLength);
                }
            }

            ReaderNode outputStream;
            long outputLength;
            SelectStream(metadata, decoderSection, decoderSection.DecodedStream, inputStreams, decoders, out outputStream, out outputLength);

            mCoordinator = inputCoordinator;
            mInputStreams = inputStreams;
            mDecoders = decoders;
            mOutputStream = outputStream;
        }
Example #15
0
 public LzmaArchiveDecoder(ImmutableArray <byte> settings, long length)
 {
     mDecoder      = new LZMA.Decoder(LZMA.DecoderSettings.CreateFrom(settings));
     mOutput       = new OutputStream(this);
     mOutputLength = length;
 }
Example #16
0
            public void SetInput(ReaderNode stream, long length)
            {
                if (stream == null)
                    throw new ArgumentNullException(nameof(stream));

                if (mInput != null)
                    throw new InvalidOperationException();

                mInput = stream;
                mInputLength = length;
            }