Exemple #1
0
        public static AbcFile From(AbcFileInfo fileInfo)
        {
            var res = new AbcFile {
                MajorVersion = fileInfo.MajorVersion,
                MinorVersion = fileInfo.MinorVersion
            };

            var loader = new AbcFileLoader(fileInfo);

            loader.SaveTo(res);

            return(res);
        }
Exemple #2
0
        public static XElement ToXml(AbcFileInfo abcInfo)
        {
            var abc = AbcFile.From(abcInfo);
            var res = new XElement(TAG_NAME,
                                   new XAttribute("minorVersion", abc.MinorVersion),
                                   new XAttribute("majorVersion", abc.MajorVersion)
                                   );

            if (abc.Classes.Count > 0)
            {
                var xClasses = new XElement("classes");
                foreach (var cls in abc.Classes)
                {
                    xClasses.Add(cls.ToXml());
                }
                res.Add(xClasses);
            }

            if (abc.Scripts.Count > 0)
            {
                var xScripts = new XElement("scripts");
                foreach (var script in abc.Scripts)
                {
                    xScripts.Add(ToXml(script));
                }
                res.Add(xScripts);
            }

            if (abc.Methods.Count > 0)
            {
                var xMethods = new XElement("methods");
                foreach (var method in abc.Methods)
                {
                    xMethods.Add(method.ToXml());
                }
                res.Add(xMethods);
            }

            return(res);
        }
Exemple #3
0
        public AbcFileLoader(AbcFileInfo fileInfo)
        {
            FileInfo = fileInfo;

            ReadConstants();

            for (var i = 0; i < fileInfo.Classes.Length; i++)
            {
                Classes.Add(new AbcClass());
            }

            for (var i = 0; i < fileInfo.Scripts.Length; i++)
            {
                Scripts.Add(new AbcScript());
            }

            foreach (var metaInfo in fileInfo.Metadata)
            {
                _metadata.Add(ReadMetadata(metaInfo));
            }

            foreach (var methodInfo in fileInfo.Methods)
            {
                var method = new AbcMethod {
                    Name           = fileInfo.ConstantPool.Strings[methodInfo.Name],
                    ReturnType     = GetMultiname(methodInfo.ReturnType, AbcMultiname.Void),
                    NeedArguments  = methodInfo.NeedArguments,
                    NeedActivation = methodInfo.NeedActivation,
                    NeedRest       = methodInfo.NeedRest,
                    SetDxns        = methodInfo.SetDxns,
                    IgnoreRest     = methodInfo.IgnoreRest,
                    Native         = methodInfo.Native,
                };
                for (var paramIndex = 0; paramIndex < methodInfo.ParamTypes.Length; paramIndex++)
                {
                    var paramInfo = methodInfo.ParamTypes[paramIndex];
                    method.Params.Add(new AbcMethodParam {
                        Type = GetMultiname(paramInfo, AbcMultiname.Any),
                        Name = methodInfo.HasParamNames ? fileInfo.ConstantPool.Strings[methodInfo.ParamNames[paramIndex].ParamName] : null
                    });
                }
                if (methodInfo.HasOptional)
                {
                    var paramShift = methodInfo.ParamTypes.Length - methodInfo.Options.Length;
                    for (var i = 0; i < methodInfo.ParamTypes.Length; i++)
                    {
                        var defaultIndex = i - paramShift;
                        if (defaultIndex >= 0)
                        {
                            var param  = method.Params[i];
                            var option = methodInfo.Options[defaultIndex];
                            param.Default = GetConstantValue(option.Kind, option.Value);
                        }
                    }
                }
                Methods.Add(method);
            }
            LoadClassInstances();
            LoadMethodBodies();
            LoadClassInitializers();
            LoadScriptInitializers();
            LoadTraits();
        }