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 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); } }
public void ReadSwfFileInfoTest() { var mem = new MemoryStream(); mem.WriteByte((byte)'C'); mem.WriteByte((byte)'W'); mem.WriteByte((byte)'S'); mem.WriteByte(10); mem.WriteByte(0x78); mem.WriteByte(0x56); mem.WriteByte(0x34); mem.WriteByte(0x12); mem.Seek(0, SeekOrigin.Begin); var reader = new SwfStreamReader(mem); var fileInfo = reader.ReadSwfFileInfo(); Assert.AreEqual("CWS", fileInfo.Format); Assert.AreEqual(10, fileInfo.Version); Assert.AreEqual(0x12345678, fileInfo.FileLength); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream"); }
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 ReadCwsFileInfoTest() { var mem = new MemoryStream(); mem.WriteByte((byte)'C'); mem.WriteByte((byte)'W'); mem.WriteByte((byte)'S'); mem.WriteByte(10); mem.WriteByte(0x78); mem.WriteByte(0x56); mem.WriteByte(0x34); mem.WriteByte(0x12); mem.Seek(0, SeekOrigin.Begin); var reader = new SwfStreamReader(mem); var fileInfo = reader.ReadSwfFileInfo(); Assert.AreEqual(SwfFormat.CWS, fileInfo.Format); Assert.AreEqual(10, fileInfo.Version); Assert.AreEqual(0x12345678, fileInfo.FileLength); 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; } }