Пример #1
0
        public virtual byte[] GetData()
        {
            var writer = new SwfWriter();

            WriteBody(writer);
            return(writer.ToByteArray());
        }
Пример #2
0
        internal override void ToSwf(SwfWriter w)
        {
            if (this.CompressionMode == CompressionType.ZLIB)
            {
                w.AppendByte((byte)'C');
            }
            else if (this.CompressionMode == CompressionType.LZMA)
            {
                w.AppendByte((byte)'Z');
            }
            else
            {
                w.AppendByte((byte)'F');
            }
            w.AppendByte((byte)'W');
            w.AppendByte((byte)'S');

            w.AppendByte(this.Version);

            w.AppendUI32(this.FileLength);
            this.FrameSize.ToSwf(w);

            ushort frateWhole = (ushort)this.FrameRate;
            uint   frateDec   = (((uint)this.FrameRate * 0x100) & 0xFF);

            w.AppendUI16((uint)((frateWhole << 8) + frateDec));

            w.AppendUI16(this.FrameCount);
        }
Пример #3
0
        public byte[] GetData()
        {
            var writer = new SwfWriter();

            WriteData(writer);
            return(writer.ToByteArray());
        }
Пример #4
0
 protected override void WriteBody(SwfWriter writer)
 {
     if (Body != null)
     {
         writer.Write(Body);
     }
 }
Пример #5
0
        internal void ToSwf(SwfWriter w)
        {
            w.AppendBits(0, 2);
            w.AppendBit(ButtonHasBlendMode);
            w.AppendBit(ButtonHasFilterList);
            w.AppendBit(ButtonStateHitTest);
            w.AppendBit(ButtonStateDown);
            w.AppendBit(ButtonStateOver);
            w.AppendBit(ButtonStateUp);

            w.AppendUI16(CharacterID);
            w.AppendUI16(PlaceDepth);
            PlaceMatrix.ToSwf(w);

            if (containerTag == TagType.DefineButton2)
            {
                ColorTransform.ToSwf(w, true);

                if (ButtonHasFilterList)
                {
                    w.AppendByte((byte)FilterList.Count);
                    for (int i = 0; i < FilterList.Count; i++)
                    {
                        FilterList[i].ToSwf(w);
                    }
                }
                if (ButtonHasBlendMode)
                {
                    w.AppendByte((byte)BlendMode);
                }
            }
        }
Пример #6
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUIntEncoded((uint)_method.Index);
            writer.WriteUIntEncoded((uint)MaxStackDepth);
            writer.WriteUIntEncoded((uint)LocalCount);
            writer.WriteUIntEncoded((uint)MinScopeDepth);
            writer.WriteUIntEncoded((uint)MaxScopeDepth);

            if (_il != null)
            {
                using (var codeWriter = new SwfWriter())
                {
                    codeWriter.ABC = writer.ABC;
                    _il.Write(codeWriter);
                    var code = codeWriter.ToByteArray();
                    writer.WriteUIntEncoded((uint)code.Length);
                    writer.Write(code);
                }
            }
            else
            {
                writer.WriteUInt8(0);
            }

            _exceptions.Write(writer);
            _traits.Write(writer);
        }
Пример #7
0
        internal void ToSwf(SwfWriter w)
        {
            w.AppendBits(0, 2); // reserved
            w.AppendBit(IsSyncStop);
            w.AppendBit(IsSyncNoMultiple);
            w.AppendBit(HasEnvelope);
            w.AppendBit(HasLoops);
            w.AppendBit(HasOutPoint);
            w.Align();

            if (HasInPoint)
            {
                w.AppendUI32(InPoint);
            }
            if (HasOutPoint)
            {
                w.AppendUI32(OutPoint);
            }
            if (HasLoops)
            {
                w.AppendUI16(LoopCount);
            }
            if (HasEnvelope)
            {
                w.AppendByte((byte)LoopCount);
                uint count = (uint)EnvelopeRecords.Length;
                for (int i = 0; i < EnvelopeRecords.Length; i++)
                {
                    w.AppendUI32(EnvelopeRecords[i].Pos44);
                    w.AppendUI16(EnvelopeRecords[i].LeftLevel);
                    w.AppendUI16(EnvelopeRecords[i].RightLevel);
                }
            }
        }
Пример #8
0
        public void Write(SwfWriter writer)
        {
            writer.ABC = this;
            var ver = Version;

            writer.WriteUInt16((ushort)ver.Minor);
            writer.WriteUInt16((ushort)ver.Major);
            if (ver.Major == CurrentMajor && ver.Minor == CurrentMinor)
            {
                IntPool.Write(writer);
                UIntPool.Write(writer);
                DoublePool.Write(writer);
                StringPool.Write(writer);
                Namespaces.Write(writer);
                NamespaceSets.Write(writer);
                Multinames.Write(writer);

                Methods.Write(writer);
                Metadata.Write(writer);

                int n = Instances.Count;
                writer.WriteUIntEncoded((uint)n);
                Instances.Write(writer);
                Classes.Write(writer);

                Scripts.Write(writer);
                MethodBodies.Write(writer);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Пример #9
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.DefineFunction);
            w.AppendUI16(Length - 3); // don't incude def byte and len

            w.AppendString(FunctionName);
            w.AppendUI16((uint)Params.Length);
            for (int i = 0; i < Params.Length; i++)
            {
                w.AppendString(Params[i]);
            }

            w.AppendUI16(CodeSize); // temp
            long startPos = w.Position;

            for (int i = 0; i < Statements.Count; i++)
            {
                Statements[i].ToSwf(w);
            }

            // adjust code size
            long curPos = w.Position;

            if (codeSize != (curPos - startPos))
            {
                codeSize   = (uint)(curPos - startPos);
                w.Position = startPos - 2;
                w.AppendUI16(CodeSize); // acutal
                w.Position = curPos;
            }
        }
Пример #10
0
        private static byte[] GetRGB24(Bitmap bmp, bool alpha)
        {
            var writer = new SwfWriter();
            //NOTE: The RGB data must already be multiplied by the alpha channel value.
            int w = bmp.Width;
            int h = bmp.Height;

            using (var fbmp = new FastBitmap(bmp))
            {
                for (int y = 0; y < h; ++y)
                {
                    for (int x = 0; x < w; ++x)
                    {
                        var c = fbmp[x, y];
                        if (alpha)
                        {
                            c = MulAlpha(c);
                            writer.WriteARGB(c);
                        }
                        else
                        {
                            writer.WriteUInt8(0);
                            writer.WriteUInt8(c.R);
                            writer.WriteUInt8(c.G);
                            writer.WriteUInt8(c.B);
                        }
                    }
                }
            }
            return(writer.ToByteArray());
        }
Пример #11
0
 protected override void WriteBeforeClipActions(SwfWriter writer)
 {
     if ((Flags & SwfPlaceFlags.HasFilterList) != 0)
     {
         _filters.Write(writer);
     }
 }
Пример #12
0
        internal override void ToSwf(SwfWriter w, ref uint fillBits, ref uint lineBits, ShapeType shapeType)
        {
            w.AppendBit(true);
            w.AppendBit(true);
            uint bits = SwfWriter.MinimumBits(DeltaX, DeltaY);

            bits = bits < 2 ? 2 : bits; // min 2 bits

            w.AppendBits(bits - 2, 4);
            if (DeltaX != 0 && DeltaY != 0)
            {
                w.AppendBit(true);
                w.AppendSignedNBits(DeltaX, bits);
                w.AppendSignedNBits(DeltaY, bits);
            }
            else if (DeltaX == 0)
            {
                w.AppendBit(false);
                w.AppendBit(true);
                w.AppendSignedNBits(DeltaY, bits);
            }
            else
            {
                w.AppendBit(false);
                w.AppendBit(false);
                w.AppendSignedNBits(DeltaX, bits);
            }
        }
Пример #13
0
        internal void ToSwf(SwfWriter w, bool isSwf6Plus)
        {
            if ((uint)ClipEvents == 0)
            {
                if (isSwf6Plus)
                {
                    w.AppendUI32(0);
                }
                else
                {
                    w.AppendUI16(0);
                }
            }
            else
            {
                w.AppendBits((uint)ClipEvents, 32);

                uint start = (uint)w.Position;
                w.AppendUI32(0);                 // write len after tag written

                if ((ClipEvents & ClipEvents.KeyPress) > 0)
                {
                    w.AppendByte(KeyCode);
                }
                ActionRecords.ToSwf(w);

                uint end = (uint)w.Position;
                w.Position = start;
                w.AppendUI32(end - start - 4);
                w.Position = end;
            }
        }
Пример #14
0
        public override void Write(SwfWriter writer, SwfTagCode shapeType)
        {
            if (DeltaX == 0 && DeltaY == 0)
            {
                return;
            }

            writer.WriteBit(true); //edge flag
            writer.WriteBit(true); //strait flag

            if (DeltaX == 0)       //vert
            {
                WriteCoord(writer, DeltaY, true);
            }
            else if (DeltaY == 0) //horz
            {
                WriteCoord(writer, DeltaX, false);
            }
            else
            {
                int x    = DeltaX.ToTwips();
                int y    = DeltaY.ToTwips();
                int bits = _bits;
                if (!_read)
                {
                    bits = Math.Max(x.GetMinBits(y), 2);
                }
                writer.WriteUB((uint)(bits - 2), 4);
                writer.WriteBit(true); //gl
                writer.WriteSB(x, bits);
                writer.WriteSB(y, bits);
            }
        }
Пример #15
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.GoToLabel);
            w.AppendUI16(Length - 3); // don't incude def byte and len

            w.AppendString(Label);
        }
Пример #16
0
        internal override void ToSwf(SwfWriter w)
        {
            uint start = (uint)w.Position;

            w.AppendTagIDAndLength(this.TagType, 0, true);

            w.AppendBits(0, 4);
            switch (PlaybackSoundRate)
            {
            case 55000:
                w.AppendBits(0, 2);
                break;

            case 11000:
                w.AppendBits(1, 2);
                break;

            case 22000:
                w.AppendBits(2, 2);
                break;

            case 44000:
                w.AppendBits(3, 2);
                break;
            }
            w.AppendBit(PlaybackSoundSize == 16u);
            w.AppendBit(IsStereo);
            w.AppendBits((uint)StreamSoundCompression, 4);

            switch (StreamSoundRate)
            {
            case 55000:
                w.AppendBits(0, 2);
                break;

            case 11000:
                w.AppendBits(1, 2);
                break;

            case 22000:
                w.AppendBits(2, 2);
                break;

            case 44000:
                w.AppendBits(3, 2);
                break;
            }
            w.AppendBit(StreamSoundSize == 16u);
            w.AppendBit(StreamIsStereo);
            w.Align();

            w.AppendUI16(StreamSoundSampleCount);

            if (StreamSoundCompression == SoundCompressionType.MP3)
            {
                w.AppendUI16(LatencySeek);
            }

            w.ResetLongTagLength(this.TagType, start);
        }
Пример #17
0
        internal override void ToSwf(SwfWriter w)
        {
            uint start = (uint)w.Position;

            w.AppendTagIDAndLength(this.TagType, 0, true);

            w.AppendUI16(ButtonId);
            w.AppendBits(0, 7);
            w.AppendBit(TrackAsMenu);
            w.AppendUI16(ActionOffset); // todo: calc offset

            for (int i = 0; i < Characters.Count; i++)
            {
                Characters[i].ToSwf(w);
            }
            w.AppendByte(0);

            if (ActionOffset > 0)
            {
                ButtonCondActions[ButtonCondActions.Count - 1].CondActionSize = 0;
                for (int i = 0; i < ButtonCondActions.Count; i++)
                {
                    ButtonCondActions[i].ToSwf(w);
                }
            }

            w.ResetLongTagLength(this.TagType, start, true);
        }
Пример #18
0
        internal override void ToSwf(SwfWriter w, bool useAlpha)
        {
            w.AppendUI16(this.Width);
            w.AppendBits((uint)this.StartCapStyle, 2);
            w.AppendBits((uint)this.JoinStyle, 2);
            w.AppendBit(this.HasFillFlag);
            w.AppendBit(this.NoHScaleFlag);
            w.AppendBit(this.NoVScaleFlag);
            w.AppendBit(this.PixelHintingFlag);
            w.AppendBits(0, 5);
            w.AppendBit(this.NoClose);
            w.AppendBits((uint)this.EndCapStyle, 2);

            if (this.JoinStyle == JoinStyle.MiterJoin)
            {
                w.AppendFixed8_8(this.MiterLimitFactor);
            }

            if (this.HasFillFlag)
            {
                this.FillStyle.ToSwf(w);
            }
            else
            {
                w.AppendByte(Color.R);
                w.AppendByte(Color.G);
                w.AppendByte(Color.B);
                if (useAlpha)
                {
                    w.AppendByte(Color.A);
                }
            }
        }
Пример #19
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.WaitForFrame2);
            w.AppendUI16(Length - 3); // don't incude def byte and len

            w.AppendByte((byte)SkipCount);
        }
Пример #20
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUIntEncoded((uint)_name.Index);

            if (_metadata == null)
            {
                Attributes &= ~AbcTraitAttributes.HasMetadata;
            }
            else
            {
                Attributes |= AbcTraitAttributes.HasMetadata;
            }

            int kind = ((int)_kind & 0x0F) | ((int)Attributes << 4);

            writer.WriteUInt8((byte)kind);

            _slot.Write(writer);

            if (_metadata != null)
            {
                int n = _metadata.Count;
                writer.WriteUIntEncoded((uint)n);
                for (int i = 0; i < n; ++i)
                {
                    writer.WriteUIntEncoded((uint)_metadata[i].Index);
                }
            }
        }
Пример #21
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.StoreRegister);
            w.AppendUI16(Length - 3); // don't incude this part

            w.AppendByte((byte)Register);
        }
Пример #22
0
        public void Write(SwfWriter writer)
        {
            writer.WriteUIntEncoded((uint)Name.Index);

            if (BaseTypeName == null)
            {
                writer.WriteUInt8(0);
            }
            else
            {
                writer.WriteUIntEncoded((uint)BaseTypeName.Index);
            }

            writer.WriteUInt8((byte)Flags);

            if ((Flags & AbcClassFlags.ProtectedNamespace) != 0)
            {
                writer.WriteUIntEncoded((uint)ProtectedNamespace.Index);
            }

            int n = _interfaces.Count;

            writer.WriteUIntEncoded((uint)n);
            for (int i = 0; i < n; ++i)
            {
                var iface = _interfaces[i];
                writer.WriteUIntEncoded((uint)iface.Index);
            }

            writer.WriteUIntEncoded((uint)_initializer.Index);
            _traits.Write(writer);
        }
Пример #23
0
        internal override void ToSwf(SwfWriter w)
        {
            // write header
            this.Header.ToSwf(w);

            for (int i = 0; i < Tags.Count; i++)
            {
                //if (i == 0x2de)//w.Position >= 0x3cd20)//
                //{
                //    i = i;
                //}
                if (Tags[i] is PlaceObject2Tag)
                {
                    bool is6Plus = this.Header.Version > 5;
                    ((PlaceObject2Tag)Tags[i]).ToSwf(w, is6Plus);
                }
                else
                {
                    Tags[i].ToSwf(w);
                }
            }

            if (Header.IsCompressed)
            {
                w.Zip();
            }

            uint len = (uint)w.Position;

            w.Position = 4;
            w.AppendUI32(len);
            w.Position = len;
        }
Пример #24
0
 public override void WriteTagData(SwfWriter writer)
 {
     if (Data != null)
     {
         writer.Write(Data);
     }
 }
Пример #25
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.SetTarget);
            w.AppendUI16(Length - 3); // don't incude def byte and len

            w.AppendString(TargetName);
        }
Пример #26
0
        public static void WriteConstIndex(this SwfWriter writer, object value)
        {
            var c = value as IAbcConst;

            if (c != null)
            {
                writer.WriteUIntEncoded((uint)c.Index);
                writer.WriteUInt8((byte)c.Kind);
                return;
            }

            var kind = GetConstantKind(value);

            switch (kind)
            {
            case AbcConstKind.True:
            case AbcConstKind.False:
            case AbcConstKind.Null:
            case AbcConstKind.Undefined:
                writer.WriteUInt8((byte)kind);
                writer.WriteUInt8((byte)kind);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Пример #27
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)ActionKind.Jump);
            w.AppendUI16(Length - 3); // don't incude def byte and len

            w.AppendInt16(BranchOffset);
        }
Пример #28
0
        /// <summary>
        /// Gets tag data.
        /// </summary>
        /// <returns></returns>
        public virtual byte[] GetData()
        {
            var body = new SwfWriter();

            WriteTagData(body);
            return(body.ToByteArray());
        }
Пример #29
0
        internal override void ToSwf(SwfWriter w)
        {
            w.AppendByte((byte)PrimitiveType);
            byte b = (BooleanValue == true) ? (byte)0x01 : (byte)0x00;

            w.AppendByte(b);
        }
Пример #30
0
        internal override void ToSwf(SwfWriter w)
        {
            uint start = (uint)w.Position;

            w.AppendTagIDAndLength(this.TagType, 0, true);

            w.AppendUI16(CharacterID);
            Bounds.ToSwf(w);

            w.AppendBit(HasText);
            w.AppendBit(WordWrap);
            w.AppendBit(Multiline);
            w.AppendBit(Password);
            w.AppendBit(ReadOnly);
            w.AppendBit(HasTextColor);
            w.AppendBit(HasMaxLength);
            w.AppendBit(HasFont);
            w.AppendBit(false);// resreved
            w.AppendBit(AutoSize);
            w.AppendBit(HasLayout);
            w.AppendBit(NoSelect);
            w.AppendBit(Border);
            w.AppendBit(false);// resreved
            w.AppendBit(HTML);
            w.AppendBit(UseOutlines);

            if (HasFont)
            {
                w.AppendUI16(FontID);
                w.AppendUI16(FontHeight);
            }
            if (HasTextColor)
            {
                w.AppendByte((byte)TextColor.R);
                w.AppendByte((byte)TextColor.G);
                w.AppendByte((byte)TextColor.B);
                w.AppendByte((byte)TextColor.A);
            }
            if (HasMaxLength)
            {
                w.AppendUI16(MaxLength);
            }
            if (HasLayout)
            {
                w.AppendByte((byte)Align);
                w.AppendUI16(LeftMargin);
                w.AppendUI16(RightMargin);
                w.AppendUI16(Indent);
                w.AppendUI16((uint)Leading);
            }

            w.AppendString(VariableName);

            if (HasText)
            {
                w.AppendString(InitialText);
            }

            w.ResetLongTagLength(this.TagType, start, true);
        }