コード例 #1
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionPushList">ActionDefineFunction</see> from swf.
        /// including inner actions
        /// </summary>
        private ActionDefineFunction ReadActionDefineFunction(BinaryReader br)
        {
            int start = Convert.ToInt32(br.BaseStream.Position);

            // read block length
            int len = Convert.ToInt32(br.ReadUInt16());

            string name      = BinaryStringRW.ReadString(br);
            int    numParams = Convert.ToInt32(br.ReadUInt16());

            string[] parameterList = new string[numParams];
            for (int i = 0; i < numParams; i++)
            {
                parameterList[i] = BinaryStringRW.ReadString(br);
            }

            int blockSize = Convert.ToInt32(br.ReadUInt16());

            // read function body
            ArrayList            InnerActions = ReadActions(br.ReadBytes(blockSize));
            ActionDefineFunction a            = new ActionDefineFunction(name, parameterList, InnerActions);

            int end = Convert.ToInt32(br.BaseStream.Position);

            //a.ByteSize = end-start +1;

            return(a);
        }
コード例 #2
0
        /// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>
        public override void Compile(BinaryWriter w)
        {
            base.Compile(w);

            byte flags = (byte)0;

            if (catchesInReg)
            {
                flags += (byte)0x04;
            }
            if (hasFinally)
            {
                flags += (byte)0x02;
            }
            if (hasCatch)
            {
                flags += (byte)0x01;
            }

            w.Write(flags);
            w.Write(trySize);
            w.Write(catchSize);
            w.Write(finallySize);

            if (catchesInReg)
            {
                w.Write(catchReg);
            }
            else
            {
                BinaryStringRW.WriteString(w, catchVar);
            }
        }
コード例 #3
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionSetTarget">ActionSetTarget</see> from swf.
        /// </summary>
        private ActionSetTarget ReadActionSetTarget(BinaryReader br)
        {
            int len = Convert.ToInt32(br.ReadUInt16());

            ActionSetTarget a = new ActionSetTarget(BinaryStringRW.ReadString(br));

            //a.ByteSize = len+3;

            return(a);
        }
コード例 #4
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionGotoLabel">ActionGotoLabel</see> from swf.
        /// </summary>
        private ActionGotoLabel ReadActionGotoLabel(BinaryReader br)
        {
            int    len   = Convert.ToInt32(br.ReadUInt16());
            string label = BinaryStringRW.ReadString(br);

            ActionGotoLabel a = new ActionGotoLabel(label);

            //a.ByteSize = len+3;

            return(a);
        }
コード例 #5
0
        /// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>/// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>
        public override void Compile(BinaryWriter w)
        {
            base.Compile(w);
            w.Write(Convert.ToUInt16(ConstantList.Count));

            foreach (object c in ConstantList)
            {
                string stringToWrite = (string)c;
                BinaryStringRW.WriteString(w, stringToWrite);
            }
        }
コード例 #6
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionGetUrl">ActionGetUrl</see> from swf.
        /// </summary>
        private ActionGetUrl ReadActionGetUrl(BinaryReader br)
        {
            int len = Convert.ToInt32(br.ReadUInt16());

            string urlStr    = BinaryStringRW.ReadString(br);
            string targetStr = BinaryStringRW.ReadString(br);

            ActionGetUrl a = new ActionGetUrl(urlStr, targetStr);

            //a.ByteSize = len+3;

            return(a);
        }
コード例 #7
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionPushList">ActionDefineFunction2</see> from swf.
        /// including inner actions
        /// </summary>
        private ActionDefineFunction2 ReadActionDefineFunction2(BinaryReader br)
        {
            int start = Convert.ToInt32(br.BaseStream.Position);
            // read block length
            int len = Convert.ToInt32(br.ReadUInt16());

            string name      = BinaryStringRW.ReadString(br);
            int    numParams = Convert.ToInt32(br.ReadUInt16());
            int    numRegs   = Convert.ToInt32(br.ReadByte());
            byte   flags1    = br.ReadByte();
            byte   flags2    = br.ReadByte();

            ActionDefineFunction2.VariableFlagSet f
                = new ActionDefineFunction2.VariableFlagSet(
                      (flags1 & 0x80) == 0x80,
                      (flags1 & 0x40) == 0x40,
                      (flags1 & 0x20) == 0x20,
                      (flags1 & 0x10) == 0x10,
                      (flags1 & 0x08) == 0x08,
                      (flags1 & 0x04) == 0x04,
                      (flags1 & 0x02) == 0x02,
                      (flags1 & 0x01) == 0x01,
                      (flags2 & 0x01) == 0x01
                      );

            // read parameters
            ActionDefineFunction2.RegParamPair[] paramList = new ActionDefineFunction2.RegParamPair[numParams];

            for (int i = 0; i < numParams; i++)
            {
                int    r = Convert.ToInt32(br.ReadByte());
                string p = BinaryStringRW.ReadString(br);
                paramList[i] = new ActionDefineFunction2.RegParamPair(r, p);
            }
            int blockSize = Convert.ToInt32(br.ReadUInt16());

            // read function body
            ArrayList             InnerActions = ReadActions(br.ReadBytes(blockSize));
            ActionDefineFunction2 a            = new ActionDefineFunction2(name, paramList, numRegs, f, InnerActions);

            int end = Convert.ToInt32(br.BaseStream.Position);

            ////a.ByteSize = len+3+blockSize;
            //a.ByteSize = end-start+1;

            return(a);
        }
コード例 #8
0
        /// <summary>
        /// compile push type and value (but not action code), so method can
        /// be used by <see cref="SwfOp.ByteCode.Actions.ActionPushList">ActionPushList</see> as well
        /// </summary>
        public void CompileBody(BinaryWriter w)
        {
            w.Write(Convert.ToByte(Type));

            switch ((PushType)Type)
            {
            case PushType.String:
                string stringToWrite = (string)Value;
                BinaryStringRW.WriteString(w, stringToWrite);
                break;

            case PushType.Float:
                w.Write(Convert.ToSingle(Value));
                break;

            case PushType.Register:
                w.Write(Convert.ToByte(Value));
                break;

            case PushType.Boolean:
                w.Write((bool)Value);
                break;

            case PushType.Double:
                byte[] b = BitConverter.GetBytes((double)Value);
                for (int i = 0; i < 4; i++)
                {
                    byte temp = b[i];
                    b[i]     = b[4 + i];
                    b[4 + i] = temp;
                }
                w.Write(b);
                break;

            case PushType.Int:
                w.Write((int)Value);
                break;

            case PushType.Constant8:
                w.Write(Convert.ToByte(Value));
                break;

            case PushType.Constant16:
                w.Write(Convert.ToUInt16(Value));
                break;
            }
        }
コード例 #9
0
        /// <summary>
        /// Read <see cref="SwfOp.ByteCode.Actions.ActionConstantPool">constant pool</see> action from swf. the constant pool is not parsed.
        /// </summary>
        private ActionConstantPool ReadActionConstantPool(BinaryReader br)
        {
            // read block length
            int len = Convert.ToInt32(br.ReadUInt16());

            int constCount = Convert.ToInt32(br.ReadUInt16());

            string[] constantPool = new string[constCount];

            for (int i = 0; i < constCount; i++)
            {
                constantPool[i] = BinaryStringRW.ReadString(br);
            }
            ActionConstantPool a = new ActionConstantPool(constantPool);

            //a.ByteSize = len+3;
            return(a);
        }
コード例 #10
0
        /// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>
        public override void Compile(BinaryWriter w)
        {
            w.Write(Convert.ToByte(Code));
            w.Write(Convert.ToUInt16(ByteCount - innerByteCount - 3));
            BinaryStringRW.WriteString(w, Name);

            w.Write(Convert.ToUInt16(ParameterList.Length));
            foreach (string str in ParameterList)
            {
                BinaryStringRW.WriteString(w, str);
            }

            w.Write(Convert.ToUInt16(innerByteCount));
            foreach (object a in ActionRecord)
            {
                BaseAction action = (BaseAction)a;
                action.Compile(w);
            }
        }
コード例 #11
0
        /// <summary>
        /// Read try/catch block from swf and create corresponding
        /// <see cref="SwfOp.ByteCode.Actions.ActionTry">ActionTry</see>,
        /// <see cref="SwfOp.ByteCode.Actions.ActionCatch">ActionCatch</see>,
        /// <see cref="SwfOp.ByteCode.Actions.ActionFinally">ActionFinally</see>,
        /// <see cref="SwfOp.ByteCode.Actions.ActionEndTryBlock">ActionEndTryBlock</see>
        /// actions.
        /// </summary>
        private ActionTry ReadActionTry(BinaryReader br)
        {
            br.ReadUInt16();

            long startStream = br.BaseStream.Position;

            byte flags = br.ReadByte();

            bool catchInRegister = ((flags & 0x04) == 0x04);
            bool finallyFlag     = ((flags & 0x02) == 0x02);
            bool catchFlag       = ((flags & 0x01) == 0x01);

            ushort trySize     = br.ReadUInt16();
            ushort catchSize   = br.ReadUInt16();
            ushort finallySize = br.ReadUInt16();

            string catchName     = "";
            byte   catchRegister = 0;

            if (catchInRegister)
            {
                catchRegister = br.ReadByte();
            }
            else
            {
                catchName = BinaryStringRW.ReadString(br);
            }

            int len = Convert.ToInt32(br.BaseStream.Position - startStream);

            ActionTry a = new ActionTry(catchInRegister, finallyFlag, catchFlag,
                                        trySize, catchSize, finallySize,
                                        catchName, catchRegister);

            //a.ByteSize = len+3;

            return(a);
        }
コード例 #12
0
        /// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>
        public override void Compile(BinaryWriter w)
        {
            w.Write(Convert.ToByte(Code));
            w.Write(Convert.ToUInt16(ByteCount - InnerByteCount - 3));
            BinaryStringRW.WriteString(w, Name);

            w.Write(Convert.ToUInt16(ParameterList.Length));
            w.Write(Convert.ToByte(RegisterCount));
            w.Write(flags.Bytecode);

            foreach (RegParamPair rp in ParameterList)
            {
                w.Write(Convert.ToByte(rp.Register));
                BinaryStringRW.WriteString(w, rp.Parameter);
            }

            w.Write(Convert.ToUInt16(InnerByteCount));

            foreach (object a in ActionRecord)
            {
                BaseAction action = (BaseAction)a;
                action.Compile(w);
            }
        }
コード例 #13
0
        /// <summary>
        /// Read multiply push action action as <see cref="SwfOp.ByteCode.Actions.ActionPushList">ActionPushList</see> from swf.
        /// </summary>
        private ActionPushList ReadActionPush(BinaryReader br)
        {
            // read block length
            int       len      = Convert.ToInt32(br.ReadUInt16());
            int       i        = 0;
            ArrayList pushList = new ArrayList();

            while (i < len)
            {
                int pushType = Convert.ToInt32(br.ReadByte());
                i++;

                object val = new object();

                switch (pushType)
                {
                case 0: string str = BinaryStringRW.ReadString(br);
                    i  += str.Length + 1;
                    val = str;
                    break;

                case 1: val = (object)br.ReadSingle();
                    i      += 4;
                    break;

                case 2: val = null;
                    break;

                case 3: val = null;
                    break;

                case 4: val = (object)Convert.ToInt32(br.ReadByte());
                    i++;
                    break;

                case 5: val = (object )br.ReadBoolean();
                    i++;
                    break;

                case 6: byte[] b0 = br.ReadBytes(4);
                    byte[]     b1 = br.ReadBytes(4);
                    byte[]     b  = new byte[8];
                    b0.CopyTo(b, 4);
                    b1.CopyTo(b, 0);
                    val = (object)BitConverter.ToDouble(b, 0);
                    i  += 8;
                    break;

                case 7: val = (object)br.ReadInt32();
                    i      += 4;
                    break;

                case 8: val = (object)Convert.ToInt32(br.ReadByte());
                    i++;
                    break;

                case 9: val = (object)Convert.ToInt32(br.ReadUInt16());
                    i      += 2;
                    break;
                }

                ActionPush p = new ActionPush(pushType, val);
                pushList.Add(p);
            }

            ActionPush[] pList = new ActionPush[pushList.Count];
            pushList.CopyTo(pList, 0);
            ActionPushList a = new ActionPushList(pList);

            //a.ByteSize = len+3;
            return(a);
        }
コード例 #14
0
 /// <see cref="SwfOp.ByteCode.Actions.BaseAction.Compile"/>
 public override void Compile(BinaryWriter w)
 {
     base.Compile(w);
     BinaryStringRW.WriteString(w, target);
 }