Exemplo n.º 1
0
        // Methods
        public override void Load(Stream fileStream)
        {
            // Header
            var    reader = new ExtendedBinaryReader(fileStream, Encoding.ASCII, false);
            string sig    = reader.ReadSignature();

            if (sig != Signature)
            {
                throw new InvalidSignatureException(Signature, sig);
            }

            // Textures
            uint totalFrameCount = reader.ReadUInt32();
            byte textureCount    = reader.ReadByte();

            for (int i = 0; i < textureCount; ++i)
            {
                Textures.Add(new Texture()
                {
                    FilePath = reader.ReadString(),
                    Unknown1 = reader.ReadByte()
                });
            }

            // Animations
            ushort animCount = reader.ReadUInt16();

            for (int i2 = 0; i2 < animCount; ++i2)
            {
                var anim = new Animation()
                {
                    Name = reader.ReadString()
                };

                ushort frameCount = reader.ReadUInt16();
                anim.Unknown1 = reader.ReadInt16();
                anim.Unknown2 = reader.ReadInt16();

                // Animation Frames
                for (int i3 = 0; i3 < frameCount; ++i3)
                {
                    anim.Frames.Add(new Frame()
                    {
                        TextureIndex = reader.ReadByte(),
                        Unknown1     = reader.ReadInt16(),
                        Unknown2     = reader.ReadInt16(),
                        X            = reader.ReadUInt16(),
                        Y            = reader.ReadUInt16(),
                        Width        = reader.ReadUInt16(),
                        Height       = reader.ReadUInt16(),
                        OriginX      = reader.ReadInt16(),
                        OriginY      = reader.ReadInt16()
                    });
                }

                Animations.Add(anim);
            }
        }
Exemplo n.º 2
0
        public override void Read(ExtendedBinaryReader reader, Action <Color> synchronizationCallback)
        {
            byte r = reader.ReadByte();
            byte g = reader.ReadByte();
            byte b = reader.ReadByte();
            byte a = reader.ReadByte();

            synchronizationCallback(Color.FromNonPremultiplied(r, g, b, a));
        }
Exemplo n.º 3
0
        public override void Deserialize(ExtendedBinaryReader reader, Action <Color> valueFixup)
        {
            byte r = reader.ReadByte();
            byte g = reader.ReadByte();
            byte b = reader.ReadByte();
            byte a = reader.ReadByte();

            valueFixup(Color.FromNonPremultiplied(r, g, b, a));
        }
Exemplo n.º 4
0
            public static Phenotype ReadPhenotype(ExtendedBinaryReader reader)
            {
                var mimNumber    = reader.ReadOptInt32();
                var phenotype    = reader.ReadAsciiString();
                var mapping      = (Mapping)reader.ReadByte();
                var comments     = (Comments)reader.ReadByte();
                var inheritance  = reader.ReadOptArray(reader.ReadAsciiString);
                var inheritances = inheritance == null ? null : new HashSet <string>(inheritance);

                return(new Phenotype(mimNumber, phenotype, mapping, comments, inheritances));
            }
Exemplo n.º 5
0
        protected override Subtitle ReadSubtitle(ExtendedBinaryReader input)
        {
            var offset    = input.ReadUInt16();
            var returnPos = input.Position;

            input.Seek(offset, SeekOrigin.Begin);

            using (var ms = new MemoryStream())
            {
                var subtitle = new Subtitle {
                    Offset = offset
                };

                var b = input.ReadByte();

                while (b != 0x00)
                {
                    switch (b)
                    {
                    case 0x07:     // Color
                    {
                        var b2     = input.ReadByte();
                        var buffer = this.FileEncoding.GetBytes($"<Color: {b2:X2}>");
                        ms.Write(buffer, 0, buffer.Length);
                        break;
                    }

                    case 0x1F:     // Item
                    {
                        var id     = input.ReadUInt16();
                        var buffer = this.FileEncoding.GetBytes($"<Item: {id:X4}>");
                        ms.Write(buffer, 0, buffer.Length);
                        break;
                    }

                    default:
                    {
                        ms.WriteByte(b);     // Es el encoding quien se encarga de sustituirlo si es necesario
                        break;
                    }
                    }

                    b = input.Position == input.Length ? (byte)0x00 : input.ReadByte();
                }

                var text = FileEncoding.GetString(ms.ToArray());
                subtitle.Text        = text;
                subtitle.Translation = text;
                subtitle.Loaded      = text;

                input.Seek(returnPos, SeekOrigin.Begin);
                return(subtitle);
            }
        }
Exemplo n.º 6
0
        protected override IList <TF.Core.TranslationEntities.Subtitle> GetSubtitles()
        {
            var result = new List <TF.Core.TranslationEntities.Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding, Endianness.BigEndian))
                {
                    input.Skip(3);
                    var count = input.ReadByte();
                    input.Skip(4);
                    var pointer1      = input.ReadInt32();
                    var countPointer1 = input.ReadInt16();

                    var numTalkers       = input.ReadInt16();
                    var pointerTalkers   = input.ReadInt32();
                    var pointerRemainder = input.ReadInt32();

                    for (var i = 0; i < count; i++)
                    {
                        input.Skip(4);
                        var groupOffset = input.ReadInt32();
                        input.Skip(1);
                        var stringCount = input.ReadByte();
                        input.Skip(6);

                        var subs = ReadSubtitles(input, groupOffset, stringCount);

                        if (subs.Count > 0)
                        {
                            result.AddRange(subs);
                        }
                    }

                    if (pointerTalkers > 0 && result.Count > 0)
                    {
                        input.Seek(pointerTalkers, SeekOrigin.Begin);
                        for (var i = 0; i < numTalkers; i++)
                        {
                            var offset   = input.ReadInt32();
                            var subtitle = ReadSubtitle(input, offset, true);
                            if (subtitle != null)
                            {
                                subtitle.PropertyChanged += SubtitlePropertyChanged;
                                result.Add(subtitle);
                            }
                        }
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 7
0
        public override void Rebuild(string outputFolder)
        {
            var outputPath = System.IO.Path.Combine(outputFolder, RelativePath);

            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outputPath));

            var subtitles = GetSubtitles();

            using (var fsInput = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fsInput, FileEncoding, Endianness.LittleEndian))
                    using (var fsOutput = new FileStream(outputPath, FileMode.Create))
                        using (var output = new ExtendedBinaryWriter(fsOutput, FileEncoding, Endianness.LittleEndian))
                        {
                            var outputOffset = 0;

                            while (input.Position < input.Length)
                            {
                                var inputNextOffset = input.ReadInt16();
                                var sectionName     = input.ReadString(Encoding.UTF8);

                                using (var tempMemoryStream = new MemoryStream())
                                    using (var temp = new ExtendedBinaryWriter(tempMemoryStream, FileEncoding, Endianness.LittleEndian))
                                    {
                                        temp.WriteString(sectionName);

                                        var aux = input.PeekInt16();
                                        while (aux != -1)
                                        {
                                            var index = input.ReadByte();
                                            temp.Write(index);

                                            var size = input.ReadByte();

                                            var offset = (int)input.Position;
                                            WriteSubtitle(temp, subtitles, offset);

                                            input.ReadString();
                                            aux = input.PeekInt16();
                                        }

                                        input.Skip(2);
                                        temp.Write((short)-1);

                                        var bytes = tempMemoryStream.ToArray();
                                        output.Write((short)(outputOffset + 2 + bytes.Length));
                                        output.Write(bytes);

                                        outputOffset = outputOffset + 2 + bytes.Length;
                                    }
                            }
                        }
        }
Exemplo n.º 8
0
        public NsiReader(Stream stream)
        {
            _stream = stream;
            var compressData = new byte[MaxStreamLength];
            int length       = stream.Read(compressData, 0, MaxStreamLength);
            //uncompress
            var zstd = new Zstandard();
            var decompressedLength = zstd.GetDecompressedLength(compressData, length);
            var decompressedData   = new byte[decompressedLength];

            zstd.Decompress(compressData, length, decompressedData, decompressedLength);

            using (var memStream = new MemoryStream(decompressedData, 0, decompressedLength))
                using (var memReader = new ExtendedBinaryReader(memStream))
                {
                    Version   = DataSourceVersion.Read(memReader);
                    Assembly  = (GenomeAssembly)memReader.ReadByte();
                    JsonKey   = memReader.ReadAsciiString();
                    ReportFor = (ReportFor)memReader.ReadByte();
                    int schemaVersion = memReader.ReadOptInt32();

                    if (schemaVersion != SaCommon.SchemaVersion)
                    {
                        throw new UserErrorException($"Schema version mismatch!! Expected {SaCommon.SchemaVersion}, observed {schemaVersion} for {JsonKey}");
                    }


                    int count         = memReader.ReadOptInt32();
                    var suppIntervals = new Dictionary <ushort, List <Interval <string> > >();
                    for (var i = 0; i < count; i++)
                    {
                        var saInterval = new SuppInterval(memReader);
                        if (suppIntervals.TryGetValue(saInterval.Chromosome.Index, out var intervals))
                        {
                            intervals.Add(new Interval <string>(saInterval.Start, saInterval.End, saInterval.GetJsonString()));
                        }
                        else
                        {
                            suppIntervals[saInterval.Chromosome.Index] = new List <Interval <string> > {
                                new Interval <string>(saInterval.Start, saInterval.End, saInterval.GetJsonString())
                            }
                        };
                    }

                    _intervalArrays = new Dictionary <ushort, IntervalArray <string> >(suppIntervals.Count);
                    foreach ((ushort chromIndex, List <Interval <string> > intervals) in suppIntervals)
                    {
                        _intervalArrays[chromIndex] = new IntervalArray <string>(intervals.ToArray());
                    }
                }
        }
Exemplo n.º 9
0
            public Tuple <int, int> GetCopyInfo()
            {
                if (_mode == WorkMode.Write)
                {
                    throw new NotImplementedException("Esta función no es válida para comprimir");
                }

                var copyFlags = (ushort)(_input.ReadByte() | _input.ReadByte() << 8);

                var copyDistance = 1 + (copyFlags >> 4);
                var copyCount    = 3 + (copyFlags & 0xF);

                return(new Tuple <int, int>(copyDistance, copyCount));
            }
Exemplo n.º 10
0
        public static byte[] Decompress(byte[] compressedData)
        {
            using (var input = new ExtendedBinaryReader(new MemoryStream(compressedData), Encoding.GetEncoding(1252), Endianness.BigEndian))
                using (var output = new MemoryStream())
                {
                    var magic      = input.ReadUInt32();
                    var endianness = input.ReadByte();

                    input.Endianness = endianness == 0 ? Endianness.LittleEndian : Endianness.BigEndian;

                    var version    = input.ReadByte();
                    var headerSize = input.ReadUInt16();

                    var uncompressedSize = input.ReadUInt32();
                    var compressedSize   = input.ReadUInt32();

                    var block = new byte[18];

                    var manager = new BitManager(input);

                    while (input.Position < input.Length)
                    {
                        var type = manager.GetFlagType();

                        switch (type)
                        {
                        case FlagType.Literal:
                            output.WriteByte(input.ReadByte());

                            break;

                        case FlagType.Copy:
                            var(copyPosition, copyCount) = manager.GetCopyInfo();

                            output.Seek(-copyPosition, SeekOrigin.End);
                            output.Read(block, 0, copyCount);
                            output.Seek(0, SeekOrigin.End);
                            output.Write(block, 0, copyCount);

                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }

                    return(output.ToArray());
                }
        }
Exemplo n.º 11
0
        private void ReadHeader()
        {
            var header = _reader.ReadString();

            if (header != SaDataBaseCommon.DataHeader)
            {
                throw new FormatException("Unrecognized header in this database");
            }

            // ReSharper disable UnusedVariable
            var dataVersion = _reader.ReadUInt16();

            var schema = _reader.ReadUInt16();

            if (schema != SaDataBaseCommon.SchemaVersion)
            {
                throw new UserErrorException($"Gene database schema mismatch. Expected {SaDataBaseCommon.SchemaVersion}, observed {schema}");
            }

            var genomeAssembly = (GenomeAssembly)_reader.ReadByte();
            var creationTime   = _reader.ReadInt64();
            // ReSharper restore UnusedVariable

            var dataSourseVersionsCount = _reader.ReadOptInt32();

            for (var i = 0; i < dataSourseVersionsCount; i++)
            {
                DataSourceVersions.Add(DataSourceVersion.Read(_reader));
            }

            CheckGuard();
        }
        private void ReadSourceCommands(ExtendedBinaryReader reader)
        {
            int count = reader.Read7BitEncodedInt();

            for (var i = 0; i < count; i++)
            {
                var action = (NotifyCollectionChangedAction)reader.ReadByte();
                switch (action)
                {
                case NotifyCollectionChangedAction.Add:
                    _sourceCommands.Add(new SourceAddCommand(reader, _keySerializer, _valueSerializer));
                    break;

                case NotifyCollectionChangedAction.Replace:
                    _sourceCommands.Add(new SourceReplaceCommand(reader, _keySerializer, _valueSerializer));
                    break;

                case NotifyCollectionChangedAction.Reset:
                    _sourceCommands.Add(new SourceClearCommand(reader, _keySerializer, _valueSerializer));
                    break;

                case NotifyCollectionChangedAction.Remove:
                    _sourceCommands.Add(new SourceRemoveCommand(reader, _keySerializer));
                    break;
                }
            }
        }
Exemplo n.º 13
0
    public IoCommandStartEvent ReadIoCommandStartEvent(ExtendedBinaryReader reader)
    {
        var evt = new IoCommandStartEvent
        {
            Uid = reader.Read7BitEncodedInt(),
            ProcessInvocationUid = reader.Read7BitEncodedInt(),
            Kind           = (IoCommandKind)reader.ReadByte(),
            Location       = GetTextById(reader.Read7BitEncodedInt()),
            Path           = GetTextById(reader.Read7BitEncodedInt()),
            TimeoutSeconds = reader.ReadNullableInt32(),
            Command        = reader.ReadNullableString(),
            TransactionId  = GetTextById(reader.Read7BitEncodedInt()),
        };

        var argCount = reader.Read7BitEncodedInt();

        if (argCount > 0)
        {
            evt.Arguments = new KeyValuePair <string, object> [argCount];
            for (var i = 0; i < argCount; i++)
            {
                var name  = GetTextById(reader.Read7BitEncodedInt());
                var value = reader.ReadObject();
                evt.Arguments[i] = new KeyValuePair <string, object>(name, value);
            }
        }

        return(evt);
    }
Exemplo n.º 14
0
    public LogEvent ReadLogEvent(ExtendedBinaryReader reader)
    {
        var evt = new LogEvent
        {
            TransactionId        = GetTextById(reader.Read7BitEncodedInt()),
            Text                 = reader.ReadString(),
            Severity             = (LogSeverity)reader.ReadByte(),
            ProcessInvocationUID = reader.ReadNullableInt32()
        };

        var argCount = reader.Read7BitEncodedInt();

        if (argCount > 0)
        {
            evt.Arguments = new KeyValuePair <string, object> [argCount];
            for (var i = 0; i < argCount; i++)
            {
                var key   = GetTextById(reader.Read7BitEncodedInt());
                var value = reader.ReadObject();
                evt.Arguments[i] = new KeyValuePair <string, object>(key, value);
            }
        }

        return(evt);
    }
Exemplo n.º 15
0
            public static Entry ReadEntry(ExtendedBinaryReader reader)
            {
                double score     = reader.ReadDouble();
                byte   enumIndex = reader.ReadByte();

                return(new Entry(score, enumIndex));
            }
Exemplo n.º 16
0
        public NsaIndex(Stream stream)
        {
            using (var memStream = new MemoryStream())
                using (var memReader = new ExtendedBinaryReader(memStream))
                {
                    stream.CopyTo(memStream);//reading all bytes in stream to memStream
                    memStream.Position = 0;

                    Assembly      = (GenomeAssembly)memReader.ReadByte();
                    Version       = DataSourceVersion.Read(memReader);
                    JsonKey       = memReader.ReadAsciiString();
                    MatchByAllele = memReader.ReadBoolean();
                    IsArray       = memReader.ReadBoolean();
                    SchemaVersion = memReader.ReadOptInt32();
                    IsPositional  = memReader.ReadBoolean();

                    var chromCount = memReader.ReadOptInt32();
                    _chromBlocks = new Dictionary <ushort, List <NsaIndexBlock> >(chromCount);
                    for (var i = 0; i < chromCount; i++)
                    {
                        var chromIndex = memReader.ReadOptUInt16();
                        var chunkCount = memReader.ReadOptInt32();
                        _chromBlocks[chromIndex] = new List <NsaIndexBlock>(chunkCount);
                        for (var j = 0; j < chunkCount; j++)
                        {
                            _chromBlocks[chromIndex].Add(new NsaIndexBlock(memReader));
                        }
                    }
                }
        }
Exemplo n.º 17
0
        public ChunkedIndex(Stream stream)
        {
            //reading the index in one shot
            var buffer      = new byte[1048576];
            var indexLength = stream.Read(buffer, 0, 1048576);

            using (var memStream = new MemoryStream(buffer, 0, indexLength))
                using (var memReader = new ExtendedBinaryReader(memStream))
                {
                    Assembly      = (GenomeAssembly)memReader.ReadByte();
                    Version       = DataSourceVersion.Read(memReader);
                    JsonKey       = memReader.ReadAsciiString();
                    MatchByAllele = memReader.ReadBoolean();
                    IsArray       = memReader.ReadBoolean();
                    SchemaVersion = memReader.ReadOptInt32();
                    IsPositional  = memReader.ReadBoolean();

                    var chromCount = memReader.ReadOptInt32();
                    _chromChunks = new Dictionary <ushort, List <Chunk> >(chromCount);
                    for (var i = 0; i < chromCount; i++)
                    {
                        var chromIndex = memReader.ReadOptUInt16();
                        var chunkCount = memReader.ReadOptInt32();
                        _chromChunks[chromIndex] = new List <Chunk>(chunkCount);
                        for (var j = 0; j < chunkCount; j++)
                        {
                            _chromChunks[chromIndex].Add(new Chunk(memReader));
                        }
                    }
                }
        }
        public sealed override void Read(ExtendedBinaryReader reader)
        {
            SubscribeToEndRead();
            var commandCount = reader.Read7BitEncodedInt();

            for (var i = 0; i < commandCount; i++)
            {
                var action = (NotifyCollectionChangedAction)reader.ReadByte();
                switch (action)
                {
                case NotifyCollectionChangedAction.Add:
                    _sourceCommands.Add(new SourceAddCommand(reader, _itemSerializer));
                    break;

                case NotifyCollectionChangedAction.Replace:
                    _sourceCommands.Add(new SourceReplaceCommand(reader, _itemSerializer));
                    break;

                case NotifyCollectionChangedAction.Reset:
                    _sourceCommands.Add(new SourceClearCommand(reader, _itemSerializer));
                    break;

                case NotifyCollectionChangedAction.Remove:
                    _sourceCommands.Add(new SourceRemoveCommand(reader, _itemSerializer));
                    break;
                }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// reads the transcript from the binary reader
        /// </summary>
        public static Transcript Read(ExtendedBinaryReader reader, Gene[] cacheGenes, SimpleInterval[] cacheIntrons,
                                      SimpleInterval[] cacheMirnas, string[] cachePeptideSeqs)
        {
            // transcript
            var referenceIndex = reader.ReadUInt16();
            var start          = reader.ReadOptInt32();
            var end            = reader.ReadOptInt32();
            var id             = CompactId.Read(reader);

            // gene
            var geneIndex = reader.ReadOptInt32();
            var gene      = cacheGenes[geneIndex];

            // encoded data
            var encoded = new EncodedTranscriptData(reader.ReadUInt16(), reader.ReadByte());

            // exons & introns
            var introns  = encoded.HasIntrons  ? ReadIndices(reader, cacheIntrons) : null;
            var cdnaMaps = encoded.HasCdnaMaps ? ReadCdnaMaps(reader)              : null;

            // protein function predictions
            int siftIndex     = encoded.HasSift     ? reader.ReadOptInt32() : -1;
            int polyphenIndex = encoded.HasPolyPhen ? reader.ReadOptInt32() : -1;

            // translation
            var translation = encoded.HasTranslation ? Translation.Read(reader, cachePeptideSeqs) : null;

            // attributes
            var mirnas = encoded.HasMirnas ? ReadIndices(reader, cacheMirnas) : null;

            return(new Transcript(referenceIndex, start, end, id, encoded.Version, translation, encoded.BioType,
                                  gene, TranscriptUtilities.GetTotalExonLength(cdnaMaps), encoded.StartExonPhase, encoded.IsCanonical,
                                  introns, mirnas, cdnaMaps, siftIndex, polyphenIndex, encoded.TranscriptSource));
        }
Exemplo n.º 20
0
        private static object ReadValueType(Type valueType, ExtendedBinaryReader br, bool noAlign = false)
        {
            if (!noAlign)
            {
                br.AlignStream();
            }

            if (valueType == typeof(string))
            {
                return(br.ReadAlignedString());
            }
            else if (valueType == typeof(Int32))
            {
                return(br.ReadInt32());
            }
            else if (valueType == typeof(UInt32))
            {
                return(br.ReadUInt32());
            }
            else if (valueType == typeof(Int64))
            {
                return(br.ReadInt64());
            }
            else if (valueType == typeof(UInt64))
            {
                return(br.ReadUInt64());
            }
            else if (valueType == typeof(Int16))
            {
                return(br.ReadInt16());
            }
            else if (valueType == typeof(UInt16))
            {
                return(br.ReadUInt16());
            }
            else if (valueType == typeof(Byte))
            {
                return(br.ReadByte());
            }
            else if (valueType == typeof(SByte))
            {
                return(br.ReadSByte());
            }
            else if (valueType == typeof(Boolean))
            {
                return(br.ReadBoolean());
            }
            else if (valueType == typeof(Double))
            {
                return(br.ReadDouble());
            }
            else if (valueType == typeof(Single))
            {
                return(br.ReadSingle());
            }
            else
            {
                throw new ArgumentException($"{valueType} is not a value type");
            }
        }
        /// <summary>
        /// checks if the header is good
        /// </summary>
        private static SupplementaryAnnotationHeader GetHeader(ExtendedBinaryReader reader, out long intervalsPosition, string saPath = null)
        {
            // check the header and data version
            var header         = System.Text.Encoding.ASCII.GetString(reader.ReadBytes(SupplementaryAnnotationCommon.DataHeader.Length));
            var dataVersion    = reader.ReadUInt16();
            var schemaVersion  = reader.ReadUInt16();
            var genomeAssembly = (GenomeAssembly)reader.ReadByte();

            if (header != SupplementaryAnnotationCommon.DataHeader || schemaVersion != SupplementaryAnnotationCommon.SchemaVersion)
            {
                throw new UserErrorException($"The header check failed for the supplementary annotation file ({saPath ?? "(resource)"}): ID: exp: {SupplementaryAnnotationCommon.DataHeader} obs: {header}, schema version: exp:{SupplementaryAnnotationCommon.SchemaVersion} obs: {schemaVersion}");
            }

            var creationTimeTicks     = reader.ReadInt64();
            var referenceSequenceName = reader.ReadString();

            // skip over the offsets since they're not currently used
            reader.ReadInt64(); // _dataSourceVersionsOffset
            reader.ReadInt64(); // _dataOffset
            intervalsPosition = reader.ReadInt64();
            reader.ReadInt64(); // _eofOffset

            // load the data source versions
            var numDataSourceVersions = reader.ReadOptInt32();
            var dataSourceVersions    = new List <DataSourceVersion>();

            for (var i = 0; i < numDataSourceVersions; i++)
            {
                dataSourceVersions.Add(DataSourceVersion.Read(reader));
            }

            return(new SupplementaryAnnotationHeader(referenceSequenceName, creationTimeTicks, dataVersion,
                                                     dataSourceVersions, genomeAssembly));
        }
Exemplo n.º 22
0
        private void LoadHeader()
        {
            // grab the index and masked intervals offsets
            _indexOffset = _reader.ReadInt64();
            _reader.ReadInt64();

            // skip the creation time
            _reader.ReadOptInt64();

            // grab the reference metadata
            NumRefSeqs = (ushort)_reader.ReadOptInt32();

            for (ushort i = 0; i < NumRefSeqs; i++)
            {
                var metadata = ReferenceMetadata.Read(_reader);
                ReferenceMetadataList.Add(metadata);
                AddReferenceName(metadata.EnsemblName, metadata.UcscName, i);
            }

            // read the cytogenetic bands
            CytogeneticBands = Genome.CytogeneticBands.Read(_reader);

            // read the genome assembly
            Sequence.Assembly = (GenomeAssembly)_reader.ReadByte();

            // grab the data start tag
            ulong dataStartTag = _reader.ReadUInt64();

            if (dataStartTag != CompressedSequenceCommon.DataStartTag)
            {
                throw new InvalidFileFormatException($"The data start tag does not match the expected values: Obs: {dataStartTag} vs Exp: {CompressedSequenceCommon.DataStartTag}");
            }
        }
Exemplo n.º 23
0
        public static CompactId Read(ExtendedBinaryReader reader)
        {
            var id   = (IdType)reader.ReadByte();
            var info = reader.ReadOptInt32();

            return(new CompactId(id, info));
        }
Exemplo n.º 24
0
        /// <summary>
        /// Reads a list of nodes from the underlying stream, where the number of
        /// nodes is determined by the LEB128 encoded integer prefix.
        /// </summary>
        /// <param name="reader">Reader used for reading from the underlying stream.</param>
        public override void ReadValue(ExtendedBinaryReader reader)
        {
            var count = reader.Read7BitEncodedInt();

            for (var i = 0; i < count; i++)
            {
                var type = (BsfType)reader.ReadByte();

                if (type == BsfType.Null)
                {
                    _list.Add(null);
                }
                else
                {
                    if (ElementType == BsfType.Null)
                    {
                        ElementType = type;
                    }

                    if (type != ElementType)
                    {
                        throw new InvalidOperationException($"List contains elements of both type '{ElementType}' and '{type}");
                    }

                    var node = Create(ElementType);
                    node.ReadValue(reader);
                    _list.Add(node);
                }
            }
        }
Exemplo n.º 25
0
        public static EncodedTranscriptData Read(ExtendedBinaryReader reader)
        {
            var info     = reader.ReadUInt16();
            var contents = reader.ReadByte();

            return(new EncodedTranscriptData(info, contents));
        }
Exemplo n.º 26
0
            public virtual Instruction Read(ExtendedBinaryReader reader)
            {
                var instruction = new Instruction(Name, ArgTypes);

                if (ArgTypes == null)
                {
                    return(instruction);
                }
                for (int i = 0; i < ArgTypes.Length; ++i)
                {
                    if (ArgTypes[i] == AT_PointerArray)
                    {
                        int[] pointers = new int[reader.ReadByte()];
                        for (int i2 = 0; i2 < pointers.Length; ++i2)
                        {
                            pointers[i] = reader.ReadInt32();
                        }
                        Arguments.Add(pointers);
                    }
                    else
                    {
                        instruction.Arguments.Add(ReadByType(reader, ArgTypes[i]));
                    }
                }

                return(instruction);
            }
Exemplo n.º 27
0
        protected override IList <Subtitle> GetSubtitles()
        {
            var result = new List <Subtitle>();

            using (var fs = new FileStream(Path, FileMode.Open))
                using (var input = new ExtendedBinaryReader(fs, FileEncoding))
                {
                    var patternPos = new List <int>();
                    var pos        = input.FindPattern(SearchPattern);
                    while (pos != -1)
                    {
                        patternPos.Add(pos);
                        pos = input.FindPattern(SearchPattern);
                    }

                    if (patternPos.Count > 0)
                    {
                        input.Seek(patternPos[patternPos.Count - 1] + 3, SeekOrigin.Begin);
                        var count = input.ReadByte();

                        for (var i = 0; i < count; i++)
                        {
                            input.Skip(0x1C);
                            var txt = ReadSubtitle(input);
                            if (!string.IsNullOrWhiteSpace(txt.Text))
                            {
                                txt.PropertyChanged += SubtitlePropertyChanged;
                                result.Add(txt);
                            }

                            txt = ReadSubtitle(input);
                            if (!string.IsNullOrWhiteSpace(txt.Text))
                            {
                                txt.PropertyChanged += SubtitlePropertyChanged;
                                result.Add(txt);
                            }
                        }

                        input.Skip(4);
                        var subtitle = ReadSubtitle(input);
                        if (!string.IsNullOrWhiteSpace(subtitle.Text))
                        {
                            subtitle.PropertyChanged += SubtitlePropertyChanged;
                            result.Add(subtitle);
                        }

                        subtitle = ReadSubtitle(input);
                        if (!string.IsNullOrWhiteSpace(subtitle.Text))
                        {
                            subtitle.PropertyChanged += SubtitlePropertyChanged;
                            result.Add(subtitle);
                        }
                    }
                }

            LoadChanges(result);

            return(result);
        }
Exemplo n.º 28
0
        public static byte[] ReadAndDecompress(ExtendedBinaryReader reader)
        {
            var  stream           = new MemoryStream();
            uint decompressedSize = reader.ReadUInt32();
            uint compressedSize   = reader.ReadUInt32();
            byte copyByte         = reader.ReadByte();

            reader.JumpAhead(3);
            uint dataStartOffset = (uint)reader.BaseStream.Position;

            while (stream.Position < decompressedSize)
            {
                byte b = reader.ReadByte();

                if (b == copyByte)
                {
                    byte returnByte = reader.ReadByte();

                    if (returnByte == copyByte)
                    {
                        stream.WriteByte(returnByte);
                        continue;
                    }

                    if (returnByte >= copyByte)
                    {
                        returnByte--;
                    }

                    uint offset          = (uint)stream.Position - returnByte;
                    byte length          = reader.ReadByte();
                    uint currentPosition = (uint)stream.Position;

                    stream.Position = offset;
                    byte[] buffer = new byte[length];
                    stream.Read(buffer, 0, length);
                    stream.Position = currentPosition;
                    stream.Write(buffer, 0, length);
                }
                else
                {
                    stream.WriteByte(b);
                }
            }
            return(stream.ToArray());
        }
        // Methods
        public static void Read(HavokFile h, ExtendedBinaryReader reader)
        {
            // Header
            reader.JumpAhead(0x10);

            // A lot of this was gathered from the Max Havok exporter.
            byte bytesInPointer = reader.ReadByte();

            reader.IsBigEndian = !reader.ReadBoolean();
            byte reusePaddingOpt   = reader.ReadByte();
            byte emptyBaseClassOpt = reader.ReadByte();

            // We jump around a lot here, but there's not really a much cleaner way to do it.
            reader.JumpTo(8, true);
            h.UserTag      = reader.ReadUInt32();
            h.ClassVersion = reader.ReadInt32();
            reader.JumpAhead(4);

            uint  sectionsCount = reader.ReadUInt32();
            uint  unknown1      = reader.ReadUInt32();
            ulong padding1      = reader.ReadUInt64();

            uint unknown2 = reader.ReadUInt32();

            h.ContentsVersion = reader.ReadNullTerminatedString();
            reader.JumpAhead(9); // Seems to be padding

            // Sections
            for (uint i = 0; i < sectionsCount; ++i)
            {
                string sectionName = new string(reader.ReadChars(0x10));
                sectionName = sectionName.Replace("\0", string.Empty);

                // TODO
                reader.JumpAhead(0x20);
            }

            // Padding Checks
            if (padding1 != 0)
            {
                Console.WriteLine($"WARNING: Padding1 != 0 ({padding1})");
            }

            // TODO
            throw new NotImplementedException();
        }
Exemplo n.º 30
0
        public override void Load(ExtendedBinaryReader reader, bool keepOpen = false)
        {
            // Check if file has a signature
            string sig = reader.ReadSignature();

            if (sig == "STSC")
            { // Newer script format
                uint headerSize = reader.ReadUInt32();
                Version = reader.ReadUInt32();
                switch (Version)
                {
                case 4:     // Date A Live: Twin Edition Rio Reincarnation (PSV)
                    ScriptID = reader.ReadUInt16();
                    break;

                case 7:     // Date A Live: Rio Reincarnation (PC)
                    ScriptName = reader.ReadNullTerminatedString();
                    reader.JumpAhead((uint)(0x20 - (ScriptName.Length + 1)));
                    reader.JumpAhead(12);
                    ScriptID = reader.ReadUInt32();
                    break;
                }
            }
            else
            { // Older script format
                // Jump back as older scripts have much smaller headers
                reader.JumpBehind(4);
                ScriptID = reader.ReadUInt16();
            }
            // Stupid workaround to find the end of the code segment
            reader.Offset = (uint)reader.BaseStream.Length;
            while (true)
            {
                byte opcode = reader.ReadByte();

                if (opcode >= 0x94)
                {
                    throw new STSCDisassembleException(this,
                                                       $"Got opcode 0x{opcode:X2} at 0x{reader.BaseStream.Position - 1:X8} in \"{ScriptName}\"" +
                                                       " There is no opcodes larger than 0x93!");
                }

                // Check if its a known instruction
                if (STSCInstructions.DALRRInstructions[opcode] == null)
                {
                    throw new STSCDisassembleException(this,
                                                       $"Got opcode 0x{opcode:X2} at 0x{reader.BaseStream.Position - 1:X8} in \"{ScriptName}\"" +
                                                       " This opcode is unknown!");
                }

                var instruction = STSCInstructions.DALRRInstructions[opcode].Read(reader);
                Instructions.Add(instruction);
                if (reader.BaseStream.Position >= reader.Offset)
                {
                    break;
                }
            }
        }
 public static FragmentRunEntry Parse(ExtendedBinaryReader br)
 {
     var entry = new FragmentRunEntry();
         entry.FirstFragment= br.ReadUInt32();
         entry.FirstFragmentTimestamp = br.ReadUInt64();
         entry.FragmentDuration = br.ReadUInt32();
     if(entry.FragmentDuration == 0)
         entry.DiscontinuityIndicator = br.ReadByte();
     else
         entry.DiscontinuityIndicator = null;
     return entry;
 }
        public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            Version = br.ReadByte();
            Flags = br.ReadUInt24();
            TimeScale = br.ReadUInt32();
            QualityEntryCount = br.ReadByte();
            QualitySegmentUrlModifiers = Enumerable.Range(0, QualityEntryCount).Select(i => br.ReadNullTerminatedString()).ToArray();
            FragmentRunEntryCount = br.ReadUInt32();
            FragmentRunEntryTable = new FragmentRunEntry[FragmentRunEntryCount];
            for (uint i = 0; i < FragmentRunEntryCount; i++)
                FragmentRunEntryTable[i] = FragmentRunEntry.Parse(br);
        }
        public override void Parse(ExtendedBinaryReader br)
        {
            base.Parse(br);

            Version = br.ReadByte();
            Flags = br.ReadUInt24();
            BootstrapinfoVersion = br.ReadUInt32();
            var b = br.ReadByte();
            Profile = (new byte[] { 0x80, 0x40 }).Select(i => (i & b) != 0).ToArray();
            Live = (0x02 & b) != 0;
            Update = (0x01 & b) != 0;
            Reserved = (new byte[] { 0x08, 0x04, 0x02, 0x01 }).Select(i => (i & b) != 0).ToArray();
            TimeScale = br.ReadUInt32();
            CurrentMediaTime = br.ReadUInt64();
            SmpteTimeCodeOffset = br.ReadUInt64();
            MovieIdentifier = br.ReadNullTerminatedString();
            ServerEntryCount = br.ReadByte();
            ServerEntryTable = new ServerEntry[ServerEntryCount];
            for (int i = 0; i < ServerEntryCount; i++)
                ServerEntryTable[i] = ServerEntry.Parse(br);
            QualityEntryCount = br.ReadByte();
            QualityEntryTable = new QualityEntry[QualityEntryCount];
            for (int i = 0; i < QualityEntryCount; i++)
                QualityEntryTable[i] = QualityEntry.Parse(br);
            DrmData = br.ReadNullTerminatedString();
            MetaData = br.ReadNullTerminatedString();
            SegmentRunTableCount = br.ReadByte();
            SegmentRunTableEntries = new SegmentRunTableBox[SegmentRunTableCount];
            for (int i = 0; i < SegmentRunTableCount; i++)
            {
                SegmentRunTableEntries[i] = new SegmentRunTableBox();
                SegmentRunTableEntries[i].Parse(br);
            }
            FragmentRunTableCount = br.ReadByte();
            FragmentRunTableEntries = new FragmentRunTableBox[FragmentRunTableCount];
            for (int i = 0; i < FragmentRunTableCount; i++)
            {
                FragmentRunTableEntries[i] = new FragmentRunTableBox();
                FragmentRunTableEntries[i].Parse(br);
            }
        }
Exemplo n.º 34
0
 public static FLVTag Parse(ExtendedBinaryReader br)
 {
     var b = br.ReadByte();
     var tag = new FLVTag
     {
         Reserved = (byte)(b & 0xc0),
         Filter = (b & 0x20) == 0,
         TagType = (TagType)(b & 0x1f),
         DataSize = br.ReadUInt24(),
         TimeStamp = br.ReadUInt24(),
         TimestampExtended = br.ReadByte(),
         StreamID = br.ReadUInt24()
     };
     tag.HeaderAndBody = br.ReadBytes((tag.TimestampExtended << 24) + (int)tag.TimeStamp);
     return tag;
 }