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; }
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(); }
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; }
public AbcFileInfo ReadAbcFile() { try { var res = new AbcFileInfo { MinorVersion = ReadU16(), MajorVersion = ReadU16(), ConstantPool = ReadConstantPool(), Methods = ReadMultipleMethods(), Metadata = ReadMutipleMetadata(), }; var classCount = ReadU30(); res.Instances = ReadMutipleInstances(classCount); res.Classes = ReadMultipleClasses(classCount); res.Scripts = ReadMultipleScripts(); res.Bodies = ReadMultipleBodies(); return res; } catch (Exception e) { throw new Exception(string.Format("Error at {0} ({0:x}):", Position), e); } }
public AbcFileInfo ReadAbcFile() { try { var res = new AbcFileInfo { MinorVersion = ReadU16(), MajorVersion = ReadU16(), ConstantPool = ReadConstantPool(), Methods = ReadMultipleMethods(), Metadata = ReadMutipleMetadata(), }; var classCount = ReadU30(); res.Instances = ReadMutipleInstances(classCount); res.Classes = ReadMultipleClasses(classCount); res.Scripts = ReadMultipleScripts(); res.Bodies = ReadMultipleBodies(); return(res); } catch (Exception e) { throw new Exception(string.Format("Error at {0} ({0:x}):", Position), e); } }
public void WriteAbcFile(AbcFileInfo abc) { WriteU16(abc.MinorVersion); WriteU16(abc.MajorVersion); WriteConstantPool(abc.ConstantPool); WriteMultipleMethods(abc.Methods); WriteMultipleMetadata(abc.Metadata); if (abc.Classes.Length != abc.Instances.Length) { throw new Exception("Number of Classes and Instances differs"); } var classCount = abc.Classes.Length; WriteU30((uint)classCount); WriteMultipleInstances(abc.Instances); WriteMultipleClasses(abc.Classes); WriteMultipleScripts(abc.Scripts); WriteMultipleBodies(abc.Bodies); }
public void WriteAbcFile(AbcFileInfo abc) { WriteU16(abc.MinorVersion); WriteU16(abc.MajorVersion); WriteConstantPool(abc.ConstantPool); WriteMultipleMethods(abc.Methods); WriteMultipleMetadata(abc.Metadata); if (abc.Classes.Count != abc.Instances.Count) { throw new Exception("Number of Classes and Instances differs"); } var classCount = abc.Classes.Count; WriteU30((uint)classCount); WriteMultipleInstances(abc.Instances); WriteMultipleClasses(abc.Classes); WriteMultipleScripts(abc.Scripts); WriteMultipleBodies(abc.Bodies); }