internal void _ParseTags() { bool __tagsRemain = true; Tags = new List <ISwfTag>(); TimelineStream = new List <byte[]>(); BinaryDatas = new Dictionary <uint, byte[]>(); Fonts = new Dictionary <uint, DefineFont2_3>(); Metadata = null; Symbols = new Dictionary <string, uint>(); while (__tagsRemain) { /* * RECORDHEADER (short) * Field Type Comment * TagCodeAndLength UI16 Upper 10 bits: tag typeLower 6 bits: tag length * * RECORDHEADER (long) * Field Type Comment * TagCodeAndLength UI16 Tag type and length of 0x3F Packed together as in short header * Length SI32 Length of tag */ uint __b = _r.GetUI16(); _curTag = (uint)(__b >> 6); _curTagLen = __b & 0x3F; if (_curTagLen == 0x3F) { _curTagLen = _r.GetUI32(); } uint __tagEnd = _r.Position + _curTagLen; //Debug.WriteLine(r.Position + " type: " + ((uint)curTag).ToString("X2") + " -- " + Enum.GetName(typeof(TagType), curTag)); switch (_curTag) { case TagType.End: Tags.Add(new EndTag()); __tagsRemain = false; break; case TagType.FileAttributes: Tags.Add(new FileAttributesTag(_r)); break; case TagType.BackgroundColor: Tags.Add(new BackgroundColorTag(_r)); break; case TagType.SerialNumber: Tags.Add(new SerialNumberTag(_r)); break; case TagType.ScriptLimits: Tags.Add(new ScriptLimitsTag(_r)); break; case TagType.Metadata: MetadataTag __metadataTag = new MetadataTag(_r); Metadata = __metadataTag.xml; Tags.Add(__metadataTag); break; case TagType.DefineBinaryData: DefineBinaryDataTag __defineBinaryDataTag = new DefineBinaryDataTag(_r, _curTagLen); BinaryDatas.Add(__defineBinaryDataTag.id, __defineBinaryDataTag.data); Tags.Add(__defineBinaryDataTag); break; case TagType.SymbolClass: SymbolClassTag __symbolClassTag = new SymbolClassTag(_r, _curTagLen); Symbols = __symbolClassTag.Symbols; Tags.Add(__symbolClassTag); break; case TagType.DefineShape: Tags.Add(new DefineShapeTag(_r)); break; case TagType.DefineShape2: Tags.Add(new DefineShape2Tag(_r)); break; case TagType.DefineShape3: Tags.Add(new DefineShape3Tag(_r)); break; case TagType.DefineShape4: Tags.Add(new DefineShape4Tag(_r)); break; case TagType.PlaceObject: Tags.Add(new PlaceObjectTag(_r, __tagEnd)); break; case TagType.PlaceObject2: Tags.Add(new PlaceObject2Tag(_r, this.Header.Version)); break; case TagType.PlaceObject3: Tags.Add(new PlaceObject3Tag(_r)); break; case TagType.RemoveObject: Tags.Add(new RemoveObjectTag(_r)); break; case TagType.RemoveObject2: Tags.Add(new RemoveObject2Tag(_r)); break; case TagType.ShowFrame: Tags.Add(new ShowFrame(_r)); break; case TagType.FrameLabel: Tags.Add(new FrameLabelTag(_r)); break; case TagType.DefineSprite: DefineSpriteTag sp = new DefineSpriteTag(_r, this.Header.Version); Tags.Add(sp); break; // Bitmaps case TagType.JPEGTables: JpegTable = new JPEGTables(_r, _curTagLen); Tags.Add(JpegTable); break; case TagType.DefineBits: Tags.Add(new DefineBitsTag(_r, _curTagLen, false, false)); break; case TagType.DefineBitsJPEG2: Tags.Add(new DefineBitsTag(_r, _curTagLen, true, false)); break; case TagType.DefineBitsJPEG3: Tags.Add(new DefineBitsTag(_r, _curTagLen, true, true)); break; case TagType.DefineBitsLossless: Tags.Add(new DefineBitsLosslessTag(_r, _curTagLen, false)); break; case TagType.DefineBitsLossless2: Tags.Add(new DefineBitsLosslessTag(_r, _curTagLen, true)); break; // Sound case TagType.DefineSound: Tags.Add(new DefineSoundTag(_r, _curTagLen)); break; case TagType.StartSound: Tags.Add(new StartSoundTag(_r)); break; case TagType.SoundStreamHead: case TagType.SoundStreamHead2: Tags.Add(new SoundStreamHeadTag(_r)); break; case TagType.SoundStreamBlock: SoundStreamBlockTag ssb = new SoundStreamBlockTag(_r, _curTagLen); TimelineStream.Add(ssb.SoundData); Tags.Add(ssb); break; // text case TagType.DefineFontInfo: break; case TagType.DefineFontInfo2: break; case TagType.DefineFont: break; case TagType.DefineFont2: DefineFont2_3 df2 = new DefineFont2_3(_r, false); Tags.Add(df2); Fonts.Add(df2.FontId, df2); break; case TagType.DefineFont3: DefineFont2_3 df3 = new DefineFont2_3(_r, true); Tags.Add(df3); Fonts.Add(df3.FontId, df3); break; case TagType.DefineFontAlignZones: DefineFontAlignZonesTag dfaz = new DefineFontAlignZonesTag(_r, Fonts); Tags.Add(dfaz); break; case TagType.CSMTextSettings: CSMTextSettingsTag csm = new CSMTextSettingsTag(_r); Tags.Add(csm); break; case TagType.DefineText: DefineTextTag dt = new DefineTextTag(_r, false); Tags.Add(dt); break; case TagType.DefineText2: DefineTextTag dt2 = new DefineTextTag(_r, true); Tags.Add(dt2); break; case TagType.DefineEditText: Tags.Add(new DefineEditTextTag(_r)); break; case TagType.DefineFontName: Tags.Add(new DefineFontName(_r)); break; // buttons case TagType.DefineButton: Tags.Add(new DefineButton(_r)); break; case TagType.DefineButton2: Tags.Add(new DefineButton2(_r)); break; case TagType.DefineButtonCxform: Tags.Add(new DefineButtonCxform(_r)); break; case TagType.DefineButtonSound: Tags.Add(new DefineButtonSound(_r)); break; // actions case TagType.ExportAssets: Tags.Add(new ExportAssetsTag(_r)); break; case TagType.DoAction: Tags.Add(new DoActionTag(_r, _curTagLen)); break; case TagType.DoInitAction: Tags.Add(new DoActionTag(_r, _curTagLen, true)); break; // todo: defineMorphShape case TagType.DefineMorphShape: Tags.Add(new UnsupportedDefinitionTag(_r, _curTag, "Morphs not supported")); _r.SkipBytes(_curTagLen); break; // todo: defineVideoStream case TagType.DefineVideoStream: Tags.Add(new UnsupportedDefinitionTag(_r, _curTag, "Video not supported")); _r.SkipBytes(_curTagLen); break; case TagType.ImportAssets: case TagType.ImportAssets2: Tags.Add(new UnsupportedDefinitionTag(_r, _curTag, "Import Assets not yet supported")); _r.SkipBytes(_curTagLen); break; // todo: ImportAssets tags case TagType.DoABC: Tags.Add(new DoABCTag(_r, _curTagLen)); //_r.SkipBytes(_curTagLen); break; case TagType.DoABC2: Tags.Add(new DoABCTag(_r, _curTagLen, true)); //_r.SkipBytes(_curTagLen); break; default: // skip if unknown Debug.WriteLine("unknown type: " + ((uint)_curTag).ToString("X2") + " -- "); Log.AppendLine("Unhandled swf tag: " + ((uint)_curTag).ToString("X2") + " -- "); Tags.Add(new UnsupportedDefinitionTag(_r, (uint)_curTag, "Unhandled swf tag: " + ((uint)_curTag).ToString("X2"))); _r.SkipBytes(_curTagLen); break; } if (__tagEnd != _r.Position) { Debug.WriteLine("bad tag: " + ((uint)_curTag).ToString("X2")); Log.AppendLine("Tag not fully parsed: " + ((uint)_curTag).ToString("X2")); _r.Position = __tagEnd; } } }
private void ParseTags(SwfReader r, byte swfVersion) { bool tagsRemain = true; uint curFrame = 0; while (tagsRemain) { uint b = r.GetUI16(); curTag = (uint)(b >> 6); curTagLen = b & 0x3F; if (curTagLen == 0x3F) { curTagLen = r.GetUI32(); } uint tagEnd = r.Position + curTagLen; //Debug.WriteLine("sprite type: " + ((uint)curTag).ToString("X2") + " -- " + Enum.GetName(typeof(TagType), curTag)); switch (curTag) { case TagType.End: tagsRemain = false; ControlTags.Add(new EndTag()); break; case TagType.PlaceObject: PlaceObjectTag pot = new PlaceObjectTag(r, tagEnd); FirstFrameObjects.Add(pot); ControlTags.Add(pot); break; case TagType.PlaceObject2: PlaceObject2Tag po2t = new PlaceObject2Tag(r, swfVersion); if (po2t.HasCharacter) { FirstFrameObjects.Add(po2t); } ControlTags.Add(po2t); break; case TagType.PlaceObject3: PlaceObject3Tag po3t = new PlaceObject3Tag(r); if (po3t.HasCharacter) { FirstFrameObjects.Add(po3t); } ControlTags.Add(po3t); break; case TagType.RemoveObject: ControlTags.Add(new RemoveObjectTag(r)); break; case TagType.RemoveObject2: ControlTags.Add(new RemoveObject2Tag(r)); break; case TagType.ShowFrame: ControlTags.Add(new ShowFrame(r)); curFrame++; break; case TagType.SoundStreamHead: case TagType.SoundStreamHead2: ControlTags.Add(new SoundStreamHeadTag(r)); break; case TagType.FrameLabel: ControlTags.Add(new FrameLabelTag(r)); break; case TagType.DoAction: ControlTags.Add(new DoActionTag(r, curTagLen)); break; case TagType.DoInitAction: ControlTags.Add(new DoActionTag(r, curTagLen, true)); break; default: // skip if unknown //Debug.WriteLine("invalid sprite tag: " + ((uint)curTag).ToString("X2") + " -- " + Enum.GetName(typeof(TagType), curTag)); r.SkipBytes(curTagLen); break; } if (tagEnd != r.Position) { Console.WriteLine("bad tag in sprite: " + Enum.GetName(typeof(TagType), curTag)); } } }