Exemplo n.º 1
0
        public void ReadLongTagDataTest()
        {
            const SwfTagType tagType = SwfTagType.ExportAssets;
            var data = new byte[4096];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = (byte)(i & 0xff);
            }
            const int header = ((int)tagType << 6) | 0x3f;
            var       mem    = new MemoryStream();

            mem.WriteByte(header & 0xff);
            mem.WriteByte(header >> 8);
            var tagLength = data.Length;

            mem.WriteByte((byte)((tagLength >> 0) & 0xff));
            mem.WriteByte((byte)((tagLength >> 8) & 0xff));
            mem.WriteByte((byte)((tagLength >> 16) & 0xff));
            mem.WriteByte((byte)((tagLength >> 24) & 0xff));

            mem.Write(data, 0, data.Length);
            mem.Seek(0, SeekOrigin.Begin);
            var reader  = new SwfStreamReader(mem);
            var tagData = reader.ReadTagData();

            Assert.IsNotNull(tagData);
            Assert.AreEqual(tagType, tagData.Type);
            Assert.IsNotNull(tagData.Data);
            AssertExt.AreEqual(data, tagData.Data, "Data should be equal");
            Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
        }
Exemplo n.º 2
0
        protected T ReadTag <T>(string resourceName, string tagHash) where T : SwfTagBase
        {
            using (var stream = OpenEmbeddedResource(resourceName)) {
                var file   = new SwfFile();
                var reader = new SwfStreamReader(stream);
                file.FileInfo = reader.ReadSwfFileInfo();
                reader        = GetSwfStreamReader(file.FileInfo, stream);
                file.Header   = reader.ReadSwfHeader();

                while (!reader.IsEOF)
                {
                    var tagData = reader.ReadTagData();

                    var hash = GetTagHash(tagData);
                    if (tagHash == hash)
                    {
                        var tagReader = new SwfTagDeserializer(file);
                        //using (var dump = File.Open(@"D:\temp\1.bin", FileMode.Create)) {
                        //    dump.Write(tagData.Data, 0, tagData.Data.Length);
                        //    dump.Flush();
                        //}
                        return(tagReader.ReadTag <T>(tagData));
                    }
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        protected IEnumerable <SwfTagData> IterateTags(Stream stream)
        {
            var file   = new SwfFile();
            var reader = new SwfStreamReader(stream);

            file.FileInfo = reader.ReadSwfFileInfo();
            reader        = GetSwfStreamReader(file.FileInfo, stream);
            file.Header   = reader.ReadSwfHeader();

            while (!reader.IsEOF)
            {
                var tagData = reader.ReadTagData();

                yield return(tagData);
            }
        }
Exemplo n.º 4
0
        protected SwfTagData ReadTagData(string resourceName, string tagHash)
        {
            using (var stream = OpenEmbeddedResource(resourceName)) {
                var file   = new SwfFile();
                var reader = new SwfStreamReader(stream);
                file.FileInfo = reader.ReadSwfFileInfo();
                reader        = GetSwfStreamReader(file.FileInfo, stream);
                file.Header   = reader.ReadSwfHeader();

                while (!reader.IsEOF)
                {
                    var tagData = reader.ReadTagData();

                    var hash = GetTagHash(tagData);
                    if (tagHash == hash)
                    {
                        return(tagData);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 5
0
 public void ReadShortTagDataTest()
 {
     const SwfTagType tagType = SwfTagType.ExportAssets;
     var data = new byte[10];
     for (var i = 0; i < data.Length; i++) {
         data[i] = (byte)(i & 0xff);
     }
     var header = ((int)tagType << 6) | data.Length;
     var mem = new MemoryStream();
     mem.WriteByte((byte)(header & 0xff));
     mem.WriteByte((byte)(header >> 8));
     mem.Write(data, 0, data.Length);
     mem.Seek(0, SeekOrigin.Begin);
     var reader = new SwfStreamReader(mem);
     var tagData = reader.ReadTagData();
     Assert.IsNotNull(tagData);
     Assert.AreEqual(tagType, tagData.Type);
     Assert.IsNotNull(tagData.Data);
     AssertExt.AreEqual(data, tagData.Data, "Data should be equal");
     Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream");
 }
Exemplo n.º 6
0
        protected IEnumerable<SwfTagData> IterateTags(Stream stream)
        {
            var file = new SwfFile();
            var reader = new SwfStreamReader(stream);
            file.FileInfo = reader.ReadSwfFileInfo();
            reader = GetSwfStreamReader(file.FileInfo, stream);
            file.Header = reader.ReadSwfHeader();

            while (!reader.IsEOF) {
                var tagData = reader.ReadTagData();

                yield return tagData;
            }
        }