/// <summary> /// Adds the range. /// </summary> /// <param name="values">The values.</param> public void AddRange(BaseTagCollection values) { IEnumerator enums = values.GetEnumerator(); while (enums.MoveNext()) { Add((BaseTag)enums.Current); } }
/// <summary> /// Creates a new <see cref="DefineSpriteTag"/> instance. /// </summary> /// <param name="spriteId">Sprite id. That's a unique identifier, in the range 1..65535, for the movie clip.</param> /// <param name="frameCount">Frame count. </param> /// <param name="tags">Tags. That's an array of BaseTag objects that define the commands that are executed by the Flash Player to animate the movie clip.</param> public DefineSpriteTag(ushort spriteId, ushort frameCount, BaseTagCollection tags) { Init(); this.spriteId = spriteId; this.frameCount = frameCount; this.tagList = tags; if (tagList == null || tagList.Count == 0) { return; } _actionCount = 0; foreach (BaseTag b in tagList) { if (b != null) { _actionCount += b.ActionRecCount; } } tagForAction = new int[_actionCount]; tagOffset = new int[tagList.Count]; int actionIdx = 0; for (int i = 0; i < tagList.Count; i++) { if (tagList[i] == null) { continue; } tagOffset[i] = actionIdx; int count = tagList[i].ActionRecCount; if (count > 0) { for (int j = 0; j < count; j++) { tagForAction[actionIdx + j] = i; } actionIdx += count; } } }
/// <summary> /// Creates a new <see cref="Swf"/> instance. /// </summary> public Swf() { this.header = new SwfHeader(); this.tagList = new BaseTagCollection(); this.tagList.TagAdded += new TagAddedEvent(tagList_TagAdded); Init(); }
/// <summary> /// Injects a range of tags in the current Swf. /// </summary> /// <param name="values">The values.</param> public void InjectTags(BaseTagCollection values) { IEnumerator enums = values.GetEnumerator(); for (int i = 0; enums.MoveNext(); i++) { BaseTag baseTag = (BaseTag)enums.Current; Add(baseTag); } }
/// <summary> /// Creates a new <see cref="Swf"/> instance. /// </summary> /// <param name="header">Swf Header.</param> /// <param name="tagList">Swf Tag list sequence.</param> public Swf(SwfHeader header, BaseTagCollection tagList) { this.header = header; this.tagList = tagList; Init(); // count actions _actionCount = 0; foreach (BaseTag b in tagList) { _actionCount += b.ActionRecCount; if (b is DefineTag) dictionnary.Add(b as DefineTag); } }
/// <summary> /// Adds the range. /// </summary> /// <param name="values">The values.</param> public void AddRange(BaseTagCollection values) { IEnumerator enums = values.GetEnumerator(); while (enums.MoveNext()) Add((BaseTag)enums.Current); }
/// <summary> /// Read and parse VideoFrameTag, into inner tags and raw byte-array header data /// </summary> private static VideoFrameTag ReadVideoFrameTag(BufferedBinaryReader binaryReader, BaseTagCollection tagList) { VideoFrameTag video = new VideoFrameTag(); ushort streamId = binaryReader.PeekUInt16(); IEnumerator tags = tagList.GetEnumerator(); while (tags.MoveNext()) { BaseTag tag = (BaseTag)tags.Current; if (tag is DefineVideoStreamTag) { if (((DefineVideoStreamTag)tag).CharacterId == streamId) video.CodecId = ((DefineVideoStreamTag)tag).CodecId; } } return video; }
/// <summary> /// Read next tag from swf input stream. /// </summary> /// <param name="version">Version.</param> /// <param name="binaryReader">Binary reader.</param> /// <param name="tagList">Tag list.</param> /// <returns></returns> internal static BaseTag ReadTag(byte version, BufferedBinaryReader binaryReader, BaseTagCollection tagList) { long posBefore = binaryReader.BaseStream.Position; RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); int offset = (int)(binaryReader.BaseStream.Position - posBefore); binaryReader.BaseStream.Position = posBefore; BaseTag resTag = null; switch (rh.TagCode) { case (int)TagCodeEnum.DefineBits: resTag = new DefineBitsTag(); break; case (int)TagCodeEnum.DefineBitsJpeg2: resTag = new DefineBitsJpeg2Tag(); break; case (int)TagCodeEnum.DefineBitsJpeg3: resTag = new DefineBitsJpeg3Tag(); break; case (int)TagCodeEnum.DefineBitsLossLess: resTag = new DefineBitsLossLessTag(); break; case (int)TagCodeEnum.DefineBitsLossLess2: resTag = new DefineBitsLossLess2Tag(); break; case (int)TagCodeEnum.DefineButton: resTag = new DefineButtonTag(); break; case (int)TagCodeEnum.DefineButton2: resTag = new DefineButton2Tag(); break; case (int)TagCodeEnum.DefineButtonCxForm: resTag = new DefineButtonCxFormTag(); break; case (int)TagCodeEnum.DefineButtonSound: resTag = new DefineButtonSoundTag(); break; case (int)TagCodeEnum.DefineEditText: resTag = new DefineEditTextTag(); break; case (int)TagCodeEnum.DefineFont: resTag = new DefineFontTag(); break; case (int)TagCodeEnum.DefineFont2: resTag = new DefineFont2Tag(); break; case (int)TagCodeEnum.DefineFontInfo: resTag = new DefineFontInfoTag(); break; case (int)TagCodeEnum.DefineFontInfo2: resTag = new DefineFontInfo2Tag(); break; case (int)TagCodeEnum.DefineMorphShape: resTag = new DefineMorphShapeTag(); break; case (int)TagCodeEnum.DefineShape: resTag = new DefineShapeTag(); break; case (int)TagCodeEnum.DefineShape2: resTag = new DefineShape2Tag(); break; case (int)TagCodeEnum.DefineShape3: resTag = new DefineShape3Tag(); break; case (int)TagCodeEnum.DefineSound: resTag = new DefineSoundTag(); break; case (int)TagCodeEnum.DefineSprite: resTag = new DefineSpriteTag(); break; case (int)TagCodeEnum.DefineText: resTag = new DefineTextTag(); break; case (int)TagCodeEnum.DefineText2: resTag = new DefineText2Tag(); break; case (int)TagCodeEnum.DefineVideoStream: resTag = new DefineVideoStreamTag(); break; case (int)TagCodeEnum.DoAction: resTag = new DoActionTag(); break; case (int)TagCodeEnum.EnableDebugger: resTag = new EnableDebuggerTag(); break; case (int)TagCodeEnum.EnableDebugger2: resTag = new EnableDebugger2Tag(); break; case (int)TagCodeEnum.End: resTag = new EndTag(); break; case (int)TagCodeEnum.ExportAssets: resTag = new ExportAssetsTag(); break; case (int)TagCodeEnum.FrameLabel: resTag = new FrameLabelTag(); break; case (int)TagCodeEnum.ImportAssets: resTag = new ImportAssetsTag(); break; case (int)TagCodeEnum.InitAction: resTag = new InitActionTag(); break; case (int)TagCodeEnum.JpegTable: resTag = new JpegTableTag(); break; case (int)TagCodeEnum.PlaceObject: resTag = new PlaceObjectTag(); break; case (int)TagCodeEnum.PlaceObject2: resTag = new PlaceObject2Tag(); break; case (int)TagCodeEnum.Protect: resTag = new ProtectTag(); break; case (int)TagCodeEnum.RemoveObject: resTag = new RemoveObjectTag(); break; case (int)TagCodeEnum.RemoveObject2: resTag = new RemoveObject2Tag(); break; case (int)TagCodeEnum.ScriptLimit: resTag = new ScriptLimitTag(); break; case (int)TagCodeEnum.SetBackgroundColor: resTag = new SetBackgroundColorTag(); break; case (int)TagCodeEnum.SetTabIndex: resTag = new SetTabIndexTag(); break; case (int)TagCodeEnum.ShowFrame: resTag = new ShowFrameTag(); break; case (int)TagCodeEnum.SoundStreamBlock: resTag = new SoundStreamBlockTag(); break; case (int)TagCodeEnum.SoundStreamHead: resTag = new SoundStreamHeadTag(); break; case (int)TagCodeEnum.SoundStreamHead2: resTag = new SoundStreamHead2Tag(); break; case (int)TagCodeEnum.StartSound: resTag = new StartSoundTag(); break; //TODO: Sorenson Codec case (int)TagCodeEnum.VideoFrame: resTag = ReadVideoFrameTag(binaryReader, tagList); break; default: resTag = new BaseTag(binaryReader.ReadBytes(System.Convert.ToInt32(rh.TagLength + offset))); break; } //Read the data of the current tag resTag.ReadData(version, binaryReader); //LOG long mustRead = rh.TagLength + offset; if (posBefore + mustRead != binaryReader.BaseStream.Position) { binaryReader.BaseStream.Position = posBefore + rh.TagLength + offset; if (log.IsErrorEnabled) log.Error(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....KO"); } else if (log.IsInfoEnabled) log.Info(Enum.GetName(TagCodeEnum.DefineBits.GetType(), rh.TagCode) + "....OK (" + mustRead + ")"); return resTag; }
/// <summary> /// Reads the SWF header only. /// This method don't read the complete content of the /// SWF file. Then, it provides the possibility to /// get faster header informations, and only it. /// </summary> /// <returns></returns> public SwfHeader ReadSwfHeader() { // compressed swf? if (br.PeekChar()=='C') Inflate(); SwfHeader header = new SwfHeader(); header.ReadData(br); this.version = header.Version; tagList = new BaseTagCollection(); br.Close(); return header; }
/// <summary> /// Read swf (header and tags), this is the only /// public method of <see cref="SwfDotNet.IO.SwfReader">SwfReader</see> /// with <see cref="SwfDotNet.IO.SwfReader.Close">Close</see> and /// <see cref="SwfDotNet.IO.SwfReader.ReadSwfHeader">ReadSwfHeader</see> methods. /// The returned <see cref="SwfDotNet.IO.Swf">Swf</see> object contains swf headers informations and the /// tags list. /// </summary> public Swf ReadSwf() { // compressed swf? if (br.PeekChar()=='C') Inflate(); SwfHeader header = new SwfHeader(); header.ReadData(br); this.version = header.Version; tagList = new BaseTagCollection(); bool readEndTag = false; //necessary for the 1 more byte bug while (br.BaseStream.Position < br.BaseStream.Length && !readEndTag) { BaseTag b = SwfReader.ReadTag(this.version, this.br, this.tagList); if (b != null) { if (b is EndTag) readEndTag = true; tagList.Add(b); } }; br.Close(); return new Swf(header, tagList); }
/// <summary> /// Inits this instance. /// </summary> protected void Init() { _tagCode = (int)TagCodeEnum.DefineSprite; this.tagList = new BaseTagCollection(); }
/// <summary> /// Creates a new <see cref="DefineSpriteTag"/> instance. /// </summary> /// <param name="spriteId">Sprite id. That's a unique identifier, in the range 1..65535, for the movie clip.</param> /// <param name="frameCount">Frame count. </param> /// <param name="tags">Tags. That's an array of BaseTag objects that define the commands that are executed by the Flash Player to animate the movie clip.</param> public DefineSpriteTag(ushort spriteId, ushort frameCount, BaseTagCollection tags) { Init(); this.spriteId = spriteId; this.frameCount = frameCount; this.tagList = tags; if (tagList == null || tagList.Count == 0) return; _actionCount = 0; foreach (BaseTag b in tagList) { if (b != null) _actionCount += b.ActionRecCount; } tagForAction = new int[_actionCount]; tagOffset = new int[tagList.Count]; int actionIdx = 0; for (int i = 0; i < tagList.Count; i++) { if (tagList[i] == null) continue; tagOffset[i] = actionIdx; int count = tagList[i].ActionRecCount; if (count > 0) { for (int j = 0; j < count; j++) { tagForAction[actionIdx + j] = i; } actionIdx+=count; } } }