Beispiel #1
0
 public MultipleEnumerator(TraitContainer <T> container, uint actor)
 {
     actors     = container.actors;
     traits     = container.traits;
     this.actor = actor;
     Reset();
 }
Beispiel #2
0
 public AllEnumerator(TraitContainer <T> container)
     : this()
 {
     actors = container.actors;
     traits = container.traits;
     Reset();
 }
Beispiel #3
0
 public void SetTrait(TraitContainer trait)
 {
     this.trait     = trait;
     traitName.text = trait.trait.traitName;
     if (!trait.showInInterface)
     {
         traitName.color = Color.blue;
     }
 }
Beispiel #4
0
        protected int FindMessageReferences(ASClass asClass, TraitContainer container)
        {
            IEnumerable <MethodGetterSetterTrait> mgsTraits =
                container.FindMethodGetterSetterTraits();

            int rank = 0;
            int msgReferencesFound = 0;

            foreach (MethodGetterSetterTrait mgsTrait in mgsTraits)
            {
                msgReferencesFound +=
                    FindMessageReferences(asClass, container, mgsTrait.Method, ++rank, 0);
            }
            return(msgReferencesFound);
        }
Beispiel #5
0
        protected virtual void WriteTraitsHashData(BinaryWriter hashInput, TraitContainer traitContainer)
        {
            hashInput.Write(traitContainer.Traits.Count);
            foreach (ASTrait trait in traitContainer.Traits)
            {
                hashInput.Write((byte)trait.TraitType);
                hashInput.Write((byte)trait.Attributes);
                hashInput.Write(trait.Id);
                switch (trait.TraitType)
                {
                case TraitType.Class:
                {
                    var classTrait = (ClassTrait)trait.Data;
                    WriteClassHashData(hashInput, classTrait.Class);
                    break;
                }

                case TraitType.Method:
                case TraitType.Getter:
                case TraitType.Setter:
                {
                    var mgsTrait = (MethodGetterSetterTrait)trait.Data;
                    WriteMethodHashData(hashInput, mgsTrait.Method, true);
                    break;
                }

                case TraitType.Slot:
                case TraitType.Constant:
                {
                    var slotConstTrait = (SlotConstantTrait)trait.Data;
                    WriteValueSlotHashData(hashInput, slotConstTrait);
                    break;
                }

                case TraitType.Function:
                {
                    var funcTrait = (FunctionTrait)trait.Data;
                    WriteMethodHashData(hashInput, funcTrait.Function, true);
                    break;
                }
                }
            }
        }
Beispiel #6
0
 public AllEnumerable(TraitContainer <T> container)
 {
     this.container = container;
 }
Beispiel #7
0
 public MultipleEnumerable(TraitContainer <T> container, uint actor)
 {
     this.container = container; this.actor = actor;
 }
Beispiel #8
0
        protected int FindMessageReferences(ASClass fromClass, TraitContainer container, ASMethod fromMethod, int rank, int msgReferencesFound)
        {
            ABCFile abc = fromClass.ABC;

            using (var inCode = new FlashReader(fromMethod.Body.Bytecode))
            {
                var multinameStack = new Stack <ASMultiname>();
                while (inCode.IsDataAvailable)
                {
                    OPCode   op     = inCode.ReadOP();
                    object[] values = inCode.ReadValues(op);

                    switch (op)
                    {
                        #region Case: GetProperty
                    case OPCode.GetProperty:
                    {
                        multinameStack.Push(abc.Constants.Multinames[(int)values[0]]);
                        break;
                    }

                        #endregion
                        #region Case: NewFunction
                    case OPCode.NewFunction:
                    {
                        ASMethod newFuncMethod = abc.Methods[(int)values[0]];
                        msgReferencesFound = FindMessageReferences(fromClass, container, newFuncMethod, rank, msgReferencesFound);
                        break;
                    }

                        #endregion
                        #region Case: ConstructProp
                    case OPCode.ConstructProp:
                    {
                        ASMultiname constructPropType =
                            abc.Constants.Multinames[(int)values[0]];

                        ASClass messageClass =
                            abc.FindFirstClassByName(constructPropType.Name);

                        if (messageClass == null || !IsMessageClass(messageClass))
                        {
                            continue;
                        }

                        if (!_messageReferences.ContainsKey(messageClass))
                        {
                            _messageReferences[messageClass] = new List <ASReference>();
                        }

                        var msgReference = new ASReference(messageClass, fromClass, fromMethod);
                        if (!IsMessageOutgoing(messageClass))
                        {
                            ASMultiname topName = multinameStack.Pop();
                            msgReference.FromMethod = null;

                            IEnumerable <MethodGetterSetterTrait> mgsTraits =
                                container.FindMethodGetterSetterTraits();

                            rank = 0;     // TODO: Move this into a method or something, I'm re-writing it below as well.
                            foreach (MethodGetterSetterTrait mgsTrait in mgsTraits)
                            {
                                rank++;
                                if (mgsTrait.Method.TraitName == topName.Name)
                                {
                                    msgReference.FromMethod = mgsTrait.Method;
                                    break;
                                }
                            }
                            if (msgReference.FromMethod == null && multinameStack.Count > 0)
                            {
                                ASMultiname bottomName = multinameStack.Pop();
                                foreach (ASTrait trait in container.Traits)
                                {
                                    switch (trait.TraitType)
                                    {
                                        #region Case: Slot, Constant
                                    case TraitType.Slot:
                                    case TraitType.Constant:
                                    {
                                        if (trait.Name.Name != bottomName.Name)
                                        {
                                            continue;
                                        }

                                        var scTrait = (SlotConstantTrait)trait.Data;
                                        if (scTrait.TypeName.MultinameType != ConstantType.QName)
                                        {
                                            continue;
                                        }
                                        ASClass slotValueClass = abc.FindFirstClassByName(scTrait.TypeName.Name);

                                        rank      = 0;
                                        mgsTraits = slotValueClass.Instance.FindMethodGetterSetterTraits();
                                        foreach (MethodGetterSetterTrait mgsTrait in mgsTraits)
                                        {
                                            rank++;
                                            if (mgsTrait.Method.TraitName == topName.Name)
                                            {
                                                msgReference.FromMethod = mgsTrait.Method;
                                                break;
                                            }
                                        }

                                        if (msgReference.FromMethod != null)
                                        {
                                            msgReference.FromClass = slotValueClass;
                                        }

                                        break;
                                    }
                                        #endregion
                                    }
                                    if (msgReference.FromMethod != null)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        msgReference.Id = ((++msgReferencesFound) + rank);
                        // We can't rely on the amount of references found, since the hooking of incoming messages are randomized each revision.
                        if (!IsMessageOutgoing(messageClass))
                        {
                            msgReference.Id = rank;
                        }

                        _messageReferences[messageClass].Add(msgReference);
                        break;
                    }
                        #endregion
                    }
                }
            }
            return(msgReferencesFound);
        }
Beispiel #9
0
 protected virtual void WriteTraitsHashData(BinaryWriter hashInput, TraitContainer traitContainer)
 {
     hashInput.Write(traitContainer.Traits.Count);
     foreach (ASTrait trait in traitContainer.Traits)
     {
         hashInput.Write((byte)trait.TraitType);
         hashInput.Write((byte)trait.Attributes);
         hashInput.Write(trait.Id);
         switch (trait.TraitType)
         {
             case TraitType.Class:
             {
                 var classTrait = (ClassTrait)trait.Data;
                 WriteClassHashData(hashInput, classTrait.Class);
                 break;
             }
             case TraitType.Method:
             case TraitType.Getter:
             case TraitType.Setter:
             {
                 var mgsTrait = (MethodGetterSetterTrait)trait.Data;
                 WriteMethodHashData(hashInput, mgsTrait.Method, true);
                 break;
             }
             case TraitType.Slot:
             case TraitType.Constant:
             {
                 var slotConstTrait = (SlotConstantTrait)trait.Data;
                 WriteValueSlotHashData(hashInput, slotConstTrait);
                 break;
             }
             case TraitType.Function:
             {
                 var funcTrait = (FunctionTrait)trait.Data;
                 WriteMethodHashData(hashInput, funcTrait.Function, true);
                 break;
             }
         }
     }
 }