A multiname, for pinpointing something within all loaded code.
Example #1
0
        internal Multiname CreateMultiname(Multiname.MultinameKind kind, string name, Namespace ns, NamespaceSet set)
        {
            Multiname mn = new Multiname(kind, name, ns, set);

            this.multinameConsts.Add(mn);
            return(mn);
        }
Example #2
0
        /// <summary>
        /// Factory method for a new timeline class.
        /// </summary>
        /// <param name="abc">The abc code to create the class within.</param>
        /// <param name="packageName">Name of the fla. You can make this up, since you probably don't have
        /// a fla.</param>
        /// <param name="className">Name of the class.</param>
        /// <returns>A bew timeline class.</returns>
        private static AS3ClassDef GenerateTimelineClass(AbcCode abc, string qClassName, SWFContext ctx)
        {
            int splitPos = qClassName.LastIndexOf('.');

            if (splitPos < 0)
            {
                throw new SWFModellerException(SWFModellerError.CodeMerge,
                                               "A generated timeline class must have a package name.",
                                               ctx.Sentinel("TimelineDefaultPackage"));
            }

            string packageName = qClassName.Substring(0, splitPos);
            string className   = qClassName.Substring(splitPos + 1);

            /* Class name: */
            Namespace flaNS = abc.CreateNamespace(Namespace.NamespaceKind.Package, packageName);
            Multiname classMultinameName = abc.CreateMultiname(Multiname.MultinameKind.QName, className, flaNS, null);

            /* Superclass: */
            Namespace nsFlashDisplay = abc.CreateNamespace(Namespace.NamespaceKind.Package, "flash.display");
            Multiname mnMovieClip    = abc.CreateMultiname(Multiname.MultinameKind.QName, "MovieClip", nsFlashDisplay, null);

            AS3ClassDef newClass = abc.CreateClass();

            newClass.Name      = classMultinameName;
            newClass.Supername = mnMovieClip;

            Namespace protectedNS = abc.CreateNamespace(Namespace.NamespaceKind.Protected, packageName + ":" + className);

            newClass.ProtectedNS = protectedNS;

            newClass.Cinit = abc.CreateMethod(className + "Constructor.abc", 1, 1, 9, 10,

                                              /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                               * I have no real ideal about how I'd work them out for myself, which would obviously be
                                               * more ideal. */

                                              /* AFAICT, this is always generated by the IDE because the abc file format
                                               * doesn't allow for classes with no static initialiser. It doesn't seem
                                               * to actually do anything. */

                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.PushScope),
                                              abc.Op(Opcode.Mnemonics.ReturnVoid));

            newClass.Iinit = abc.CreateMethod(className + "ClassInit.abc", 1, 1, 10, 11,

                                              /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                               * I have no real ideal about how I'd work them out for myself, which would obviously be
                                               * more ideal. */

                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.PushScope),
                                              abc.Op(Opcode.Mnemonics.GetLocal0),
                                              abc.Op(Opcode.Mnemonics.ConstructSuper, 0U),

                                              abc.Op(Opcode.Mnemonics.ReturnVoid));

            return(newClass);
        }
Example #3
0
        /// <summary>
        /// Factory method for a new timeline script.
        /// </summary>
        /// <param name="abc">The abc object to create the script into.</param>
        /// <param name="timelineClass">A generated timeline class. See GenerateTimelineClass</param>
        /// <returns>The new method</returns>
        private static Method GenerateTimelineScript(AbcCode abc, AS3ClassDef timelineClass)
        {
            Multiname mnMovieClip    = timelineClass.Supername;
            Namespace nsFlashDisplay = mnMovieClip.NS;

            Namespace nsEmptyPackage = abc.CreateNamespace(Namespace.NamespaceKind.Package, string.Empty);
            Namespace nsFlashEvents  = abc.CreateNamespace(Namespace.NamespaceKind.Package, "flash.events");

            Multiname mnObject                 = abc.CreateMultiname(Multiname.MultinameKind.QName, "Object", nsEmptyPackage, null);
            Multiname mnEventDispatcher        = abc.CreateMultiname(Multiname.MultinameKind.QName, "EventDispatcher", nsFlashEvents, null);
            Multiname mnDisplayObject          = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObject", nsFlashDisplay, null);
            Multiname mnInteractiveObject      = abc.CreateMultiname(Multiname.MultinameKind.QName, "InteractiveObject", nsFlashDisplay, null);
            Multiname mnDisplayObjectContainer = abc.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObjectContainer", nsFlashDisplay, null);
            Multiname mnSprite                 = abc.CreateMultiname(Multiname.MultinameKind.QName, "Sprite", nsFlashDisplay, null);

            return(abc.CreateMethod("Timeline.abc", 2, 1, 1, 9,

                                    /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                     * I have no real ideal about how I'd work them out for myself, which would obviously be
                                     * more ideal. */
                                    abc.Op(Opcode.Mnemonics.GetLocal0),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetScopeObject, (byte)0),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnEventDispatcher),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnInteractiveObject),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnDisplayObjectContainer),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnSprite),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                    abc.Op(Opcode.Mnemonics.PushScope),
                                    abc.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                    abc.Op(Opcode.Mnemonics.NewClass, timelineClass),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.PopScope),
                                    abc.Op(Opcode.Mnemonics.InitProperty, timelineClass.Name),
                                    abc.Op(Opcode.Mnemonics.ReturnVoid)));
        }
Example #4
0
        /// <summary>
        /// Generates a script that binds a class to a clip.
        /// </summary>
        /// <param name="spr">The sprite to create the class for.</param>
        public void GenerateClipClassBindingScript(Sprite spr)
        {
            Namespace nsEmptyPackage = this.CreateNamespace(Namespace.NamespaceKind.Package, string.Empty);
            Namespace nsFlashEvents  = this.CreateNamespace(Namespace.NamespaceKind.Package, "flash.events");
            Namespace nsFlashDisplay = this.CreateNamespace(Namespace.NamespaceKind.Package, "flash.display");

            Multiname mnObject                 = this.CreateMultiname(Multiname.MultinameKind.QName, "Object", nsEmptyPackage, null);
            Multiname mnEventDispatcher        = this.CreateMultiname(Multiname.MultinameKind.QName, "EventDispatcher", nsFlashEvents, null);
            Multiname mnDisplayObject          = this.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObject", nsFlashDisplay, null);
            Multiname mnInteractiveObject      = this.CreateMultiname(Multiname.MultinameKind.QName, "InteractiveObject", nsFlashDisplay, null);
            Multiname mnDisplayObjectContainer = this.CreateMultiname(Multiname.MultinameKind.QName, "DisplayObjectContainer", nsFlashDisplay, null);
            Multiname mnSprite                 = this.CreateMultiname(Multiname.MultinameKind.QName, "Sprite", nsFlashDisplay, null);
            Multiname mnMovieClip              = this.CreateMultiname(Multiname.MultinameKind.QName, "MovieClip", nsFlashDisplay, null);

            Multiname sprQName     = null;
            Multiname sprMultiname = null;

            if (spr.Class.Name.Kind == Multiname.MultinameKind.Multiname)
            {
                sprMultiname = spr.Class.Name;

                /* ISSUE 5: Convert a multiname to a QName of the form:
                 * mn QName "MyClassName"; ns Package "com.mypackage"; set *
                 */
                throw new SWFModellerException(
                          SWFModellerError.UnimplementedFeature,
                          "Unsupported sprite class name kind in class binding script generation: " + spr.Class.Name.Kind.ToString());
            }
            else if (spr.Class.Name.Kind == Multiname.MultinameKind.QName)
            {
                sprQName = spr.Class.Name;

                /* Convert to form:
                 * mn Multiname "MyClassName"; ns *; set {ns Package "com.mypackage"}
                 */
                sprMultiname = this.CreateMultiname(
                    Multiname.MultinameKind.Multiname,
                    sprQName.Name,
                    nsEmptyPackage,
                    this.CreateNamespaceSet(new Namespace[] { sprQName.NS }));
            }
            else
            {
                /* ISSUE 73 */
                throw new SWFModellerException(
                          SWFModellerError.UnimplementedFeature,
                          "Unsupported sprite class name kind in class binding script generation: " + spr.Class.Name.Kind.ToString());
            }

            Method bindingMethod = this.CreateMethod(spr.Class.Name.Name + "BindingScript.abc", 2, 1, 1, 9,

                                                     /* The above magic numbers come from the numbers generated by IDE versions of this function.
                                                      * I have no real ideal about how I'd work them out for myself, which would obviously be
                                                      * more ideal. */

                                                     /* Line */
                                                     /*  1 */ this.Op(Opcode.Mnemonics.GetLocal0),
                                                     /*  2 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /*  3 */ this.Op(Opcode.Mnemonics.FindPropStrict, sprMultiname),
                                                     /*  4 */ this.Op(Opcode.Mnemonics.GetLex, mnObject),
                                                     /*  5 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /*  6 */ this.Op(Opcode.Mnemonics.GetLex, mnEventDispatcher),
                                                     /*  7 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /*  8 */ this.Op(Opcode.Mnemonics.GetLex, mnDisplayObject),
                                                     /*  9 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /* 10 */ this.Op(Opcode.Mnemonics.GetLex, mnInteractiveObject),
                                                     /* 11 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /* 12 */ this.Op(Opcode.Mnemonics.GetLex, mnDisplayObjectContainer),
                                                     /* 13 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /* 14 */ this.Op(Opcode.Mnemonics.GetLex, mnSprite),
                                                     /* 15 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /* 16 */ this.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                                     /* 17 */ this.Op(Opcode.Mnemonics.PushScope),
                                                     /* 18 */ this.Op(Opcode.Mnemonics.GetLex, mnMovieClip),
                                                     /* 19 */ this.Op(Opcode.Mnemonics.NewClass, spr.Class),
                                                     /* 20 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 21 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 22 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 23 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 24 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 25 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 26 */ this.Op(Opcode.Mnemonics.PopScope),
                                                     /* 27 */ this.Op(Opcode.Mnemonics.InitProperty, sprQName),
                                                     /* 28 */ this.Op(Opcode.Mnemonics.ReturnVoid));

            Trait classTrait = new ClassTrait()
            {
                As3class = (AS3ClassDef)spr.Class,
                Kind     = TraitKind.Class,
                Name     = sprQName
            };

            bindingMethod.AddTrait(classTrait);

            Script bindScript = new Script()
            {
                Method = bindingMethod,
            };

            bindScript.AddTrait(classTrait);

            this.scripts.Insert(0, bindScript); /* Insert at the start to make sure any timeline script is last. */
        }
Example #5
0
 /// <summary>
 /// Adds a multiname to the code.
 /// </summary>
 /// <param name="mn">The multiname to add.</param>
 public void AddMultiname(Multiname mn)
 {
     this.multinameConsts.Add(mn);
 }
Example #6
0
        public void ToStringModelView(int nest, StringBuilder sb)
        {
            string indent = new string(' ', nest * 4);

            sb.AppendLine(indent + "Constants:");

            for (int i = 0; i < this.IntConsts.Length; i++)
            {
                sb.AppendLine(indent + "int #" + i + "\t" + this.IntConsts[i]);
            }

            for (int i = 0; i < this.UIntConsts.Length; i++)
            {
                sb.AppendLine(indent + "uint #" + i + "\t" + this.UIntConsts[i]);
            }

            for (int i = 0; i < this.DoubleConsts.Length; i++)
            {
                sb.AppendLine(indent + "double #" + i + "\t" + BitConverter.Int64BitsToDouble((long)this.DoubleConsts[i]));
            }

            for (int i = 0; i < this.StringConsts.Length; i++)
            {
                sb.AppendLine(indent + "string #" + i + "\t\"" + this.StringConsts[i] + "\"");
            }

            for (int i = 0; i < this.nsConsts.Count; i++)
            {
                sb.AppendLine(indent + "ns #" + i + "\t" + this.nsConsts[i]);
            }

            for (int i = 0; i < this.nsSetConsts.Count; i++)
            {
                sb.AppendLine(indent + "ns set #" + i + "\t(" + this.nsSetConsts[i].Count + " items)");
                foreach (Namespace ns in this.nsSetConsts[i])
                {
                    sb.AppendLine(indent + "    - " + ns);
                }
            }

            for (int i = 0; i < this.multinameConsts.Count; i++)
            {
                Multiname mn = this.multinameConsts[i];
                sb.AppendLine(indent + "multiname #" + i + "\t" + mn);
            }

            sb.AppendLine(indent + "Metadata:");

            foreach (string group in this.metadata.Keys)
            {
                Dictionary <string, string> dict = this.metadata[group];
                foreach (string k in dict.Keys)
                {
                    sb.AppendLine(group + "." + k + " = \"" + dict[k] + "\"");
                }
            }

            sb.AppendLine(indent + "End of metadata.");

            foreach (AS3ClassDef c in this.Classes)
            {
                c.ToStringModelView(nest, sb);
            }

            foreach (Script s in this.Scripts)
            {
                sb.AppendLine(indent + "Script:");
                sb.AppendLine(indent + "{");
                s.ToStringModelView(nest + 1, sb);
                sb.AppendLine(indent + "}");
            }
        }
Example #7
0
        private void RegisterMultiname(Multiname mn)
        {
            this.stringMarshal.Register(mn.Name);

            if (mn.NS != null)
            {
                this.nsMarshal.Register(mn.NS);
            }

            if (!mn.IsEmptySet)
            {
                foreach (Namespace ns in mn.Set)
                {
                    this.nsMarshal.Register(ns);
                }

                this.nsSetMarshal.Register(mn.Set);
            }

            this.multinameMarshal.Register(mn);
        }
Example #8
0
        /// <summary>
        /// Gets an ID for a multiname, ensuring that all other dependencies of the multiname
        /// are themselves registered with IDs.
        /// </summary>
        /// <param name="mn">The multiname</param>
        /// <returns>The ID of the multiname</returns>
        private int MultinameID(Multiname mn)
        {
            this.stringMarshal.Register(mn.Name);

            if (mn.NS != null)
            {
                /*(void)*/this.NamespaceID(mn.NS);
            }

            if (mn.Set != null)
            {
                /*(void)*/this.NamespaceSetID(mn.Set);
            }

            return this.multinameMarshal.GetIDFor(mn);
        }
Example #9
0
 internal void SetMultinames(Multiname[] multinames)
 {
     this.multinameConsts = new List<Multiname>();
     this.multinameConsts.Add(Multiname.GlobalMultiname);
     this.multinameConsts.AddRange(multinames);
 }
Example #10
0
 internal Multiname CreateMultiname(Multiname.MultinameKind kind, string name, Namespace ns, NamespaceSet set)
 {
     Multiname mn = new Multiname(kind, name, ns, set);
     this.multinameConsts.Add(mn);
     return mn;
 }
Example #11
0
 /// <summary>
 /// Adds a multiname to the code.
 /// </summary>
 /// <param name="mn">The multiname to add.</param>
 public void AddMultiname(Multiname mn)
 {
     this.multinameConsts.Add(mn);
 }