예제 #1
0
        internal DefineSoundTag(SwfReader r, uint tagLen)
            : base(TagType.DefineSound)
        {
            SoundId     = r.GetUI16();
            SoundFormat = (SoundCompressionType)r.GetBits(4);
            uint sr = r.GetBits(2);

            switch (sr)
            {
            case 0:
                SoundRate = 5512;                         // ?
                break;

            case 1:
                SoundRate = 11025;
                break;

            case 2:
                SoundRate = 22050;
                break;

            case 3:
                SoundRate = 44100;
                break;
            }
            SoundSize = r.GetBit() ? 16U : 8U;
            IsStereo  = r.GetBit();
            r.Align();

            SoundSampleCount = r.GetUI32();
            // todo: this needs to decompress if mp3 etc
            SoundData = r.GetBytes(tagLen - 7);
        }
예제 #2
0
        internal SoundInfo(SwfReader r)
        {
            r.GetBits(2);             // reserved

            IsSyncStop       = r.GetBit();
            IsSyncNoMultiple = r.GetBit();
            HasEnvelope      = r.GetBit();
            HasLoops         = r.GetBit();
            HasOutPoint      = r.GetBit();

            r.Align();
            if (HasInPoint)
            {
                InPoint = r.GetUI32();
            }
            if (HasOutPoint)
            {
                OutPoint = r.GetUI32();
            }
            if (HasLoops)
            {
                LoopCount = r.GetUI16();
            }
            if (HasEnvelope)
            {
                uint count = (uint)r.GetByte();

                uint pos;
                uint left;
                uint right;
                EnvelopeRecords = new SoundEnvelope[count];
                for (int i = 0; i < count; i++)
                {
                    pos   = r.GetUI32();
                    left  = r.GetUI16();
                    right = r.GetUI16();
                    EnvelopeRecords[i] = new SoundEnvelope(pos, left, right);
                }
            }
        }
예제 #3
0
 internal SwfHeader(SwfReader r)
 {
     this.CompressionMode  = CompressionType.Error;
     this.CompressionRatio = 0;
     //byte[] __signature = r.GetBytes(3);
     this.Signature = r.GetString(3);
     //Signature = r.GetString(3);
     if (Signature == "CWS")
     {
         this.CompressionMode = CompressionType.ZLIB;
         uint __oldSize = r.Size;
         r.DecompressCWSSwf();
         uint __newSize = r.Size;
         this.CompressionRatio = ((double)__oldSize / (double)__newSize) * 100;
     }
     else if (Signature == "ZWS")
     {
         this.CompressionMode = CompressionType.LZMA;
         //r.DecompressZWSSwf
         uint __oldSize = r.Size;
         r.DecompressCWSSwf();
         uint __newSize = r.Size;
         this.CompressionRatio = (double)__oldSize / (double)__newSize;
     }
     else if (Signature == "FWS")
     {
         this.CompressionMode = CompressionType.None;
     }
     if (this.CompressionMode != CompressionType.Error)
     {
         this.Version    = r.GetByte();
         this.FileLength = r.GetUI32();
         this.FrameSize  = new Rect(r);
         UInt16 __frate = r.GetUI16();
         this.FrameRate  = (__frate >> 8) + ((__frate & 0xFF) / 0xFF);
         this.FrameCount = r.GetUI16();
     }
     else
     {
         this.Version    = 0;
         this.FileLength = 0;
         this.FrameSize  = new Rect(0, 0, 0, 0);
         this.FrameRate  = 0;
         this.FrameCount = 0;
     }
 }
예제 #4
0
        internal ClipActionRecord(SwfReader r, bool isSwf6Plus)
        {
            uint highClip    = r.GetBits(16) << 16;
            uint lowClip     = 0;
            bool isEndRecord = false;

            if (highClip == 0)
            {
                if (isSwf6Plus)
                {
                    lowClip = r.GetBits(16);
                    if (lowClip == 0)
                    {
                        ClipEvents       = (ClipEvents)0;
                        ActionRecordSize = 4;
                        isEndRecord      = true;
                    }
                }
                else
                {
                    ClipEvents       = (ClipEvents)0;
                    ActionRecordSize = 2;
                    isEndRecord      = true;
                }
            }
            else
            {
                lowClip = r.GetBits(16);
            }

            if (!isEndRecord)
            {
                ClipEvents       = (ClipEvents)(lowClip | highClip);
                ActionRecordSize = r.GetUI32();
                if ((ClipEvents & ClipEvents.KeyPress) > 0)
                {
                    KeyCode = r.GetByte();
                }
                ActionRecords = new ActionRecords(r, ActionRecordSize);                 // always is init tag?
            }
        }
예제 #5
0
        // this needs to combine with the jpegTables in the swfCompilationUnit to make an image
        internal DefineBitsTag(SwfReader r, uint curTagLen, bool hasOwnTable, bool hasAlphaData)
            : base(TagType.DefineBits)
        {
            this.HasOwnTable  = hasOwnTable;
            this.HasAlphaData = hasAlphaData;

            if (hasOwnTable && !hasAlphaData)
            {
                tagType = TagType.DefineBitsJPEG2;
            }
            else if (hasOwnTable && hasAlphaData)
            {
                tagType = TagType.DefineBitsJPEG3;
            }

            CharacterId = r.GetUI16();
            if (!hasAlphaData)
            {
                if (!hasOwnTable)
                {
                    r.GetBytes(2);                 // SOI
                    JpegData = r.GetBytes(curTagLen - 6);
                    r.GetBytes(2);                 // EOI
                }
                else
                {
                    JpegData = r.GetBytes(curTagLen - 2);
                    CleanData();
                }
            }
            else
            {
                uint jpgDataSize = r.GetUI32();
                JpegData = r.GetBytes(jpgDataSize);

                // ignore alpha for now
                CompressedAlphaData = r.GetBytes(curTagLen - 6 - jpgDataSize);
                CleanData();
            }
        }
예제 #6
0
        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;
                }
            }
        }
예제 #7
0
        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));
                }
            }
        }
예제 #8
0
        internal DefineFont2_3(SwfReader r, bool isHighRes)
            : base(TagType.DefineFont2)
        {
            this.IsHighRes = isHighRes; // true;
            if (isHighRes)
            {
                this.tagType = TagType.DefineFont3;
            }
            this.FontId               = r.GetUI16();
            this.FontFlagsHasLayout   = r.GetBit();
            this.FontFlagsShiftJIS    = r.GetBit();
            this.FontFlagsSmallText   = r.GetBit();
            this.FontFlagsANSI        = r.GetBit();
            this.FontFlagsWideOffsets = r.GetBit();
            this.FontFlagsWideCodes   = r.GetBit();
            this.FontFlagsItalic      = r.GetBit();
            this.FontFlagsBold        = r.GetBit();

            r.Align();

            this.LanguageCode = (uint)r.GetByte();
            uint fontNameLen = (uint)r.GetByte();

            this.FontName  = r.GetString(fontNameLen);
            this.NumGlyphs = r.GetUI16();

            this.OffsetTable = new uint[this.NumGlyphs];
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                this.OffsetTable[i] = this.FontFlagsWideOffsets ? r.GetUI32() : r.GetUI16();
            }

            this.CodeTableOffset = this.FontFlagsWideOffsets ? r.GetUI32() : r.GetUI16();

            GlyphShapeTable = new List <Shape>();
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                Shape s = new Shape(r);
                GlyphShapeTable.Add(s);
            }

            this.CodeTable = new uint[this.NumGlyphs];
            for (int i = 0; i < this.NumGlyphs; i++)
            {
                this.CodeTable[i] = r.GetUI16();
            }

            if (this.FontFlagsHasLayout)
            {
                this.FontAscent  = r.GetInt16();
                this.FontDescent = r.GetInt16();
                this.FontLeading = r.GetInt16();

                this.FontAdvanceTable = new int[this.NumGlyphs];
                for (int i = 0; i < this.NumGlyphs; i++)
                {
                    this.FontAdvanceTable[i] = r.GetInt16();
                }

                this.FontBoundsTable = new Rect[this.NumGlyphs];
                for (int i = 0; i < this.NumGlyphs; i++)
                {
                    this.FontBoundsTable[i] = new Rect(r);
                }

                this.KerningCount = r.GetUI16();

                this.FontKerningTable = new KerningRecord[this.KerningCount];
                if (this.FontFlagsWideCodes)
                {
                    for (int i = 0; i < this.KerningCount; i++)
                    {
                        this.FontKerningTable[i] = new KerningRecord(r.GetUI16(), r.GetUI16(), r.GetInt16());
                    }
                }
                else
                {
                    for (int i = 0; i < this.KerningCount; i++)
                    {
                        this.FontKerningTable[i] = new KerningRecord((uint)r.GetByte(), (uint)r.GetByte(), r.GetInt16());
                    }
                }
            }
        }
예제 #9
0
 internal FileAttributesTag(SwfReader r)
     : base(TagType.FileAttributes)
 {
     this._flags = r.GetUI32();
 }