예제 #1
0
        public AssemblyTypeInfoGenerator(string assembly, string[] searchDirs)
        {
            ReaderParameters readerParameters = new ReaderParameters();

            readerParameters.set_AssemblyResolver(AssemblyTypeInfoGenerator.AssemblyResolver.WithSearchDirs(searchDirs));
            this.assembly_ = AssemblyDefinition.ReadAssembly(assembly, readerParameters);
        }
예제 #2
0
        public AssemblyTypeInfoGenerator(string assembly, IAssemblyResolver resolver)
        {
            ReaderParameters readerParameters = new ReaderParameters();

            readerParameters.set_AssemblyResolver(resolver);
            this.assembly_ = AssemblyDefinition.ReadAssembly(assembly, readerParameters);
        }
        public void CollectReferences(string path, bool collectMethods, float progressValue, bool ignoreSystemDlls)
        {
            this._progressValue       = progressValue;
            this._assemblyDefinitions = new HashSet <AssemblyDefinition>();
            string[] array = (!Directory.Exists(path)) ? new string[0] : Directory.GetFiles(path);
            DefaultAssemblyResolver assemblyResolver = AssemblyReferenceChecker.AssemblyResolverFor(path);

            string[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                string text = array2[i];
                if (!(Path.GetExtension(text) != ".dll"))
                {
                    string           arg_74_0         = text;
                    ReaderParameters readerParameters = new ReaderParameters();
                    readerParameters.set_AssemblyResolver(assemblyResolver);
                    AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(arg_74_0, readerParameters);
                    if (!ignoreSystemDlls || !AssemblyReferenceChecker.IsIgnoredSystemDll(assemblyDefinition.get_Name().get_Name()))
                    {
                        this._assemblyFileNames.Add(Path.GetFileName(text));
                        this._assemblyDefinitions.Add(assemblyDefinition);
                    }
                }
            }
            AssemblyDefinition[] array3 = this._assemblyDefinitions.ToArray <AssemblyDefinition>();
            this._referencedTypes = MonoAOTRegistration.BuildReferencedTypeList(array3);
            if (collectMethods)
            {
                this.CollectReferencedAndDefinedMethods(array3);
            }
        }
 public AssemblyTypeInfoGenerator(string assembly, IAssemblyResolver resolver)
 {
   string str = assembly;
   ReaderParameters readerParameters1 = new ReaderParameters();
   readerParameters1.set_AssemblyResolver(resolver);
   ReaderParameters readerParameters2 = readerParameters1;
   this.assembly_ = AssemblyDefinition.ReadAssembly(str, readerParameters2);
 }
 public AssemblyTypeInfoGenerator(string assembly, string[] searchDirs)
 {
   string str = assembly;
   ReaderParameters readerParameters1 = new ReaderParameters();
   readerParameters1.set_AssemblyResolver(AssemblyTypeInfoGenerator.AssemblyResolver.WithSearchDirs(searchDirs));
   ReaderParameters readerParameters2 = readerParameters1;
   this.assembly_ = AssemblyDefinition.ReadAssembly(str, readerParameters2);
 }
        public AssemblyTypeInfoGenerator(string assembly, IAssemblyResolver resolver)
        {
            string           str = assembly;
            ReaderParameters readerParameters1 = new ReaderParameters();

            readerParameters1.set_AssemblyResolver(resolver);
            ReaderParameters readerParameters2 = readerParameters1;

            this.assembly_ = AssemblyDefinition.ReadAssembly(str, readerParameters2);
        }
        public AssemblyTypeInfoGenerator(string assembly, string[] searchDirs)
        {
            string           str = assembly;
            ReaderParameters readerParameters1 = new ReaderParameters();

            readerParameters1.set_AssemblyResolver(AssemblyTypeInfoGenerator.AssemblyResolver.WithSearchDirs(searchDirs));
            ReaderParameters readerParameters2 = readerParameters1;

            this.assembly_ = AssemblyDefinition.ReadAssembly(str, readerParameters2);
        }
예제 #8
0
        public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray)
        {
            List <string>           list                    = new List <string>();
            List <string>           list2                   = new List <string>();
            ReaderParameters        readerParameters        = new ReaderParameters();
            DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver();

            defaultAssemblyResolver.AddSearchDirectory(Path.GetDirectoryName(path));
            readerParameters.set_AssemblyResolver(defaultAssemblyResolver);
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path, readerParameters);

            using (Collection <ModuleDefinition> .Enumerator enumerator = assemblyDefinition.get_Modules().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ModuleDefinition current = enumerator.get_Current();
                    using (Collection <TypeDefinition> .Enumerator enumerator2 = current.get_Types().GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            TypeDefinition current2 = enumerator2.get_Current();
                            TypeReference  baseType = current2.get_BaseType();
                            try
                            {
                                if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assemblyDefinition, baseType))
                                {
                                    list.Add(current2.get_Name());
                                    list2.Add(current2.get_Namespace());
                                }
                            }
                            catch (Exception)
                            {
                                UnityEngine.Debug.LogError(string.Concat(new string[]
                                {
                                    "Failed to extract ",
                                    current2.get_FullName(),
                                    " class of base type ",
                                    baseType.get_FullName(),
                                    " when inspecting ",
                                    path
                                }));
                            }
                        }
                    }
                }
            }
            classNamesArray      = list.ToArray();
            classNameSpacesArray = list2.ToArray();
        }
        public static string GenerateBlackList(string librariesFolder, RuntimeClassRegistry usedClasses, string[] allAssemblies)
        {
            string path2 = "tmplink.xml";

            usedClasses.SynchronizeClasses();
            using (TextWriter w = (TextWriter) new StreamWriter(Path.Combine(librariesFolder, path2)))
            {
                w.WriteLine("<linker>");
                w.WriteLine("<assembly fullname=\"UnityEngine\">");
                using (List <string> .Enumerator enumerator = usedClasses.GetAllManagedClassesAsString().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        string current = enumerator.Current;
                        w.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", (object)current, (object)usedClasses.GetRetentionLevel(current)));
                    }
                }
                w.WriteLine("</assembly>");
                DefaultAssemblyResolver assemblyResolver1 = new DefaultAssemblyResolver();
                ((BaseAssemblyResolver)assemblyResolver1).AddSearchDirectory(librariesFolder);
                foreach (string allAssembly in allAssemblies)
                {
                    DefaultAssemblyResolver assemblyResolver2 = assemblyResolver1;
                    string           withoutExtension         = Path.GetFileNameWithoutExtension(allAssembly);
                    ReaderParameters readerParameters1        = new ReaderParameters();
                    readerParameters1.set_AssemblyResolver((IAssemblyResolver)assemblyResolver1);
                    ReaderParameters   readerParameters2  = readerParameters1;
                    AssemblyDefinition assemblyDefinition = ((BaseAssemblyResolver)assemblyResolver2).Resolve(withoutExtension, readerParameters2);
                    w.WriteLine("<assembly fullname=\"{0}\">", (object)((AssemblyNameReference)assemblyDefinition.get_Name()).get_Name());
                    if (((AssemblyNameReference)assemblyDefinition.get_Name()).get_Name().StartsWith("UnityEngine."))
                    {
                        using (List <string> .Enumerator enumerator = usedClasses.GetAllManagedClassesAsString().GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                string current = enumerator.Current;
                                w.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", (object)current, (object)usedClasses.GetRetentionLevel(current)));
                            }
                        }
                    }
                    MonoAssemblyStripping.GenerateBlackListTypeXML(w, (IList <TypeDefinition>)assemblyDefinition.get_MainModule().get_Types(), usedClasses.GetAllManagedBaseClassesAsString());
                    w.WriteLine("</assembly>");
                }
                w.WriteLine("</linker>");
            }
            return(path2);
        }
예제 #10
0
        public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray)
        {
            List <string>           stringList1      = new List <string>();
            List <string>           stringList2      = new List <string>();
            ReaderParameters        readerParameters = new ReaderParameters();
            DefaultAssemblyResolver assemblyResolver = new DefaultAssemblyResolver();

            ((BaseAssemblyResolver)assemblyResolver).AddSearchDirectory(Path.GetDirectoryName(path));
            readerParameters.set_AssemblyResolver((IAssemblyResolver)assemblyResolver);
            AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(path, readerParameters);

            using (Collection <ModuleDefinition> .Enumerator enumerator1 = assembly.get_Modules().GetEnumerator())
            {
                // ISSUE: explicit reference operation
                while (((Collection <ModuleDefinition> .Enumerator)@enumerator1).MoveNext())
                {
                    // ISSUE: explicit reference operation
                    using (Collection <TypeDefinition> .Enumerator enumerator2 = ((Collection <ModuleDefinition> .Enumerator)@enumerator1).get_Current().get_Types().GetEnumerator())
                    {
                        // ISSUE: explicit reference operation
                        while (((Collection <TypeDefinition> .Enumerator)@enumerator2).MoveNext())
                        {
                            // ISSUE: explicit reference operation
                            TypeDefinition current  = ((Collection <TypeDefinition> .Enumerator)@enumerator2).get_Current();
                            TypeReference  baseType = current.get_BaseType();
                            try
                            {
                                if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, baseType))
                                {
                                    stringList1.Add(((TypeReference)current).get_Name());
                                    stringList2.Add(((TypeReference)current).get_Namespace());
                                }
                            }
                            catch (Exception ex)
                            {
                                UnityEngine.Debug.LogError((object)("Failed to extract " + ((TypeReference)current).get_FullName() + " class of base type " + baseType.get_FullName() + " when inspecting " + path));
                            }
                        }
                    }
                }
            }
            classNamesArray      = stringList1.ToArray();
            classNameSpacesArray = stringList2.ToArray();
        }
        public static string GenerateBlackList(string librariesFolder, RuntimeClassRegistry usedClasses, string[] allAssemblies)
        {
            string text = "tmplink.xml";

            usedClasses.SynchronizeClasses();
            using (TextWriter textWriter = new StreamWriter(Path.Combine(librariesFolder, text)))
            {
                textWriter.WriteLine("<linker>");
                textWriter.WriteLine("<assembly fullname=\"UnityEngine\">");
                foreach (string current in usedClasses.GetAllManagedClassesAsString())
                {
                    textWriter.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", current, usedClasses.GetRetentionLevel(current)));
                }
                textWriter.WriteLine("</assembly>");
                DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver();
                defaultAssemblyResolver.AddSearchDirectory(librariesFolder);
                for (int i = 0; i < allAssemblies.Length; i++)
                {
                    string path = allAssemblies[i];
                    BaseAssemblyResolver arg_CB_0     = defaultAssemblyResolver;
                    string           arg_CB_1         = Path.GetFileNameWithoutExtension(path);
                    ReaderParameters readerParameters = new ReaderParameters();
                    readerParameters.set_AssemblyResolver(defaultAssemblyResolver);
                    AssemblyDefinition assemblyDefinition = arg_CB_0.Resolve(arg_CB_1, readerParameters);
                    textWriter.WriteLine("<assembly fullname=\"{0}\">", assemblyDefinition.get_Name().get_Name());
                    if (assemblyDefinition.get_Name().get_Name().StartsWith("UnityEngine."))
                    {
                        foreach (string current2 in usedClasses.GetAllManagedClassesAsString())
                        {
                            textWriter.WriteLine(string.Format("<type fullname=\"UnityEngine.{0}\" preserve=\"{1}\"/>", current2, usedClasses.GetRetentionLevel(current2)));
                        }
                    }
                    MonoAssemblyStripping.GenerateBlackListTypeXML(textWriter, assemblyDefinition.get_MainModule().get_Types(), usedClasses.GetAllManagedBaseClassesAsString());
                    textWriter.WriteLine("</assembly>");
                }
                textWriter.WriteLine("</linker>");
            }
            return(text);
        }
        public static string GenerateLinkXmlToPreserveDerivedTypes(string stagingArea, string librariesFolder, RuntimeClassRegistry usedClasses)
        {
            string fullPath = Path.GetFullPath(Path.Combine(stagingArea, "preserved_derived_types.xml"));
            DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();

            resolver.AddSearchDirectory(librariesFolder);
            using (TextWriter textWriter = new StreamWriter(fullPath))
            {
                textWriter.WriteLine("<linker>");
                foreach (AssemblyDefinition current in MonoAssemblyStripping.CollectAssembliesRecursive((from s in usedClasses.GetUserAssemblies()
                                                                                                         where usedClasses.IsDLLUsed(s)
                                                                                                         select s).Select(delegate(string file)
                {
                    BaseAssemblyResolver arg_1F_0 = resolver;
                    string arg_1F_1 = Path.GetFileNameWithoutExtension(file);
                    ReaderParameters readerParameters = new ReaderParameters();
                    readerParameters.set_AssemblyResolver(resolver);
                    return(arg_1F_0.Resolve(arg_1F_1, readerParameters));
                })))
                {
                    if (!(current.get_Name().get_Name() == "UnityEngine"))
                    {
                        HashSet <TypeDefinition> hashSet = new HashSet <TypeDefinition>();
                        MonoAssemblyStripping.CollectBlackListTypes(hashSet, current.get_MainModule().get_Types(), usedClasses.GetAllManagedBaseClassesAsString());
                        if (hashSet.Count != 0)
                        {
                            textWriter.WriteLine("<assembly fullname=\"{0}\">", current.get_Name().get_Name());
                            foreach (TypeDefinition current2 in hashSet)
                            {
                                textWriter.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", current2.get_FullName());
                            }
                            textWriter.WriteLine("</assembly>");
                        }
                    }
                }
                textWriter.WriteLine("</linker>");
            }
            return(fullPath);
        }
        private void CollectReferencesFromRootsRecursive(string dir, IEnumerable <string> roots, bool ignoreSystemDlls)
        {
            DefaultAssemblyResolver assemblyResolver = AssemblyReferenceChecker.AssemblyResolverFor(dir);

            foreach (string current in roots)
            {
                string text = Path.Combine(dir, current);
                if (!this._assemblyFileNames.Contains(current))
                {
                    string           arg_4D_0         = text;
                    ReaderParameters readerParameters = new ReaderParameters();
                    readerParameters.set_AssemblyResolver(assemblyResolver);
                    AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(arg_4D_0, readerParameters);
                    if (!ignoreSystemDlls || !AssemblyReferenceChecker.IsIgnoredSystemDll(assemblyDefinition.get_Name().get_Name()))
                    {
                        this._assemblyFileNames.Add(current);
                        this._assemblyDefinitions.Add(assemblyDefinition);
                        using (Collection <AssemblyNameReference> .Enumerator enumerator2 = assemblyDefinition.get_MainModule().get_AssemblyReferences().GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                AssemblyNameReference current2 = enumerator2.get_Current();
                                string text2 = current2.get_Name() + ".dll";
                                if (!this._assemblyFileNames.Contains(text2))
                                {
                                    this.CollectReferencesFromRootsRecursive(dir, new string[]
                                    {
                                        text2
                                    }, ignoreSystemDlls);
                                }
                            }
                        }
                    }
                }
            }
        }