Beispiel #1
0
 /**
  * When assemblies are declared in the 'Compiled Assemblies' list within Obfuscator options then before any
  * obfuscation they are temporarily backed up then operated on. This method is then called after obfuscation
  * to restore the original assembly and remove the backup.
  */
 public static void RestoreOriginalDlls()
 {
     try
     {
         Options options = OptionsManager.LoadOptionsIgnoringInstallFiles();
         if (options == null || options.compiledAssemblies.Length == 0)
         {
             return;
         }
         ICollection <string>         compiledAssemblyPaths = new AssemblySelector(options).GetCompiledAssemblyPaths();
         IDictionary <string, string> backupMap             = FileBackup.GetBackupMap(compiledAssemblyPaths);
         //DLLs declared within 'Compiled Assemblies' will be restored from this method.
         FileBackup.Restore(backupMap);
     }
     finally
     {
         EditorApplication.update -= RestoreOriginalDlls;
     }
 }
        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;
        }