public Abc() { MajorVersion = 46; MinorVersion = 16; ConstantPool = new ConstantPoolInfo(); MethodArray = new MethodInfo[0]; MetadataArray = new MetadataInfo[0]; AbcClassArray = new AbcClass[0]; ScriptArray = new ScriptInfo[0]; MethodBodyArray = new MethodBodyInfo[0]; }
public static XElement ToXml(this AbcClass cls) { var res = new XElement("class"); res.Add(cls.Instance.ToXml()); if (cls.Traits.Count > 0) { res.Add(cls.Traits.ToXml()); } return(res); }
private static void EnshureClassInitializer(AbcClass klass) { if (klass.Initializer != null) { return; } var abc = klass.Abc; var type = klass.Type; if (type != null && type.IsEnum) { if (AbcGenConfig.InitEnumFields && !AbcGenConfig.ExludeEnumConstants) { klass.Initializer = BuildEnumCinit(abc, type); } else { klass.Initializer = abc.DefineEmptyMethod(); } return; } var instance = klass.Instance; var generator = instance.Generator; if (instance.IsInterface) { klass.Initializer = abc.DefineEmptyMethod(); } else { generator.StaticCtors.EnsureStaticCtor(instance); var info = GetClassInitInfo(instance); if (info != null && info.MustDefine) { klass.Initializer = BuildClassInitializer(klass, info); } else { klass.Initializer = abc.DefineEmptyMethod(); } } if (klass.Initializer == null) { throw new InvalidOperationException(); } }
public AbcClass FindClass(TraitDescription[] insTraits, TraitDescription[] staTraits) { for (uint i = 0; i < AbcClassArray.Length; i++) { AbcClass cls = AbcClassArray[i]; bool ret = true; if (insTraits != null) { if (insTraits.Length <= cls.InstanceInfo.TraitsArray.Count) { for (int j = 0; j < insTraits.Length; j++) { if (!insTraits[j].IsMatch(cls.InstanceInfo.TraitsArray[j])) { ret = false; } } } else { ret = false; } } if (staTraits != null) { if (insTraits.Length <= cls.ClassInfo.TraitsArray.Count) { for (int j = 0; j < staTraits.Length; j++) { if (staTraits[j].IsMatch(cls.ClassInfo.TraitsArray[j])) { ret = false; } } } else { ret = false; } } if (ret) { return(cls); } } return(null); }
public void Decompile(byte[] data) { AbcStream stream = data; MinorVersion = stream.ReadShort(); MajorVersion = stream.ReadShort(); ConstantPool = stream.ReadConstantPoolInfo(); MethodArray = new MethodInfo[stream.ReadU30()]; for (uint i = 0; i < MethodArray.Length; i++) { MethodArray[i] = stream.ReadMethodInfo(ConstantPool, i); } MetadataArray = new MetadataInfo[stream.ReadU30()]; for (int i = 0; i < MetadataArray.Length; i++) { MetadataArray[i] = stream.ReadMetadataInfo(ConstantPool); } AbcClassArray = new AbcClass[stream.ReadU30()]; for (uint i = 0; i < AbcClassArray.Length; i++) { AbcClassArray[i] = new AbcClass(this, i); AbcClassArray[i].InstanceInfo = stream.ReadInstanceInfo(this, i); } for (uint i = 0; i < AbcClassArray.Length; i++) { AbcClassArray[i].ClassInfo = stream.ReadClassInfo(this, i); } ScriptArray = new ScriptInfo[stream.ReadU30()]; for (uint i = 0; i < ScriptArray.Length; i++) { ScriptArray[i] = stream.ReadScriptInfo(this, i); } MethodBodyArray = new MethodBodyInfo[stream.ReadU30()]; for (uint i = 0; i < MethodBodyArray.Length; i++) { MethodBodyArray[i] = stream.ReadMethodBodyInfo(this, i); MethodArray[MethodBodyArray[i].Method.Index].MethodBody = MethodBodyArray[i]; } }
private static AbcMethod BuildClassInitializer(AbcClass klass, InitInfo info) { var abc = klass.Abc; var generator = abc.Generator; var assetTraits = new List <AbcTrait>(); foreach (var f in info.Assets) { generator.FieldBuilder.Build(f); var t = f.Data as AbcTrait; if (t == null) { throw new InvalidOperationException(); } Debug.Assert(t.AssetInstance != null); assetTraits.Add(t); } var type = klass.Type; return(abc.DefineMethod(Sig.@global(null), code => { code.PushThisScope(); code.InitFields(type, true, false); foreach (var t in assetTraits) { code.LoadThis(); code.Getlex(t.AssetInstance.Name); code.SetProperty(t.Name); } code.ReturnVoid(); })); }
public TraitsInfo GetPropertyTrait(Abc abc, As3GetProperty as3GetProperty) { AbcClass abcClass = GetAbcClass(abc); return(abcClass.GetTraitByName(abc.ConstantPool.GetMultinameAt(as3GetProperty.Multiname.Index).MKQName.Name)); }
private string GetClassReference(AbcClass baseType) { return(baseType.Instance.Name.ToXml()); }