Пример #1
0
        private static void ReadBlocks(IReader reader, ContainerReader containerFile, TagContainer tags)
        {
            while (containerFile.NextBlock())
            {
                switch (containerFile.BlockName)
                {
                case "data":
                    // Data block
                    tags.AddDataBlock(ReadDataBlock(reader, containerFile.BlockVersion));
                    break;

                case "tag!":
                    // Extracted tag
                    tags.AddTag(ReadTag(reader, containerFile.BlockVersion));
                    break;

                case "ersp":
                    // Extracted Raw Resource Page
                    tags.AddExtractedResourcePage(ReadExtractedResourcePage(reader, containerFile.BlockVersion));
                    break;

                case "rspg":
                    // Resource page
                    tags.AddResourcePage(ReadResourcePage(reader, containerFile.BlockVersion));
                    break;

                case "rsrc":
                    // Resource info
                    tags.AddResource(ReadResource(reader, containerFile.BlockVersion));
                    break;
                }
            }
        }
        public WordCollection Read()
        {
            var result          = new WordCollection();
            var containerReader = new ContainerReader();

            var text = containerReader.Read(ContainerName.MORPHOLOGICAL);


            var splitText = text.Split(Environment.NewLine.ToCharArray()).Where(t => !string.IsNullOrEmpty(t)).Where(t => (t.Trim()[0] != '#'));


            foreach (var row in splitText)
            {
                var cols = row.Split('\t');


                var newWord = new Word()
                {
                    Text        = cols[0],
                    Root        = new Word(cols[1]),
                    Morphologic = cols[2].Split('+').Select(m => new MorphologicItem(m)).ToList()
                };


                result.Add(newWord);
            }



            return(result);
        }
Пример #3
0
        public async Task WriteReadData()
        {
            const string fileName = "hello.txt";
            Random       rand     = new Random(156);

            byte[] data = new byte[1024 * 156];
            rand.NextBytes(data);

            IRsaCryptoAccessor p12CryptoAccessor = this.CreateAccesor();

            using MemoryStream writeMs = new MemoryStream();
            using (ContainerWriter writer = new ContainerWriter(writeMs, fileName, await p12CryptoAccessor.ExtractPublicCertificate()))
            {
                await writer.Write(data, 0, data.Length);
            }

            using MemoryStream readMs = new MemoryStream(writeMs.ToArray());

            using (ContainerReader reader = new ContainerReader(readMs, p12CryptoAccessor))
            {
                string decodedFileName = await reader.ReadFileName();

                Assert.AreEqual(fileName, decodedFileName, "Decoded file name");
                using Stream contentStream = await reader.GetContentStream();

                using MemoryStream buffer = new MemoryStream(data.Length + 10);
                await contentStream.CopyToAsync(buffer);

                byte[] decryptedData = buffer.ToArray();

                Assert.AreEqual(data.Length, decryptedData.Length);
                CollectionAssert.AreEquivalent(data, decryptedData);
            }
        }
Пример #4
0
        private static Patch ReadBlocks(IReader reader, ContainerReader container)
        {
            var result = new Patch();

            while (container.NextBlock())
            {
                switch (container.BlockName)
                {
                case "titl":
                    ReadPatchInfo(reader, container.BlockVersion, result);
                    break;

                case "segm":
                    ReadSegmentChanges(reader, result);
                    break;

                case "blfc":
                    ReadBlfInfo(reader, result);
                    break;

                    #region Deprecated

                case "meta":
                    ReadMetaChanges(reader, result);
                    break;

                case "locl":
                    ReadLocaleChanges(reader, result);
                    break;

                    #endregion Deprecated
                }
            }
            return(result);
        }
Пример #5
0
        public static TagContainer ReadTagContainer(IReader reader)
        {
            var tags = new TagContainer();

            var containerFile = new ContainerReader(reader);

            if (!containerFile.NextBlock() || containerFile.BlockName != "tagc")
            {
                throw new ArgumentException("Not a valid tag container file");
            }

            containerFile.EnterBlock();
            ReadBlocks(reader, containerFile, tags);
            containerFile.LeaveBlock();

            return(tags);
        }
Пример #6
0
        public static Patch LoadPatch(IReader reader)
        {
            var container = new ContainerReader(reader);

            if (!container.NextBlock() || container.BlockName != "asmp")
            {
                throw new InvalidOperationException("Invalid assembly patch");
            }
            if (container.BlockVersion > 0)
            {
                throw new InvalidOperationException("Unrecognized patch version");
            }

            container.EnterBlock();
            Patch patch = ReadBlocks(reader, container);

            container.LeaveBlock();

            return(patch);
        }
Пример #7
0
        public VorbisReader(Stream stream, bool closeStreamOnDispose)
            : this()
        {
            BufferedReadStream bufferedReadStream = new BufferedReadStream(stream)
            {
                CloseBaseStream = closeStreamOnDispose
            };
            ContainerReader containerReader = new ContainerReader(bufferedReadStream, closeStreamOnDispose);

            if (!LoadContainer(containerReader))
            {
                bufferedReadStream.Dispose();
                throw new InvalidDataException("Could not determine container type!");
            }
            _containerReader = containerReader;
            if (_decoders.Count == 0)
            {
                throw new InvalidDataException("No Vorbis data found!");
            }
        }
        private static int DecryptFile(DecryptFileOptions opts)
        {
            string          pkcs11LibPath = opts.LibPath ?? FindEidLibrary();
            IBokPinProvider pinProvider   = CreatePinpProvider(opts.UseConsolePin);

            using EidRsaCryptoAccessor eidRsaCryptoAccessor = new EidRsaCryptoAccessor(pkcs11LibPath, pinProvider);

            using FileStream inputFiletream = new FileStream(opts.EncryptedFile, FileMode.Open, FileAccess.Read);

            using ContainerReader reader = new ContainerReader(inputFiletream, eidRsaCryptoAccessor);

            string fileName       = reader.ReadFileName().GetAwaiter().GetResult();
            string outputFilePath = Path.Combine(Path.GetDirectoryName(opts.EncryptedFile), fileName);

            using FileStream outputFiletream = new FileStream(outputFilePath, FileMode.Create, FileAccess.ReadWrite);

            using Stream contentSrream = reader.GetContentStream().GetAwaiter().GetResult();
            contentSrream.CopyTo(outputFiletream);

            return(0);
        }
Пример #9
0
        private static void ReadBlocks(IReader reader, ContainerReader containerFile, TagContainer tags)
        {
            while (containerFile.NextBlock())
            {
                switch (containerFile.BlockName)
                {
                case "data":
                    // Data block
                    tags.AddDataBlock(ReadDataBlock(reader, containerFile.BlockVersion));
                    break;

                case "tag!":
                    // Extracted tag
                    tags.AddTag(ReadTag(reader, containerFile.BlockVersion));
                    break;

                case "ersp":
                    // Extracted Raw Resource Page
                    tags.AddExtractedResourcePage(ReadExtractedResourcePage(reader, containerFile.BlockVersion));
                    break;

                case "rspg":
                    // Resource page
                    tags.AddResourcePage(ReadResourcePage(reader, containerFile.BlockVersion));
                    break;

                case "rsrc":
                    // Resource info
                    tags.AddResource(ReadResource(reader, containerFile.BlockVersion));
                    break;

                case "pdct":
                    // Prediction info
                    tags.AddPrediction(ReadPrediction(reader, containerFile.BlockVersion));
                    break;

                case "sndc":
                    // Sound platform codec
                    tags.AddSoundCodec(ReadSoundCodec(reader, containerFile.BlockVersion));
                    break;

                case "snpr":
                    // Sound pitch range
                    tags.AddSoundPitchRange(ReadSoundPitchRange(reader, containerFile.BlockVersion));
                    break;

                case "snld":
                    // Sound language pitch range
                    tags.AddSoundLanguageDuration(ReadSoundLanguageDuration(reader, containerFile.BlockVersion));
                    break;

                case "snpb":
                    // Sound playback parameter
                    tags.AddSoundPlayback(ReadSoundPlayback(reader, containerFile.BlockVersion));
                    break;

                case "snsc":
                    // Sound scale
                    tags.AddSoundScale(ReadSoundScale(reader, containerFile.BlockVersion));
                    break;

                case "spro":
                    // Sound promotion
                    tags.AddSoundPromotion(ReadSoundPromotion(reader, containerFile.BlockVersion));
                    break;

                case "scpb":
                    // Sound custom playback
                    tags.AddSoundCustomPlayback(ReadSoundCustomPlayback(reader, containerFile.BlockVersion));
                    break;

                case "snex":
                    // Sound extra info
                    tags.AddSoundExtraInfo(ReadSoundExtraInfo(reader, containerFile.BlockVersion));
                    break;
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Create a track to be placed in the list of a container's tracks.
 /// </summary>
 /// <param name="source">The container containing this track.</param>
 /// <param name="trackNumber">The position of the track in the container's list of tracks.</param>
 /// <remarks>The <paramref name="trackNumber"/> required for reading from the container.</remarks>
 internal MatroskaTrack(ContainerReader source, int trackNumber) : base(source, trackNumber)
 {
 }
Пример #11
0
 /// <summary>
 /// Create a track to be placed in the list of a container's tracks.
 /// </summary>
 /// <param name="source">The container containing this track.</param>
 /// <param name="trackNumber">The position of the track in the container's list of tracks.</param>
 /// <remarks>The <paramref name="trackNumber"/> required for reading from the container.</remarks>
 internal Track(ContainerReader source, int trackNumber)
 {
     Source           = source;
     this.trackNumber = trackNumber;
 }