Beispiel #1
0
        XElement IActionVisitor <XElement, XElement> .Visit(ActionTry action, XElement param)
        {
            var res = new XElement(XActionNames.FromAction(action));

            if (action.Reserved != 0)
            {
                res.Add(new XAttribute("reserved", action.Reserved));
            }
            if (action.CatchInRegister)
            {
                res.Add(new XAttribute("catchReg", action.CatchRegister));
            }
            else
            {
                res.Add(new XAttribute("catchName", action.CatchName));
            }
            res.Add(XAction.ToXml(action.Try, new XElement("try")));
            if (action.CatchBlock)
            {
                res.Add(XAction.ToXml(action.Catch, new XElement("catch")));
            }
            if (action.FinallyBlock)
            {
                res.Add(XAction.ToXml(action.Finally, new XElement("finally")));
            }
            return(res);
        }
Beispiel #2
0
        ActionBase IActionVisitor <XElement, ActionBase> .Visit(ActionTry action, XElement xAction)
        {
            var xReserved  = xAction.Attribute("reserved");
            var xCatchReg  = xAction.Attribute("catchReg");
            var xCatchName = xAction.Attribute("catchName");
            var xTry       = xAction.Element("try");
            var xCatch     = xAction.Element("catch");
            var xFinally   = xAction.Element("finally");

            if (xReserved != null)
            {
                action.Reserved = byte.Parse(xReserved.Value);
            }
            if (xCatchReg != null && xCatchName == null)
            {
                action.CatchInRegister = true;
                action.CatchRegister   = byte.Parse(xCatchReg.Value);
            }
            else if (xCatchReg == null && xCatchName != null)
            {
                action.CatchInRegister = false;
                action.CatchName       = xCatchName.Value;
            }
            else if (xCatchReg != null && xCatchName != null)
            {
                throw new InvalidOperationException("catchReg and catchName are mutally exclusive");
            }
            else
            {
                throw new InvalidOperationException("Either catchReg or catchName must be specified");
            }

            XAction.FromXml(xTry, action.Try);
            if (xCatch != null)
            {
                action.CatchBlock = true;
                XAction.FromXml(xCatch, action.Catch);
            }
            if (xFinally != null)
            {
                action.FinallyBlock = true;
                XAction.FromXml(xFinally, action.Finally);
            }
            return(action);
        }
        /// <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);
        }
        /// <summary>
        /// create other pseudo actions
        /// </summary>

        private void CreatePseudoActions(ArrayList actionRecord)
        {
            for (int i = 0; i < actionRecord.Count; i++)
            {
                BaseAction a = (BaseAction)actionRecord[i];

                // -----------------------
                // try/catch/finally block
                // -----------------------

                ActionTry aTry = a as ActionTry;
                if (aTry != null)
                {
                    int j      = i + 1;
                    int offset = aTry.SizeTry;
                    // skip try block
                    while (offset > 0)
                    {
                        BaseAction currentAction = (BaseAction)actionRecord[j];
                        offset -= currentAction.ByteCount;
                        j++;
                    }
                    // skip catch
                    if (aTry.SizeCatch > 0)
                    {
                        actionRecord.Insert(j, new ActionCatch());
                        j++;
                        offset = aTry.SizeCatch;
                        while (offset > 0)
                        {
                            BaseAction currentAction = (BaseAction)actionRecord[j];
                            offset -= currentAction.ByteCount;
                            j++;
                        }
                    }
                    // skip finally
                    if (aTry.SizeFinally > 0)
                    {
                        actionRecord.Insert(j, new ActionFinally());
                        j++;
                        offset = aTry.SizeFinally;
                        while (offset > 0)
                        {
                            BaseAction currentAction = (BaseAction)actionRecord[j];
                            offset -= currentAction.ByteCount;
                            j++;
                        }
                    }
                    // end
                    actionRecord.Insert(j, new ActionEndTryBlock());
                }

                // -----------------------
                //          with
                // -----------------------

                ActionWith aWith = a as ActionWith;

                if (aWith != null)
                {
                    int j      = i + 1;
                    int offset = aWith.BlockLength;
                    while (offset > 0)
                    {
                        BaseAction currentAction = (BaseAction)actionRecord[j];
                        offset -= currentAction.ByteCount;
                        j++;
                    }
                    actionRecord.Insert(j, new ActionEndWith());
                }

                // -----------------------
                //    wait for frame
                // -----------------------

                ActionWaitForFrame aWait = a as ActionWaitForFrame;
                if (aWait != null)
                {
                    int j     = i + 1;
                    int count = aWait.SkipCount;
                    while (count > 0)
                    {
                        if (((int)((BaseAction)actionRecord[j]).Code >= 0x00) ||
                            (((BaseAction)actionRecord[j]).Code == (int)ActionCode.PushList))
                        {
                            count--;
                        }
                        j++;
                    }
                    actionRecord.Insert(j, new ActionEndWait());
                }
                ActionWaitForFrame2 aWait2 = a as ActionWaitForFrame2;
                if (aWait2 != null)
                {
                    int j     = i + 1;
                    int count = aWait2.SkipCount;
                    while (count > 0)
                    {
                        if (((int)((BaseAction)actionRecord[j]).Code >= 0x00) ||
                            (((BaseAction)actionRecord[j]).Code == (int)ActionCode.PushList))
                        {
                            count--;
                        }
                        j++;
                    }
                    actionRecord.Insert(j, new ActionEndWait());
                }
            }
        }