Beispiel #1
0
        /// <summary>
        /// Defines the disp_id of a method in this class.
        /// </summary>
        /// <param name="method">The method of this class whose disp_id to define.</param>
        /// <param name="dispid">The disp_id for the method. This must be greater than 0.</param>
        internal void defineMethodDispId(MethodTrait method, int dispid)
        {
            if (dispid <= 0)
            {
                return;
            }

            if (!m_slotMap.tryAddMethod(dispid, method))
            {
                throw ErrorHelper.createError(ErrorCode.MARIANA__ABC_SLOT_ID_ALREADY_TAKEN, dispid, name.ToString());
            }
        }
Beispiel #2
0
            public _Method(MethodTrait def, VectorInstFromScriptClass inst)
                : base(def.name, inst, inst.applicationDomain, def.isStatic)
            {
                var defParams = def.getParameters();

                var instParams = (defParams.length == 0)
                    ? Array.Empty <MethodTraitParameter>()
                    : new MethodTraitParameter[defParams.length];

                for (int i = 0; i < instParams.Length; i++)
                {
                    var defParam      = defParams[i];
                    var instParamType = inst._substituteElement(defParam.type);
                    instParams[i] = new MethodTraitParameter(
                        defParam.name, instParamType, defParam.isOptional, defParam.hasDefault, defParam.defaultValue);
                }

                setIsOverride(def.isOverride);
                setSignature(def.hasReturn, def.hasReturn ? inst._substituteElement(def.returnType) : null, instParams, def.hasRest);
                setMetadata(def.metadata);
                setUnderlyingMethodInfo(def.underlyingMethodInfo);

                inst.m_incompleteTraitsByToken[def.underlyingMethodInfo.MetadataToken] = this;
            }
Beispiel #3
0
        /// <summary>
        /// Read in a trait, which are like object properties.
        /// </summary>
        /// <returns>A trait.</returns>
        private Trait ReadTrait()
        {
            Trait     t         = null;
            Multiname traitName = this.code.GetMultiname((int)this.abcdtr.ReadU30());
            int       traitCode = this.abcdtr.ReadUI8();
            TraitKind kind      = (TraitKind)(traitCode & 0xF);

            switch (kind)
            {
            case TraitKind.Slot:
            case TraitKind.Const:
                SlotTrait st = new SlotTrait();
                st.Name = traitName;
                st.Kind = kind;

                st.SlotID   = this.abcdtr.ReadU30();
                st.TypeName = this.code.GetMultiname((int)this.abcdtr.ReadU30());

                uint vindex = this.abcdtr.ReadU30();

                if (vindex != 0)
                {
                    st.ValKind = (ConstantKind)this.abcdtr.ReadUI8();
                    switch (st.ValKind)
                    {
                    case ConstantKind.ConInt:
                        st.Val = this.code.IntConsts[vindex];
                        break;

                    case ConstantKind.ConUInt:
                        st.Val = this.code.UIntConsts[vindex];
                        break;

                    case ConstantKind.ConDouble:
                        st.Val = this.code.DoubleConsts[vindex];
                        break;

                    case ConstantKind.ConUtf8:
                        st.Val = this.code.StringConsts[vindex];
                        break;

                    case ConstantKind.ConTrue:
                    case ConstantKind.ConFalse:
                    case ConstantKind.ConNull:
                    case ConstantKind.ConUndefined:
                        break;

                    case ConstantKind.ConNamespace:
                    case ConstantKind.ConPackageNamespace:
                    case ConstantKind.ConPackageInternalNs:
                    case ConstantKind.ConProtectedNamespace:
                    case ConstantKind.ConExplicitNamespace:
                    case ConstantKind.ConStaticProtectedNs:
                    case ConstantKind.ConPrivateNs:
                        st.Val = this.code.GetNamespace((int)vindex);
                        break;

                    default:
                        throw new SWFModellerException(
                                  SWFModellerError.Internal,
                                  "Unsupported constant kind: " + st.ValKind.ToString());
                    }
                }

                t = st;
                break;

            case TraitKind.Class:
                ClassTrait ct = new ClassTrait();
                ct.Name = traitName;
                ct.Kind = kind;

                ct.SlotID = this.abcdtr.ReadU30();
                this.LateResolutions.Add(ct, (int)this.abcdtr.ReadU30());     /* We'll resolve the class ref later. */

                t = ct;
                break;

            case TraitKind.Function:
                FunctionTrait ft = new FunctionTrait();
                ft.Name = traitName;
                ft.Kind = kind;

                ft.SlotID = this.abcdtr.ReadU30();
                ft.Fn     = this.code.GetMethod((int)this.abcdtr.ReadU30());

                t = ft;
                break;

            case TraitKind.Method:
            case TraitKind.Getter:
            case TraitKind.Setter:
            default:
                MethodTrait mt = new MethodTrait();
                mt.Name = traitName;
                mt.Kind = kind;

                uint dispID = this.abcdtr.ReadU30();
                if (dispID != 0)
                {
                    mt.OverriddenMethod = this.code.GetMethod((int)dispID);
                }

                mt.Fn = this.code.GetMethod((int)this.abcdtr.ReadU30());

                t = mt;
                break;
            }

            return(t);
        }
Beispiel #4
0
        private void WriteTraitInfo(ABCDataTypeWriter writer, Trait t)
        {
            writer.WriteU30Packed((uint)this.MultinameID(t.Name));
            writer.WriteUI8((uint)t.Kind);

            switch (t.Kind)
            {
            case TraitKind.Slot:
            case TraitKind.Const:
                SlotTrait st = (SlotTrait)t;
                writer.WriteU30Packed(st.SlotID);
                writer.WriteU30Packed((uint)this.MultinameID(st.TypeName));

                if (st.Val == null)
                {
                    writer.WriteU30Packed(0);
                }
                else
                {
                    switch (st.ValKind)
                    {
                    case ConstantKind.ConInt:
                        writer.WriteU30Packed((uint)this.intMarshal.GetIDFor((int)st.Val));
                        break;

                    case ConstantKind.ConUInt:
                        writer.WriteU30Packed((uint)this.uintMarshal.GetIDFor((uint)st.Val));
                        break;

                    case ConstantKind.ConDouble:
                        writer.WriteU30Packed((uint)this.doubleMarshal.GetIDFor((ulong)st.Val));
                        break;

                    case ConstantKind.ConUtf8:
                        writer.WriteU30Packed((uint)this.stringMarshal.GetIDFor((string)st.Val));
                        break;

                    case ConstantKind.ConTrue:
                        /* Through observation, this always gets set to 11, I do not know why. It
                         * seems though that it should be any non-zero number. */
                        writer.WriteU30Packed(11);
                        break;

                    case ConstantKind.ConFalse:
                        /* Through observation, this always gets set to 11, I do not know why. It
                         * seems though that it should be any non-zero number. */
                        writer.WriteU30Packed(10);
                        break;

                    case ConstantKind.ConNull:
                        /* Through observation, this always gets set to 11, I do not know why. It
                         * seems though that it should be any non-zero number. */
                        writer.WriteU30Packed(12);
                        break;

                    case ConstantKind.ConUndefined:
                        /* Through observation, true, false and null all seem to have ignored but
                         * specific values. I haven't seen one for undefined, but I'm guessing it's
                         * 13. Really want to know what these number are. The don't seem to relate
                         * the string or multiname tables. */
                        writer.WriteU30Packed(13);
                        break;

                    case ConstantKind.ConNamespace:
                    case ConstantKind.ConPackageNamespace:
                    case ConstantKind.ConPackageInternalNs:
                    case ConstantKind.ConProtectedNamespace:
                    case ConstantKind.ConExplicitNamespace:
                    case ConstantKind.ConStaticProtectedNs:
                    case ConstantKind.ConPrivateNs:
                        writer.WriteU30Packed((uint)this.NamespaceID((Namespace)st.Val));
                        break;

                    default:
                        throw new SWFModellerException(
                                  SWFModellerError.Internal,
                                  "Unsupported constant type: " + st.ValKind.ToString());
                    }

                    writer.WriteUI8((uint)st.ValKind);
                }

                break;

            case TraitKind.Method:
            case TraitKind.Getter:
            case TraitKind.Setter:
                MethodTrait mt = (MethodTrait)t;
                if (mt.OverriddenMethod != null)
                {
                    writer.WriteU30Packed((uint)this.methodMarshal.GetIDFor(mt.OverriddenMethod));
                }
                else
                {
                    writer.WriteU30Packed(0);
                }

                writer.WriteU30Packed((uint)this.methodMarshal.GetIDFor(mt.Fn));
                break;

            case TraitKind.Class:
                ClassTrait ct = (ClassTrait)t;
                writer.WriteU30Packed((uint)ct.SlotID);
                writer.WriteU30Packed((uint)this.classMarshal.GetIDFor(ct.As3class));
                break;

            case TraitKind.Function:
                FunctionTrait ft = (FunctionTrait)t;
                writer.WriteU30Packed((uint)ft.SlotID);
                writer.WriteU30Packed((uint)this.methodMarshal.GetIDFor(ft.Fn));
                break;

            default:
                /* ISSUE 73 */
                throw new SWFModellerException(
                          SWFModellerError.UnimplementedFeature,
                          "Unsupported trait kind: " + t.Kind.ToString());
            }
        }
Beispiel #5
0
 /// <summary>
 /// Associates a method trait with a disp_id value.
 /// </summary>
 /// <param name="dispId">The disp_id for the method. This must be greater than 0.</param>
 /// <param name="method">The method trait to associate with <paramref name="dispId"/>.</param>
 /// <returns>True if the method was successfully mapped to <paramref name="dispId"/>, false
 /// otherwise (for example, if another method already has that disp_id).</returns>
 public bool tryAddMethod(int dispId, MethodTrait method) => m_dict.TryAdd(_keyForDispId(dispId, method.isStatic), method);