Пример #1
0
        private static void ObfuscateWhileLocked()
        {
            if (_options == null)
            {
                _options = OptionsManager.LoadOptions();
            }
            Obfuscator.FixHexBug(_options);

            if (ShouldObfuscate() == false)
            {
                return;
            }

            AssemblySelector selector = new AssemblySelector(_options);

            ICollection <string> compiledDlls = selector.GetCompiledAssemblyPaths();

            BackupDlls(compiledDlls);
            ICollection <string> dlls = selector.GetAssemblyPaths();

            if (dlls.Count == 0 && compiledDlls.Count == 0)
            {
                _noCSharpScripts = true;
            }
            else
            {
                HashSet <string> extraAssemblyReferenceDirectories = new HashSet <string>(_options.extraAssemblyDirectories);

#if UNITY_2017_3_OR_NEWER
                extraAssemblyReferenceDirectories.UnionWith(AssemblyReferenceLocator.GetAssemblyReferenceDirectories());
#endif

                Obfuscator.SetExtraAssemblyDirectories(extraAssemblyReferenceDirectories.ToArray());

#if UNITY_2018_2_OR_NEWER
                if (_options.obfuscateMonoBehaviourClassNames)
                {
                    Debug.LogError(
                        "The mechanism to obfuscate MonoBehaviour class names no longer works since Unity " +
                        "2018.2. You must either roll back to 2018.1, or disable this option.\n" +
                        "\nThis build will be obfuscated as instructed, but you are likely to see " +
                        "NullReferenceException runtime errors.\n");
                }
#endif

                Obfuscator.Obfuscate(dlls, compiledDlls, _options, EditorUserBuildSettings.activeBuildTarget);

                if (_options.obfuscateMonoBehaviourClassNames)
                {
                    /*
                     * RestoreAssets must be called via the update delegate because [PostProcessBuild] is not guaranteed to be called
                     */
                    EditorApplication.update         += RestoreAssets;
                    _monoBehaviourAssetsNeedReverting = true;
                }

                _obfuscatedAfterScene = true;
            }
        }
Пример #2
0
        public static void Obfuscate()
        {
            if (!EditorApplication.isPlayingOrWillChangePlaymode && !obfuscatedAfterScene)
            {
                try
                {
                    EditorApplication.LockReloadAssemblies();

                    HashSet <string> dlls = new HashSet <string>();

                    foreach (string assemblyName in Config.permanentDLLs)
                    {
                        dlls.Add(FindDllLocation(assemblyName));
                    }
                    backupDlls(dlls);

                    foreach (string assemblyName in Config.temporaryDLLs)
                    {
                        dlls.Add(FindDllLocation(assemblyName));
                    }

                    if (dlls.Count == 0)
                    {
                        noCSharpScripts = true;
                    }
                    else
                    {
                        if (options == null)
                        {
                            options = OptionsManager.LoadOptions();
                        }

                        Obfuscator.FixHexBug(options);

                        if (options.enabled)
                        {
                            Obfuscator.SetExtraAssemblyDirectories(Config.extraAssemblyDirectories);
                            Obfuscator.Obfuscate(dlls, options, EditorUserBuildSettings.activeBuildTarget);

                            if (options.obfuscateMonoBehaviourClassNames)
                            {
                                /*
                                 * RestoreAssets must be called via the update delegate because [PostProcessBuild] is not guaranteed to be called
                                 */
                                EditorApplication.update        += RestoreAssets;
                                monoBehaviourAssetsNeedReverting = true;
                            }
                        }
                        obfuscatedAfterScene = true;
                    }
                }
                finally
                {
                    EditorApplication.UnlockReloadAssemblies();
                }
            }
        }
Пример #3
0
        public void ObfuscateAssets(BuildTarget buildTarget, string pathToBuildProject)
        {
#if UNITY_2018_2_OR_NEWER
            if (IsXCodeProject())
            {
                return;
            }
            if (_options == null)
            {
                _options = OptionsManager.LoadOptions();
            }
            if (_options.obfuscateMonoBehaviourClassNames && File.Exists("_AssetTranslations"))
            {
                string pathToGlobalGameManagersAsset = GlobalGameManagersPath.GetPathToGlobalGameManagersAsset(buildTarget, pathToBuildProject);
                Obfuscator.RenameScriptableAssets("_AssetTranslations", pathToGlobalGameManagersAsset);
            }
#endif
        }
Пример #4
0
        private void ObfuscateWhileLocked()
        {
            if (_options == null)
            {
                _options = OptionsManager.LoadOptions();
            }

            if (ShouldObfuscate() == false)
            {
                return;
            }

            AssemblySelector selector = new AssemblySelector(_options);

            ICollection <string> compiledDlls = selector.GetCompiledAssemblyPaths();

            if (compiledDlls.Count > 0)
            {
                EditorApplication.update += RestoreUtils.RestoreOriginalDlls;
            }

            IDictionary <string, string> backupMap = FileBackup.GetBackupMap(compiledDlls);

            FileBackup.Backup(backupMap);

            ICollection <string> dlls = selector.GetAssemblyPaths();

            if (dlls.Count == 0 && compiledDlls.Count == 0)
            {
                _noCSharpScripts = true;
                return;
            }

            HashSet <string> extraAssemblyReferenceDirectories = new HashSet <string>(_options.extraAssemblyDirectories);

#if UNITY_2017_3_OR_NEWER
            extraAssemblyReferenceDirectories.UnionWith(AssemblyReferenceLocator.GetAssemblyReferenceDirectories());
#endif

            Obfuscator.SetExtraAssemblyDirectories(extraAssemblyReferenceDirectories.ToArray());

#if UNITY_2018_2_OR_NEWER
            Obfuscator.ObfuscateMonoBehavioursByAssetDatabase(false);
            var obfuscateMonoBehaviourNames = _options.obfuscateMonoBehaviourClassNames;
            try
            {
                if (IsXCodeProject() && _options.obfuscateMonoBehaviourClassNames)
                {
                    Debug.LogWarning("MonoBehaviour class names will not be obfuscated when creating Xcode projects");
                    _options.obfuscateMonoBehaviourClassNames = false;
                }
#endif

            Obfuscator.Obfuscate(dlls, compiledDlls, _options, EditorUserBuildSettings.activeBuildTarget);

#if !UNITY_2018_2_OR_NEWER
            if (_options.obfuscateMonoBehaviourClassNames)
            {
                /*
                 * RestoreAssets must be registered via the update delegate because [PostProcessBuild] is not guaranteed to be called
                 */
                EditorApplication.update         += RestoreUtils.RestoreMonobehaviourSourceFiles;
                _monoBehaviourAssetsNeedReverting = true;
            }
#else
        }

        finally
        {
            _options.obfuscateMonoBehaviourClassNames = obfuscateMonoBehaviourNames;
        }
#endif
            _hasObfuscated = true;
        }