新增Obfuz Settings
parent
338543c5a0
commit
b2fc7ffcfd
|
@ -42,13 +42,22 @@ namespace Obfuz
|
||||||
|
|
||||||
private static void RunObfuscate()
|
private static void RunObfuscate()
|
||||||
{
|
{
|
||||||
|
ObfuzSettings settings = ObfuzSettings.Instance;
|
||||||
|
if (!settings.enable)
|
||||||
|
{
|
||||||
|
Debug.Log("Obfuscation is disabled.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Debug.Log("Obfuscation begin...");
|
Debug.Log("Obfuscation begin...");
|
||||||
|
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
|
|
||||||
|
|
||||||
string originalPlayerScriptAssembliesPath = @"Library\Bee\PlayerScriptAssemblies";
|
string originalPlayerScriptAssembliesPath = @"Library\Bee\PlayerScriptAssemblies";
|
||||||
string backupPlayerScriptAssembliesPath = @"Library\Bee\PlayerScriptAssemblies_Backup";
|
string backupPlayerScriptAssembliesPath = settings.GetOriginalAssemblyBackupDir(buildTarget);
|
||||||
BashUtil.CopyDir(originalPlayerScriptAssembliesPath, backupPlayerScriptAssembliesPath);
|
BashUtil.CopyDir(originalPlayerScriptAssembliesPath, backupPlayerScriptAssembliesPath);
|
||||||
|
|
||||||
var obfuzedDlls = new List<string> { "Assembly-CSharp" };
|
|
||||||
|
|
||||||
var opt = new Obfuscator.Options
|
var opt = new Obfuscator.Options
|
||||||
{
|
{
|
||||||
|
@ -59,17 +68,19 @@ namespace Obfuz
|
||||||
@"D:\UnityHubs\2022.3.60f1\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\il2cpp\Managed",
|
@"D:\UnityHubs\2022.3.60f1\Editor\Data\PlaybackEngines\windowsstandalonesupport\Variations\il2cpp\Managed",
|
||||||
backupPlayerScriptAssembliesPath,
|
backupPlayerScriptAssembliesPath,
|
||||||
},
|
},
|
||||||
ObfuscatedAssemblyNames = obfuzedDlls,
|
ObfuscatedAssemblyNames = settings.obfuscatedAssemblyNames.ToList(),
|
||||||
outputDir = $"{backupPlayerScriptAssembliesPath}/obfuzed",
|
mappingXmlPath = settings.GetMappingFile(buildTarget),
|
||||||
|
outputDir = ObfuzSettings.Instance.GetObfuscatedAssemblyOutputDir(buildTarget),
|
||||||
};
|
};
|
||||||
var obfuz = new Obfuscator(opt);
|
var obfuz = new Obfuscator(opt);
|
||||||
obfuz.DoIt();
|
obfuz.Run();
|
||||||
|
|
||||||
foreach (var dllName in obfuzedDlls)
|
foreach (var dllName in settings.obfuscatedAssemblyNames)
|
||||||
{
|
{
|
||||||
string src = $"{opt.outputDir}/{dllName}.dll";
|
string src = $"{opt.outputDir}/{dllName}.dll";
|
||||||
string dst = $"{originalPlayerScriptAssembliesPath}/{dllName}.dll";
|
string dst = $"{originalPlayerScriptAssembliesPath}/{dllName}.dll";
|
||||||
File.Copy(src, dst, true);
|
File.Copy(src, dst, true);
|
||||||
|
Debug.Log($"obfuscate dll:{dst}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("Obfuscation end.");
|
Debug.Log("Obfuscation end.");
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Obfuz
|
||||||
|
{
|
||||||
|
public static class MenuProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/About", priority = 0)]
|
||||||
|
public static void OpenAbout() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/intro");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Settings...", priority = 61)]
|
||||||
|
public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/Obfuz");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/Quick Start")]
|
||||||
|
public static void OpenQuickStart() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/beginner/quickstart");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/Performance")]
|
||||||
|
public static void OpenPerformance() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/basic/performance");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/FAQ")]
|
||||||
|
public static void OpenFAQ() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/help/faq");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/Common Errors")]
|
||||||
|
public static void OpenCommonErrors() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/help/commonerrors");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/Bug Report")]
|
||||||
|
public static void OpenBugReport() => Application.OpenURL("https://obfuz.doc.code-philosophy.com/docs/help/issue");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/GitHub")]
|
||||||
|
public static void OpenGitHub() => Application.OpenURL("https://github.com/focus-creative-games/obfuz");
|
||||||
|
|
||||||
|
[MenuItem("Obfuz/Documents/Gitee")]
|
||||||
|
public static void OpenGitee() => Application.OpenURL("https://gitee.com/focus-creative-games/obfuz");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ namespace Obfuz
|
||||||
{
|
{
|
||||||
public List<string> AssemblySearchDirs;
|
public List<string> AssemblySearchDirs;
|
||||||
public List<string> ObfuscatedAssemblyNames;
|
public List<string> ObfuscatedAssemblyNames;
|
||||||
|
public string mappingXmlPath;
|
||||||
public string outputDir;
|
public string outputDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +45,13 @@ namespace Obfuz
|
||||||
assemblies = _obfuzAssemblies,
|
assemblies = _obfuzAssemblies,
|
||||||
renamePolicy = _renamePolicy,
|
renamePolicy = _renamePolicy,
|
||||||
nameMaker = _nameMaker,
|
nameMaker = _nameMaker,
|
||||||
|
mappingXmlPath = _options.mappingXmlPath,
|
||||||
outputDir = _options.outputDir,
|
outputDir = _options.outputDir,
|
||||||
};
|
};
|
||||||
_symbolRename = new SymbolRename(ctx);
|
_symbolRename = new SymbolRename(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoIt()
|
public void Run()
|
||||||
{
|
{
|
||||||
LoadAssemblies();
|
LoadAssemblies();
|
||||||
Rename();
|
Rename();
|
||||||
|
|
|
@ -27,6 +27,8 @@ namespace Obfuz
|
||||||
|
|
||||||
public INameMaker nameMaker;
|
public INameMaker nameMaker;
|
||||||
|
|
||||||
|
public string mappingXmlPath;
|
||||||
|
|
||||||
public string outputDir;
|
public string outputDir;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,6 @@ namespace Obfuz
|
||||||
_mappingFile = mappingFile;
|
_mappingFile = mappingFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Init(List<ObfuzAssemblyInfo> assemblies, INameMaker nameMaker)
|
public void Init(List<ObfuzAssemblyInfo> assemblies, INameMaker nameMaker)
|
||||||
{
|
{
|
||||||
LoadXmlMappingFile(_mappingFile);
|
LoadXmlMappingFile(_mappingFile);
|
||||||
|
|
|
@ -17,6 +17,7 @@ namespace Obfuz
|
||||||
|
|
||||||
public class SymbolRename
|
public class SymbolRename
|
||||||
{
|
{
|
||||||
|
private readonly string _mappingXmlPath;
|
||||||
private readonly AssemblyCache _assemblyCache;
|
private readonly AssemblyCache _assemblyCache;
|
||||||
private readonly List<ObfuzAssemblyInfo> _obfuzAssemblies;
|
private readonly List<ObfuzAssemblyInfo> _obfuzAssemblies;
|
||||||
private readonly HashSet<ModuleDef> _obfuscatedModules = new HashSet<ModuleDef>();
|
private readonly HashSet<ModuleDef> _obfuscatedModules = new HashSet<ModuleDef>();
|
||||||
|
@ -33,8 +34,10 @@ namespace Obfuz
|
||||||
public List<CAArgument> arguments;
|
public List<CAArgument> arguments;
|
||||||
public List<CANamedArgument> namedArguments;
|
public List<CANamedArgument> namedArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SymbolRename(ObfuscatorContext ctx)
|
public SymbolRename(ObfuscatorContext ctx)
|
||||||
{
|
{
|
||||||
|
_mappingXmlPath = ctx.mappingXmlPath;
|
||||||
_assemblyCache = ctx.assemblyCache;
|
_assemblyCache = ctx.assemblyCache;
|
||||||
_obfuzAssemblies = ctx.assemblies;
|
_obfuzAssemblies = ctx.assemblies;
|
||||||
_renamePolicy = ctx.renamePolicy;
|
_renamePolicy = ctx.renamePolicy;
|
||||||
|
@ -46,7 +49,7 @@ namespace Obfuz
|
||||||
}
|
}
|
||||||
BuildCustomAttributeArguments();
|
BuildCustomAttributeArguments();
|
||||||
|
|
||||||
_renameRecordMap = new RenameRecordMap(Path.Combine(ctx.outputDir, "mapping.xml"));
|
_renameRecordMap = new RenameRecordMap(ctx.mappingXmlPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CollectCArgumentWithTypeOf(IHasCustomAttribute meta, List<CustomAttributeInfo> customAttributes)
|
private void CollectCArgumentWithTypeOf(IHasCustomAttribute meta, List<CustomAttributeInfo> customAttributes)
|
||||||
|
@ -721,6 +724,7 @@ namespace Obfuz
|
||||||
|
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(_mappingXmlPath));
|
||||||
_renameRecordMap.WriteXmlMappingFile();
|
_renameRecordMap.WriteXmlMappingFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditorInternal;
|
||||||
|
|
||||||
|
namespace Obfuz
|
||||||
|
{
|
||||||
|
|
||||||
|
[InitializeOnLoad]
|
||||||
|
public static class EditorStatusWatcher
|
||||||
|
{
|
||||||
|
public static Action OnEditorFocused;
|
||||||
|
static bool isFocused;
|
||||||
|
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||||
|
static void Update()
|
||||||
|
{
|
||||||
|
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||||
|
{
|
||||||
|
isFocused = InternalEditorUtility.isApplicationActive;
|
||||||
|
if (isFocused)
|
||||||
|
{
|
||||||
|
_ = ObfuzSettings.Instance;
|
||||||
|
OnEditorFocused?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditor.Presets;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
|
namespace Obfuz
|
||||||
|
{
|
||||||
|
public class ObfuzSettingsProvider : SettingsProvider
|
||||||
|
{
|
||||||
|
|
||||||
|
private static ObfuzSettingsProvider s_provider;
|
||||||
|
|
||||||
|
[SettingsProvider]
|
||||||
|
public static SettingsProvider CreateMyCustomSettingsProvider()
|
||||||
|
{
|
||||||
|
if (s_provider == null)
|
||||||
|
{
|
||||||
|
s_provider = new ObfuzSettingsProvider();
|
||||||
|
using (var so = new SerializedObject(ObfuzSettings.Instance))
|
||||||
|
{
|
||||||
|
s_provider.keywords = GetSearchKeywordsFromSerializedObject(so);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return s_provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private SerializedObject _serializedObject;
|
||||||
|
private SerializedProperty _enable;
|
||||||
|
private SerializedProperty _obfuscatedAssemblyNames;
|
||||||
|
|
||||||
|
public ObfuzSettingsProvider() : base("Project/Obfuz", SettingsScope.Project)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||||
|
{
|
||||||
|
EditorStatusWatcher.OnEditorFocused += OnEditorFocused;
|
||||||
|
InitGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitGUI()
|
||||||
|
{
|
||||||
|
var setting = ObfuzSettings.Instance;
|
||||||
|
_serializedObject?.Dispose();
|
||||||
|
_serializedObject = new SerializedObject(setting);
|
||||||
|
_enable = _serializedObject.FindProperty("enable");
|
||||||
|
_obfuscatedAssemblyNames = _serializedObject.FindProperty("obfuscatedAssemblyNames");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEditorFocused()
|
||||||
|
{
|
||||||
|
InitGUI();
|
||||||
|
Repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnGUI(string searchContext)
|
||||||
|
{
|
||||||
|
using (CreateSettingsWindowGUIScope())
|
||||||
|
{
|
||||||
|
if (_serializedObject == null||!_serializedObject.targetObject)
|
||||||
|
{
|
||||||
|
InitGUI();
|
||||||
|
}
|
||||||
|
_serializedObject.Update();
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
|
EditorGUILayout.PropertyField(_enable);
|
||||||
|
EditorGUILayout.PropertyField(_obfuscatedAssemblyNames);
|
||||||
|
|
||||||
|
if (EditorGUI.EndChangeCheck())
|
||||||
|
{
|
||||||
|
_serializedObject.ApplyModifiedProperties();
|
||||||
|
ObfuzSettings.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IDisposable CreateSettingsWindowGUIScope()
|
||||||
|
{
|
||||||
|
var unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
|
||||||
|
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
|
||||||
|
return Activator.CreateInstance(type) as IDisposable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnDeactivate()
|
||||||
|
{
|
||||||
|
base.OnDeactivate();
|
||||||
|
EditorStatusWatcher.OnEditorFocused -= OnEditorFocused;
|
||||||
|
ObfuzSettings.Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
using System.IO;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEditorInternal;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Obfuz
|
||||||
|
{
|
||||||
|
|
||||||
|
public class ObfuzSettings : ScriptableObject
|
||||||
|
{
|
||||||
|
[Tooltip("enable Obfuz")]
|
||||||
|
public bool enable = true;
|
||||||
|
|
||||||
|
[Tooltip("obfuscated assembly names(without .dll suffix)")]
|
||||||
|
public string[] obfuscatedAssemblyNames;
|
||||||
|
|
||||||
|
public string ObfuzRootDir => $"Library/Obfuz";
|
||||||
|
|
||||||
|
public string GetMappingFile(BuildTarget target)
|
||||||
|
{
|
||||||
|
return $"{ObfuzRootDir}/{target}/mapping.xml";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetObfuscatedAssemblyOutputDir(BuildTarget target)
|
||||||
|
{
|
||||||
|
return $"{ObfuzRootDir}/{target}/ObfuscatedAssemblies";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetOriginalAssemblyBackupDir(BuildTarget target)
|
||||||
|
{
|
||||||
|
return $"{ObfuzRootDir}/{target}/OriginalAssemblies";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ObfuzSettings s_Instance;
|
||||||
|
|
||||||
|
public static ObfuzSettings Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!s_Instance)
|
||||||
|
{
|
||||||
|
LoadOrCreate();
|
||||||
|
}
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static string SettingsPath => "ProjectSettings/Obfuz.asset";
|
||||||
|
|
||||||
|
private static ObfuzSettings LoadOrCreate()
|
||||||
|
{
|
||||||
|
string filePath = SettingsPath;
|
||||||
|
var arr = InternalEditorUtility.LoadSerializedFileAndForget(filePath);
|
||||||
|
s_Instance = arr.Length > 0 ? arr[0] as ObfuzSettings : CreateInstance<ObfuzSettings>();
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Save()
|
||||||
|
{
|
||||||
|
if (!s_Instance)
|
||||||
|
{
|
||||||
|
Debug.LogError("Cannot save ScriptableSingleton: no instance!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string filePath = SettingsPath;
|
||||||
|
string directoryName = Path.GetDirectoryName(filePath);
|
||||||
|
Directory.CreateDirectory(directoryName);
|
||||||
|
UnityEngine.Object[] obj = new ObfuzSettings[1] { s_Instance };
|
||||||
|
InternalEditorUtility.SaveToSerializedFileAndForget(obj, filePath, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue