コード例 #1
0
 SwfTagData ISwfTagVisitor <ISwfStreamWriter, SwfTagData> .Visit(DefineFontTag tag, ISwfStreamWriter writer)
 {
     writer.WriteUInt16(tag.FontID);
     foreach (var offset in tag.OffsetTable)
     {
         writer.WriteUInt16(offset);
     }
     return(null);
 }
コード例 #2
0
ファイル: PokeSwf.cs プロジェクト: wanghehacker/flashdevelop
        static void ExploreSWF(Stream stream)
        {
            if (stream == null)
            {
                return;
            }
            SwfReader reader = new SwfReader(stream);
            //SwfExportTagReader reader = new SwfExportTagReader(stream);
            Swf swf = null;

            try
            {
                swf = reader.ReadSwf();
                foreach (BaseTag tag in swf)
                {
                    if (tag is ExportTag)
                    {
                        ExportTag etag = (ExportTag)tag;
                        for (int i = 0; i < etag.Ids.Count; i++)
                        {
                            BaseTag ftag = FindObject(swf, (ushort)etag.Ids[i]);
                            if (ftag is DefineSpriteTag)
                            {
                                DefineSpriteTag stag = (DefineSpriteTag)ftag;
                                Console.WriteLine("Symbol '" + etag.Names[i] + "' - " + stag.Size);
                            }
                            else if (ftag is DefineSoundTag)
                            {
                                DefineSoundTag stag = (DefineSoundTag)ftag;
                                Console.WriteLine("Sound '" + etag.Names[i] + "' - " + stag.MediaData.Length);
                            }
                            else if (ftag is DefineBitsTag)
                            {
                                DefineBitsTag btag = (DefineBitsTag)ftag;
                                Console.WriteLine("Image '" + etag.Names[i] + "' - " + btag.MediaData.Length);
                            }
                        }
                    }
                    else if (tag is DefineFontTag)
                    {
                        DefineFontTag ftag = (DefineFontTag)tag;
                        Console.WriteLine("Font '" + ftag.Name + "' - " + ftag.Data.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("-- Swf error: " + ex.Message);
            }
        }
コード例 #3
0
ファイル: SwfTagDeserializer.cs プロジェクト: shhadi/SwfLib
        SwfTagBase ISwfTagVisitor <ISwfStreamReader, SwfTagBase> .Visit(DefineFontTag tag, ISwfStreamReader reader)
        {
            tag.FontID = reader.ReadUInt16();
            var firstOffset = reader.ReadUInt16();
            var glyphsCount = firstOffset / 2;

            tag.OffsetTable.Add(firstOffset);
            for (var i = 1; i < glyphsCount; i++)
            {
                tag.OffsetTable.Add(reader.ReadUInt16());
            }

            return(tag);
        }
コード例 #4
0
        /// <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;

            case (int)TagCodeEnum.Metadata: resTag = new MetadataTag(); break;

            case (int)TagCodeEnum.SymbolClass: resTag = new SymbolClassTag(); 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)), rh.TagCode); 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);
        }
コード例 #5
0
 ITagFormatter ISwfTagVisitor <object, ITagFormatter> .Visit(DefineFontTag tag, object arg)
 {
     return(new DefineFontTagFormatter());
 }
コード例 #6
0
        private void ExploreSWF(Stream stream)
        {
            SwfExportTagReader reader = new SwfExportTagReader(stream);
            Swf swf = null;

            try
            {
                swf = reader.ReadSwf();
            }
            catch (Exception ex)
            {
                Errors.Add("Swf error: " + ex.Message);
            }
            if (swf == null)
            {
                return;
            }

            // list tags
            int currentFrame = 1;

            foreach (BaseTag tag in swf)
            {
                if (tag is ExportTag)
                {
                    ExportTag exportTag = tag as ExportTag;
                    foreach (string name in exportTag.Names)
                    {
                        if (name.StartsWith("__Packages."))
                        {
                            string cname = name.Substring(11);
                            if (!Classes.Contains(cname))
                            {
                                Classes.Add(cname + frameInfo);
                            }
                        }
                        else if (!Symbols.Contains(name))
                        {
                            Symbols.Add(name + frameInfo);
                        }
                    }
                }
                else if (tag is AbcTag)
                {
                    AbcTag abcTag = tag as AbcTag;
                    ExploreABC(abcTag.abc);
                }
                else if ((TagCodeEnum)tag.TagCode == TagCodeEnum.ShowFrame)
                {
                    currentFrame++;
                    frameInfo = " @Frame " + currentFrame;
                }
                else if (tag  is FrameTag)
                {
                    frameInfo = " @Frame " + currentFrame + ": " + (tag as FrameTag).name;
                }
                else if (tag is DefineFontTag)
                {
                    DefineFontTag ftag  = tag as DefineFontTag;
                    string        style = "";
                    if (ftag.IsBold)
                    {
                        style += "Bold ";
                    }
                    if (ftag.IsItalics)
                    {
                        style += "Italic ";
                    }
                    Fonts.Add(ftag.Name + " (" + style + ftag.GlyphCount + ")" + frameInfo);
                }
            }
        }
コード例 #7
0
        private void ExploreSWF(Stream stream)
        {
            SwfExportTagReader reader = new SwfExportTagReader(stream);
            Swf swf = null;

            try
            {
                swf = reader.ReadSwf();
            }
            catch (Exception ex)
            {
                Errors.Add("Swf error: " + ex.Message);
            }
            if (swf == null)
            {
                return;
            }

            Header = swf.Header;

            // list tags
            currentFrame = 0;
            DeclEntry frame = new DeclEntry("Frame 0");

            Frames.Add(frame);

            foreach (BaseTag tag in swf)
            {
                if (tag is ExportTag)
                {
                    ExportTag exportTag = tag as ExportTag;
                    foreach (string name in exportTag.Names)
                    {
                        if (name.StartsWith("__Packages."))
                        {
                            string cname = name.Substring(11);
                            Classes.Add(new DeclEntry(cname));
                        }
                        else
                        {
                            Symbols.Add(new DeclEntry(name));
                        }
                    }
                }
                else if (tag is DoActionTag)
                {
                    AbcSize += tag.Data.Length;
                }
                else if (tag is AbcTag)
                {
                    ExploreABC((tag as AbcTag).abc);
                    AbcSize += tag.Data.Length;
                }
                else if ((TagCodeEnum)tag.TagCode == TagCodeEnum.ShowFrame)
                {
                    currentFrame++;
                    frame = new DeclEntry("Frame " + currentFrame);
                    Frames.Add(frame);
                }
                else if (tag is FrameTag)
                {
                    frame.Name = (tag as FrameTag).name;
                }
                else if (tag is DefineFontTag)
                {
                    DefineFontTag ftag  = tag as DefineFontTag;
                    string        style = "";
                    if (ftag.IsBold)
                    {
                        style += "Bold ";
                    }
                    if (ftag.IsItalics)
                    {
                        style += "Italic ";
                    }
                    Fonts.Add(new DeclEntry(ftag.Name + " (" + style + ftag.GlyphCount + ")"));
                    FontsSize += tag.Size;
                }
                else if ((TagCodeEnum)tag.TagCode == TagCodeEnum.FileAttributes)
                {
                    ParseAttributes(tag);
                }
                else if ((TagCodeEnum)tag.TagCode == TagCodeEnum.SetBackgroundColor)
                {
                    FileAttributes.Background = (tag.Data[2] << 16 | tag.Data[3] << 8 | tag.Data[4]).ToString("X");
                    while (FileAttributes.Background.Length < 6)
                    {
                        FileAttributes.Background = "0" + FileAttributes.Background;
                    }
                    FileAttributes.Background = "#" + FileAttributes.Background;
                }

                if (tag is DoActionTag || tag is AbcTag)
                {
                    frame.AbcSize += tag.Size;
                }
                else if (tag is DefineFontTag)
                {
                    frame.FontSize += tag.Size;
                }
                else
                {
                    frame.DataSize += tag.Size;
                }
                TotalSize += tag.Size;
            }

            // empty frame at the end
            if (Frames.Count > 1 && frame.DataSize == 4)
            {
                Frames.Remove(frame);
            }
        }