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];
                    AssemblyDefinition assemblyDefinition = defaultAssemblyResolver.Resolve(Path.GetFileNameWithoutExtension(path), new ReaderParameters
                    {
                        AssemblyResolver = defaultAssemblyResolver
                    });
                    textWriter.WriteLine("<assembly fullname=\"{0}\">", assemblyDefinition.Name.Name);
                    MonoAssemblyStripping.GenerateBlackListTypeXML(textWriter, assemblyDefinition.MainModule.Types, usedClasses.GetAllManagedBaseClassesAsString());
                    textWriter.WriteLine("</assembly>");
                }
                textWriter.WriteLine("</linker>");
            }
            return(text);
        }
 private static void CollectBlackListTypes(HashSet <TypeDefinition> typesToPreserve, IList <TypeDefinition> types, List <string> baseTypes)
 {
     if (types == null)
     {
         return;
     }
     using (IEnumerator <TypeDefinition> enumerator1 = ((IEnumerable <TypeDefinition>)types).GetEnumerator())
     {
         while (((IEnumerator)enumerator1).MoveNext())
         {
             TypeDefinition current1 = enumerator1.Current;
             if (current1 != null)
             {
                 using (List <string> .Enumerator enumerator2 = baseTypes.GetEnumerator())
                 {
                     while (enumerator2.MoveNext())
                     {
                         string current2 = enumerator2.Current;
                         if (MonoAssemblyStripping.DoesTypeEnheritFrom((TypeReference)current1, current2))
                         {
                             typesToPreserve.Add(current1);
                             break;
                         }
                     }
                 }
                 MonoAssemblyStripping.CollectBlackListTypes(typesToPreserve, (IList <TypeDefinition>)current1.get_NestedTypes(), baseTypes);
             }
         }
     }
 }
        public static void MonoCilStrip(BuildTarget buildTarget, string managedLibrariesDirectory, string[] fileNames)
        {
            string buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget);
            string str = Path.Combine(buildToolsDirectory, "mono-cil-strip.exe");

            for (int i = 0; i < fileNames.Length; i++)
            {
                string  text    = fileNames[i];
                Process process = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
                string  text2   = text + ".out";
                process.StartInfo.Arguments = "\"" + str + "\"";
                ProcessStartInfo expr_5B   = process.StartInfo;
                string           arguments = expr_5B.Arguments;
                expr_5B.Arguments = string.Concat(new string[]
                {
                    arguments,
                    " \"",
                    text,
                    "\" \"",
                    text,
                    ".out\""
                });
                MonoProcessUtility.RunMonoProcess(process, "byte code stripper", Path.Combine(managedLibrariesDirectory, text2));
                MonoAssemblyStripping.ReplaceFile(managedLibrariesDirectory + "/" + text2, managedLibrariesDirectory + "/" + text);
                File.Delete(managedLibrariesDirectory + "/" + text2);
            }
        }
        private static void GenerateBlackListTypeXML(TextWriter w, IList <TypeDefinition> types, List <string> baseTypes)
        {
            HashSet <TypeDefinition> hashSet = new HashSet <TypeDefinition>();

            MonoAssemblyStripping.CollectBlackListTypes(hashSet, types, baseTypes);
            foreach (TypeDefinition current in hashSet)
            {
                w.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", current.FullName);
            }
        }
        private static void GenerateBlackListTypeXML(TextWriter w, IList <TypeDefinition> types, List <string> baseTypes)
        {
            HashSet <TypeDefinition> typesToPreserve = new HashSet <TypeDefinition>();

            MonoAssemblyStripping.CollectBlackListTypes(typesToPreserve, types, baseTypes);
            using (HashSet <TypeDefinition> .Enumerator enumerator = typesToPreserve.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    TypeDefinition current = enumerator.Current;
                    w.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", (object)((TypeReference)current).get_FullName());
                }
            }
        }
        public static string GenerateLinkXmlToPreserveDerivedTypes(string stagingArea, string librariesFolder, RuntimeClassRegistry usedClasses)
        {
            // ISSUE: object of a compiler-generated type is created
            // ISSUE: variable of a compiler-generated type
            MonoAssemblyStripping.\u003CGenerateLinkXmlToPreserveDerivedTypes\u003Ec__AnonStorey6C typesCAnonStorey6C = new MonoAssemblyStripping.\u003CGenerateLinkXmlToPreserveDerivedTypes\u003Ec__AnonStorey6C();
            // ISSUE: reference to a compiler-generated field
            typesCAnonStorey6C.usedClasses = usedClasses;
            string fullPath = Path.GetFullPath(Path.Combine(stagingArea, "preserved_derived_types.xml"));

            // ISSUE: reference to a compiler-generated field
            typesCAnonStorey6C.resolver = new DefaultAssemblyResolver();
            // ISSUE: reference to a compiler-generated field
            ((BaseAssemblyResolver)typesCAnonStorey6C.resolver).AddSearchDirectory(librariesFolder);
            using (TextWriter textWriter = (TextWriter) new StreamWriter(fullPath))
            {
                textWriter.WriteLine("<linker>");
                // ISSUE: reference to a compiler-generated field
                // ISSUE: reference to a compiler-generated method
                // ISSUE: reference to a compiler-generated method
                using (HashSet <AssemblyDefinition> .Enumerator enumerator1 = MonoAssemblyStripping.CollectAssembliesRecursive(((IEnumerable <string>)typesCAnonStorey6C.usedClasses.GetUserAssemblies()).Where <string>(new Func <string, bool>(typesCAnonStorey6C.\u003C\u003Em__EC)).Select <string, AssemblyDefinition>(new Func <string, AssemblyDefinition>(typesCAnonStorey6C.\u003C\u003Em__ED))).GetEnumerator())
                {
                    while (enumerator1.MoveNext())
                    {
                        AssemblyDefinition current1 = enumerator1.Current;
                        if (!(((AssemblyNameReference)current1.get_Name()).get_Name() == "UnityEngine"))
                        {
                            HashSet <TypeDefinition> typesToPreserve = new HashSet <TypeDefinition>();
                            // ISSUE: reference to a compiler-generated field
                            MonoAssemblyStripping.CollectBlackListTypes(typesToPreserve, (IList <TypeDefinition>)current1.get_MainModule().get_Types(), typesCAnonStorey6C.usedClasses.GetAllManagedBaseClassesAsString());
                            if (typesToPreserve.Count != 0)
                            {
                                textWriter.WriteLine("<assembly fullname=\"{0}\">", (object)((AssemblyNameReference)current1.get_Name()).get_Name());
                                using (HashSet <TypeDefinition> .Enumerator enumerator2 = typesToPreserve.GetEnumerator())
                                {
                                    while (enumerator2.MoveNext())
                                    {
                                        TypeDefinition current2 = enumerator2.Current;
                                        textWriter.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", (object)((TypeReference)current2).get_FullName());
                                    }
                                }
                                textWriter.WriteLine("</assembly>");
                            }
                        }
                    }
                }
                textWriter.WriteLine("</linker>");
            }
            return(fullPath);
        }
        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);
        }
        public static IEnumerable <AssemblyDefinition> CollectAllAssemblies(string librariesFolder, RuntimeClassRegistry usedClasses)
        {
            DefaultAssemblyResolver resolver = new DefaultAssemblyResolver();

            resolver.RemoveSearchDirectory(".");
            resolver.RemoveSearchDirectory("bin");
            resolver.AddSearchDirectory(librariesFolder);
            IEnumerable <AssemblyNameReference> source = from s in usedClasses.GetUserAssemblies()
                                                         where usedClasses.IsDLLUsed(s)
                                                         select s into file
                                                         select AssemblyNameReference.Parse(Path.GetFileNameWithoutExtension(file));

            return(MonoAssemblyStripping.CollectAssembliesRecursive(from dll in source
                                                                    select MonoAssemblyStripping.ResolveAssemblyReference(resolver, dll) into a
                                                                    where a != null
                                                                    select a));
        }
        public static void MonoCilStrip(BuildTarget buildTarget, string managedLibrariesDirectory, string[] fileNames)
        {
            string str1 = Path.Combine(BuildPipeline.GetBuildToolsDirectory(buildTarget), "mono-cil-strip.exe");

            foreach (string fileName in fileNames)
            {
                Process process = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
                string  path2   = fileName + ".out";
                process.StartInfo.Arguments = "\"" + str1 + "\"";
                ProcessStartInfo startInfo = process.StartInfo;
                string           str2      = startInfo.Arguments + " \"" + fileName + "\" \"" + fileName + ".out\"";
                startInfo.Arguments = str2;
                MonoProcessUtility.RunMonoProcess(process, "byte code stripper", Path.Combine(managedLibrariesDirectory, path2));
                MonoAssemblyStripping.ReplaceFile(managedLibrariesDirectory + "/" + path2, managedLibrariesDirectory + "/" + fileName);
                File.Delete(managedLibrariesDirectory + "/" + path2);
            }
        }
Пример #10
0
 private static void CollectBlackListTypes(HashSet <TypeDefinition> typesToPreserve, IList <TypeDefinition> types, List <string> baseTypes)
 {
     if (types != null)
     {
         foreach (TypeDefinition current in types)
         {
             if (current != null)
             {
                 foreach (string current2 in baseTypes)
                 {
                     if (MonoAssemblyStripping.DoesTypeEnheritFrom(current, current2))
                     {
                         typesToPreserve.Add(current);
                         break;
                     }
                 }
                 MonoAssemblyStripping.CollectBlackListTypes(typesToPreserve, current.NestedTypes, baseTypes);
             }
         }
     }
 }
Пример #11
0
 private static void GenerateBlackListTypeXML(TextWriter w, IList <TypeDefinition> types, List <string> baseTypes)
 {
     if (types == null)
     {
         return;
     }
     foreach (TypeDefinition current in types)
     {
         if (current != null)
         {
             foreach (string current2 in baseTypes)
             {
                 if (MonoAssemblyStripping.DoesTypeEnheritFrom(current, current2))
                 {
                     w.WriteLine("<type fullname=\"{0}\" preserve=\"all\"/>", current.FullName);
                     break;
                 }
             }
             MonoAssemblyStripping.GenerateBlackListTypeXML(w, current.NestedTypes, baseTypes);
         }
     }
 }
        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);
        }
Пример #13
0
 public static IEnumerable <AssemblyDefinition> ResolveAssemblyReferences(AssemblyDefinition assembly)
 {
     return(MonoAssemblyStripping.ResolveAssemblyReferences(assembly.MainModule.AssemblyResolver, assembly.MainModule.AssemblyReferences));
 }
Пример #14
0
        private static HashSet <AssemblyDefinition> CollectAssembliesRecursive(IEnumerable <AssemblyDefinition> assemblies)
        {
            HashSet <AssemblyDefinition> hashSet = new HashSet <AssemblyDefinition>(assemblies, new MonoAssemblyStripping.AssemblyDefinitionComparer());
            int num = 0;

            while (hashSet.Count > num)
            {
                num = hashSet.Count;
                hashSet.UnionWith(hashSet.ToArray <AssemblyDefinition>().SelectMany((AssemblyDefinition a) => MonoAssemblyStripping.ResolveAssemblyReferences(a)));
            }
            return(hashSet);
        }
Пример #15
0
        public static void MonoLink(BuildTarget buildTarget, string managedLibrariesDirectory, string[] input, string[] allAssemblies, RuntimeClassRegistry usedClasses)
        {
            Process process             = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
            string  buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget);
            string  text             = null;
            string  frameWorksFolder = MonoInstallationFinder.GetFrameWorksFolder();
            string  text2            = Path.Combine(frameWorksFolder, MonoAssemblyStripping.StripperExe());
            string  text3            = Path.Combine(Path.GetDirectoryName(text2), "link.xml");
            string  text4            = Path.Combine(managedLibrariesDirectory, "output");

            Directory.CreateDirectory(text4);
            process.StartInfo.Arguments = "\"" + text2 + "\" -l none -c link";
            for (int i = 0; i < input.Length; i++)
            {
                string           str     = input[i];
                ProcessStartInfo expr_80 = process.StartInfo;
                expr_80.Arguments = expr_80.Arguments + " -a \"" + str + "\"";
            }
            ProcessStartInfo expr_B3   = process.StartInfo;
            string           arguments = expr_B3.Arguments;

            expr_B3.Arguments = string.Concat(new string[]
            {
                arguments,
                " -out output -x \"",
                text3,
                "\" -d \"",
                managedLibrariesDirectory,
                "\""
            });
            string text5 = Path.Combine(buildToolsDirectory, "link.xml");

            if (File.Exists(text5))
            {
                ProcessStartInfo expr_110 = process.StartInfo;
                expr_110.Arguments = expr_110.Arguments + " -x \"" + text5 + "\"";
            }
            string text6 = Path.Combine(Path.GetDirectoryName(text2), "Core.xml");

            if (File.Exists(text6))
            {
                ProcessStartInfo expr_151 = process.StartInfo;
                expr_151.Arguments = expr_151.Arguments + " -x \"" + text6 + "\"";
            }
            string[] files = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "link.xml", SearchOption.AllDirectories);
            string[] array = files;
            for (int j = 0; j < array.Length; j++)
            {
                string           str2     = array[j];
                ProcessStartInfo expr_1A2 = process.StartInfo;
                expr_1A2.Arguments = expr_1A2.Arguments + " -x \"" + str2 + "\"";
            }
            if (usedClasses != null)
            {
                text = MonoAssemblyStripping.GenerateBlackList(managedLibrariesDirectory, usedClasses, allAssemblies);
                ProcessStartInfo expr_1E6 = process.StartInfo;
                expr_1E6.Arguments = expr_1E6.Arguments + " -x \"" + text + "\"";
            }
            MonoProcessUtility.RunMonoProcess(process, "assemblies stripper", Path.Combine(text4, "mscorlib.dll"));
            MonoAssemblyStripping.DeleteAllDllsFrom(managedLibrariesDirectory);
            MonoAssemblyStripping.CopyAllDlls(managedLibrariesDirectory, text4);
            string[] files2 = Directory.GetFiles(managedLibrariesDirectory);
            for (int k = 0; k < files2.Length; k++)
            {
                string text7 = files2[k];
                if (text7.Contains(".mdb"))
                {
                    string path = text7.Replace(".mdb", string.Empty);
                    if (!File.Exists(path))
                    {
                        FileUtil.DeleteFileOrDirectory(text7);
                    }
                }
            }
            if (text != null)
            {
                FileUtil.DeleteFileOrDirectory(Path.Combine(managedLibrariesDirectory, text));
            }
            FileUtil.DeleteFileOrDirectory(text4);
        }
        public static void MonoLink(BuildTarget buildTarget, string managedLibrariesDirectory, string[] input, string[] allAssemblies, RuntimeClassRegistry usedClasses)
        {
            Process process             = MonoProcessUtility.PrepareMonoProcess(buildTarget, managedLibrariesDirectory);
            string  buildToolsDirectory = BuildPipeline.GetBuildToolsDirectory(buildTarget);
            string  path2 = (string)null;
            string  path1 = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), MonoAssemblyStripping.StripperExe());
            string  str1  = Path.Combine(Path.GetDirectoryName(path1), "link.xml");
            string  str2  = Path.Combine(managedLibrariesDirectory, "output");

            Directory.CreateDirectory(str2);
            process.StartInfo.Arguments = "\"" + path1 + "\" -l none -c link";
            foreach (string str3 in input)
            {
                ProcessStartInfo startInfo = process.StartInfo;
                string           str4      = startInfo.Arguments + " -a \"" + str3 + "\"";
                startInfo.Arguments = str4;
            }
            ProcessStartInfo startInfo1 = process.StartInfo;
            string           str5       = startInfo1.Arguments + " -out output -x \"" + str1 + "\" -d \"" + managedLibrariesDirectory + "\"";

            startInfo1.Arguments = str5;
            string path3 = Path.Combine(buildToolsDirectory, "link.xml");

            if (File.Exists(path3))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path3 + "\"";
                startInfo2.Arguments = str3;
            }
            string path4 = Path.Combine(Path.GetDirectoryName(path1), "Core.xml");

            if (File.Exists(path4))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path4 + "\"";
                startInfo2.Arguments = str3;
            }
            foreach (string file in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Assets"), "link.xml", SearchOption.AllDirectories))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + file + "\"";
                startInfo2.Arguments = str3;
            }
            if (usedClasses != null)
            {
                path2 = MonoAssemblyStripping.GenerateBlackList(managedLibrariesDirectory, usedClasses, allAssemblies);
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + path2 + "\"";
                startInfo2.Arguments = str3;
            }
            foreach (string file in Directory.GetFiles(Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(EditorUserBuildSettings.activeBuildTarget, BuildOptions.None), "Whitelists"), "*.xml"))
            {
                ProcessStartInfo startInfo2 = process.StartInfo;
                string           str3       = startInfo2.Arguments + " -x \"" + file + "\"";
                startInfo2.Arguments = str3;
            }
            MonoProcessUtility.RunMonoProcess(process, "assemblies stripper", Path.Combine(str2, "mscorlib.dll"));
            MonoAssemblyStripping.DeleteAllDllsFrom(managedLibrariesDirectory);
            MonoAssemblyStripping.CopyAllDlls(managedLibrariesDirectory, str2);
            foreach (string file in Directory.GetFiles(managedLibrariesDirectory))
            {
                if (file.Contains(".mdb") && !File.Exists(file.Replace(".mdb", string.Empty)))
                {
                    FileUtil.DeleteFileOrDirectory(file);
                }
            }
            if (path2 != null)
            {
                FileUtil.DeleteFileOrDirectory(Path.Combine(managedLibrariesDirectory, path2));
            }
            FileUtil.DeleteFileOrDirectory(str2);
        }