예제 #1
0
        private static int Run(Options options)
        {
            // Banner
            var asmInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location);

            Console.WriteLine(asmInfo.ProductName);
            Console.WriteLine("Version " + asmInfo.ProductVersion);
            Console.WriteLine(asmInfo.LegalCopyright);
            Console.WriteLine("");

            // Check excluded namespaces
            if (options.ExcludedNamespaces.Count() == 1 && options.ExcludedNamespaces.First().ToLower() == "none")
            {
                options.ExcludedNamespaces = new List <string>();
            }

            // Check files
            if (!File.Exists(options.BinaryFile))
            {
                Console.Error.WriteLine($"File {options.BinaryFile} does not exist");
                return(1);
            }
            if (!File.Exists(options.MetadataFile))
            {
                Console.Error.WriteLine($"File {options.MetadataFile} does not exist");
                return(1);
            }

            // Creating a Visual Studio solution requires Unity assembly references
            var unityPath           = string.Empty;
            var unityAssembliesPath = string.Empty;

            if (options.CreateSolution)
            {
                unityPath           = FindPath(options.UnityPath);
                unityAssembliesPath = FindPath(options.UnityAssembliesPath);

                if (!Directory.Exists(unityPath))
                {
                    Console.Error.WriteLine($"Unity path {unityPath} does not exist");
                    return(1);
                }
                if (!File.Exists(unityPath + @"\Editor\Data\Managed\UnityEditor.dll"))
                {
                    Console.Error.WriteLine($"No Unity installation found at {unityPath}");
                    return(1);
                }
                if (!Directory.Exists(unityAssembliesPath))
                {
                    Console.Error.WriteLine($"Unity assemblies path {unityAssembliesPath} does not exist");
                    return(1);
                }
                if (!File.Exists(unityAssembliesPath + @"\UnityEngine.UI.dll"))
                {
                    Console.Error.WriteLine($"No Unity assemblies found at {unityAssembliesPath}");
                    return(1);
                }

                Console.WriteLine("Using Unity editor at " + unityPath);
                Console.WriteLine("Using Unity assemblies at " + unityAssembliesPath);
            }

            // Analyze data
            List <Il2CppInspector> il2cppInspectors;

            using (var il2cppTimer = new Benchmark("Analyze IL2CPP data"))
                il2cppInspectors = Il2CppInspector.LoadFromFile(options.BinaryFile, options.MetadataFile);

            if (il2cppInspectors == null)
            {
                Environment.Exit(1);
            }

            // Write output file
            int i = 0;

            foreach (var il2cpp in il2cppInspectors)
            {
                // Create model
                Il2CppModel model;
                using (var modelTimer = new Benchmark("Create type model"))
                    model = new Il2CppModel(il2cpp);

                // C# signatures output
                using (var signaturesDumperTimer = new Benchmark("Generate C# code")) {
                    var writer = new Il2CppCSharpDumper(model)
                    {
                        ExcludedNamespaces = options.ExcludedNamespaces.ToList(),
                        SuppressMetadata   = options.SuppressMetadata,
                        MustCompile        = options.MustCompile
                    };

                    var imageSuffix = i++ > 0 ? "-" + (i - 1) : "";

                    var csOut = options.CSharpOutPath;
                    if (csOut.ToLower().EndsWith(".cs"))
                    {
                        csOut = csOut.Insert(csOut.Length - 3, imageSuffix);
                    }
                    else
                    {
                        csOut += imageSuffix;
                    }

                    if (options.CreateSolution)
                    {
                        writer.WriteSolution(csOut, unityPath, unityAssembliesPath);
                    }

                    else
                    {
                        switch (options.LayoutSchema.ToLower(), options.SortOrder.ToLower())
                        {
예제 #2
0
        private static int Run(Options options)
        {
            // Check excluded namespaces
            if (options.ExcludedNamespaces.Count() == 1 && options.ExcludedNamespaces.First().ToLower() == "none")
            {
                options.ExcludedNamespaces = new List <string>();
            }

            // Check files
            if (!File.Exists(options.BinaryFile))
            {
                Console.Error.WriteLine($"File {options.BinaryFile} does not exist");
                return(1);
            }
            if (!File.Exists(options.MetadataFile))
            {
                Console.Error.WriteLine($"File {options.MetadataFile} does not exist");
                return(1);
            }

            // Analyze data
            List <Il2CppInspector> il2cppInspectors;

            using (var timer = new Benchmark("Analyze IL2CPP data"))
                il2cppInspectors = Il2CppInspector.LoadFromFile(options.BinaryFile, options.MetadataFile);

            if (il2cppInspectors == null)
            {
                Environment.Exit(1);
            }

            // Write output file
            int i = 0;

            foreach (var il2cpp in il2cppInspectors)
            {
                // Create model
                Il2CppModel model;
                using (var timer1 = new Benchmark("Create type model"))
                    model = new Il2CppModel(il2cpp);

                // C# signatures output
                using var timer2 = new Benchmark("Generate C# code");

                var writer = new Il2CppCSharpDumper(model)
                {
                    ExcludedNamespaces = options.ExcludedNamespaces.ToList(),
                    SuppressMetadata   = options.SuppressMetadata,
                    MustCompile        = options.MustCompile
                };

                var imageSuffix = i++ > 0 ? "-" + (i - 1) : "";

                var csOut = options.CSharpOutPath;
                if (csOut.ToLower().EndsWith(".cs"))
                {
                    csOut = csOut.Insert(csOut.Length - 3, imageSuffix);
                }
                else
                {
                    csOut += imageSuffix;
                }

                switch (options.LayoutSchema.ToLower(), options.SortOrder.ToLower())
                {