protected IEnumerable<TagBinaryInfo> GetTagFullBinariesFromSwfResource(string resourceName) { var file = new SwfFile(); var stream = OpenEmbeddedResource(resourceName); SwfStreamReader reader = new SwfStreamReader(stream); file.FileInfo = reader.ReadSwfFileInfo(); stream = DecompressIfNeeded(file.FileInfo, stream); stream.Seek(8, SeekOrigin.Begin); reader = new SwfStreamReader(stream); file.Header = reader.ReadSwfHeader(); while (stream.Position < stream.Length) { var position = stream.Position; ushort typeAndSize = reader.ReadUInt16(); SwfTagType type = (SwfTagType)(typeAndSize >> 6); int shortSize = typeAndSize & 0x3f; int size = shortSize < 0x3f ? shortSize : reader.ReadInt32(); var length = stream.Position - position + size; stream.Seek(position, SeekOrigin.Begin); yield return new TagBinaryInfo { Type = type, Binary = reader.ReadBytes((int)length) }; } }
public void ReadSwfHeaderTest() { var mem = new MemoryStream(); var writer = new SwfStreamWriter(mem); var rect = new SwfRect { XMin = 0x004, XMax = 0x48f, YMin = 0x008, YMax = 0x0ee }; writer.WriteRect(ref rect); writer.WriteFixedPoint8(23.75); writer.WriteUInt16(20); mem.Seek(0, SeekOrigin.Begin); var reader = new SwfStreamReader(mem); var hdr = reader.ReadSwfHeader(); Assert.AreEqual(rect, hdr.FrameSize); Assert.AreEqual(23.75, hdr.FrameRate); Assert.AreEqual(20, hdr.FrameCount); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream"); }
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); }
protected IEnumerable <TagBinaryInfo> GetTagFullBinariesFromSwfResource(string resourceName) { var file = new SwfFile(); var stream = OpenEmbeddedResource(resourceName); SwfStreamReader reader = new SwfStreamReader(stream); file.FileInfo = reader.ReadSwfFileInfo(); stream = DecompressIfNeeded(file.FileInfo, stream); stream.Seek(8, SeekOrigin.Begin); reader = new SwfStreamReader(stream); file.Header = reader.ReadSwfHeader(); while (stream.Position < stream.Length) { var position = stream.Position; ushort typeAndSize = reader.ReadUInt16(); SwfTagType type = (SwfTagType)(typeAndSize >> 6); int shortSize = typeAndSize & 0x3f; int size = shortSize < 0x3f ? shortSize : reader.ReadInt32(); var length = stream.Position - position + size; stream.Seek(position, SeekOrigin.Begin); yield return(new TagBinaryInfo { Type = type, Binary = reader.ReadBytes((int)length) }); } }
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); } }
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); }
public void ReadSwfHeaderTest() { var mem = new MemoryStream(); var writer = new SwfStreamWriter(mem); var rect = new SwfRect { XMin = 0x004, XMax = 0x48f, YMin = 0x008, YMax = 0x0ee }; writer.WriteRect(ref rect); writer.WriteFixedPoint8(23.75); writer.WriteUInt16(20); mem.Seek(0, SeekOrigin.Begin); var reader = new SwfStreamReader(mem); var hdr = reader.ReadSwfHeader(); Assert.AreEqual(rect, hdr.FrameSize); Assert.AreEqual(23.75, hdr.FrameRate); Assert.AreEqual(20, hdr.FrameCount); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream"); }
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; } }