public void ReadTest() { var mem = new MemoryStream(_etalon0); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.DefineShape, Data = mem.ToArray() }; var res = tagReader.ReadTag<DefineShapeTag>(tagData); AssertTag.AreEqual(GetDefineShapeTag0(), res); }
public void ReadTest() { var mem = new MemoryStream(_etalon); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.SetBackgroundColor, Data = mem.ToArray() }; var res = tagReader.ReadTag<SetBackgroundColorTag>(tagData); Assert.IsNotNull(res); AssertTag.AreEqual(GetSetBackgroundTag(), res); }
public void ReadTest() { var mem = new MemoryStream(_etalon); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.FileAttributes, Data = mem.ToArray() }; var res = tagReader.ReadTag<FileAttributesTag>(tagData); Assert.IsNotNull(res); AssertTag.AreEqual(GetFileAttributesTag(), res); }
public void ReadTest() { var mem = new MemoryStream(_etalon); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.End, Data = mem.ToArray() }; var res = tagReader.ReadTag<EndTag>(tagData); Assert.IsNotNull(res); Assert.IsNull(res.RestData); }
public void ReadTest() { var mem = new MemoryStream(_etalon); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.RemoveObject2, Data = mem.ToArray() }; var res = tagReader.ReadTag<RemoveObject2Tag>(tagData); Assert.IsNotNull(res); Assert.AreEqual(0x4030, res.Depth); Assert.IsNull(res.RestData); }
public void ReadTest() { var mem = new MemoryStream(_etalon); var tagReader = new SwfTagDeserializer(new SwfFile()); var tagData = new SwfTagData { Type = SwfTagType.PlaceObject, Data = mem.ToArray() }; var res = tagReader.ReadTag<PlaceObjectTag>(tagData); Assert.IsNotNull(res); Assert.AreEqual(0x2010, res.CharacterID); Assert.AreEqual(0x4030, res.Depth); Assert.IsFalse(res.Matrix.HasScale); Assert.IsFalse(res.Matrix.HasRotate); Assert.AreEqual(0, res.Matrix.TranslateX); Assert.AreEqual(0, res.Matrix.TranslateY); Assert.IsTrue(res.ColorTransform.HasValue); Assert.IsFalse(res.ColorTransform.Value.HasAddTerms); Assert.IsFalse(res.ColorTransform.Value.HasMultTerms); Assert.IsNull(res.RestData); }
protected void SaveTag(SwfTagData tagData, string root) { var tagDir = Path.Combine(root, string.Format("{0}", tagData.Type)); if (!Directory.Exists(tagDir)) { Directory.CreateDirectory(tagDir); } var binFilepath = Path.Combine(tagDir, GetFileName(tagData)); using (var bin = File.Open(binFilepath, FileMode.Create)) { bin.Write(tagData.Data, 0, tagData.Data.Length); bin.Flush(); } }
protected void ReadTag(SwfTagData tagData) { try { var tagReader = new SwfTagDeserializer(new SwfFile()).ReadTag(tagData); } catch { } }
protected string GetFileName(SwfTagData tagData) { return string.Format("{0}.bin", GetTagHash(tagData)); }
public void WriteShortTagDataTest() { const SwfTagType tagType = SwfTagType.ExportAssets; var data = new byte[10]; for (var i = 0; i < data.Length; i++) { data[i] = (byte)(i & 0xff); } var tagData = new SwfTagData { Type = tagType, Data = data }; var mem = new MemoryStream(); var writer = new SwfStreamWriter(mem); writer.WriteTagData(tagData); var array = mem.ToArray(); var header = ((int)tagType << 6) | data.Length; Assert.AreEqual((byte)(header & 0xff), array[0]); Assert.AreEqual((byte)(header >> 8), array[1]); array = array.Skip(2).ToArray(); AssertExt.AreEqual(data, array, "Data should be equal"); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream"); }
public void WriteLongTagDataTest() { const SwfTagType tagType = SwfTagType.ExportAssets; var data = new byte[4096]; for (var i = 0; i < data.Length; i++) { data[i] = (byte)(i & 0xff); } var tagData = new SwfTagData { Type = tagType, Data = data }; var mem = new MemoryStream(); var writer = new SwfStreamWriter(mem); writer.WriteTagData(tagData); var array = mem.ToArray(); const int header = ((int)tagType << 6) | 0x3f; Assert.AreEqual(header & 0xff, array[0]); Assert.AreEqual(header >> 8, array[1]); var len = data.Length; Assert.AreEqual((byte)((len >> 0) & 0xff), array[2]); Assert.AreEqual((byte)((len >> 8) & 0xff), array[3]); Assert.AreEqual((byte)((len >> 16) & 0xff), array[4]); Assert.AreEqual((byte)((len >> 24) & 0xff), array[5]); array = array.Skip(6).ToArray(); AssertExt.AreEqual(data, array, "Data should be equal"); Assert.AreEqual(mem.Length, mem.Position, "Should reach end of the stream"); }