2025-05-03 22:00:59 +08:00
|
|
|
using System;
|
2025-04-21 09:57:34 +08:00
|
|
|
using System.Collections.Generic;
|
2025-04-16 23:03:41 +08:00
|
|
|
using System.IO;
|
2025-04-18 08:58:13 +08:00
|
|
|
using System.Runtime.Remoting.Messaging;
|
2025-04-16 23:03:41 +08:00
|
|
|
using UnityEditor;
|
|
|
|
using UnityEditorInternal;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace Obfuz
|
|
|
|
{
|
2025-05-03 22:00:59 +08:00
|
|
|
[Flags]
|
|
|
|
public enum ObfuscationPassType
|
|
|
|
{
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
ConstEncryption = 0x1,
|
|
|
|
MemoryEncryption = 0x2,
|
|
|
|
|
|
|
|
SymbolObfuscation = 0x100,
|
|
|
|
CallProxy = 0x200,
|
|
|
|
ExprObfuscation = 0x400,
|
|
|
|
ControlFlowObfuscation = 0x800,
|
|
|
|
|
|
|
|
|
|
|
|
AllDataEncryption = ConstEncryption | MemoryEncryption,
|
|
|
|
AllCodeObfuscation = SymbolObfuscation | CallProxy | ExprObfuscation | ControlFlowObfuscation,
|
|
|
|
All = AllDataEncryption | AllCodeObfuscation,
|
|
|
|
}
|
2025-04-16 23:03:41 +08:00
|
|
|
|
|
|
|
public class ObfuzSettings : ScriptableObject
|
|
|
|
{
|
|
|
|
[Tooltip("enable Obfuz")]
|
|
|
|
public bool enable = true;
|
|
|
|
|
2025-05-03 21:43:50 +08:00
|
|
|
[Tooltip("name of assemblies to obfuscated")]
|
|
|
|
public string[] toObfuscatedAssemblyNames;
|
|
|
|
|
|
|
|
[Tooltip("name of assemblies not obfuscated but reference assemblies to obfuscated ")]
|
|
|
|
public string[] notObfuscatedAssemblyNamesReferencingObfuscated;
|
2025-04-21 09:57:34 +08:00
|
|
|
|
2025-05-03 22:00:59 +08:00
|
|
|
[Tooltip("enable obfuscation pass")]
|
|
|
|
public ObfuscationPassType enabledObfuscationPasses = ObfuscationPassType.All;
|
|
|
|
|
2025-04-18 08:58:13 +08:00
|
|
|
[Tooltip("path of mapping.xml")]
|
|
|
|
public string mappingFile = "Assets/Obfuz/mapping.xml";
|
|
|
|
|
2025-04-18 19:01:11 +08:00
|
|
|
[Tooltip("obfuscation rule files for assemblies")]
|
|
|
|
public string[] ruleFiles;
|
2025-04-16 23:03:41 +08:00
|
|
|
|
2025-04-19 13:30:30 +08:00
|
|
|
[Tooltip("extra assembly search dirs")]
|
|
|
|
public string[] extraAssemblySearchDirs;
|
|
|
|
|
2025-04-16 23:03:41 +08:00
|
|
|
public string ObfuzRootDir => $"Library/Obfuz";
|
|
|
|
|
|
|
|
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);
|
2025-04-17 10:08:48 +08:00
|
|
|
//Debug.Log($"typeof arr:{arr?.GetType()} arr[0]:{(arr != null && arr.Length > 0 ? arr[0].GetType(): null)}");
|
|
|
|
|
|
|
|
s_Instance = arr != null && arr.Length > 0 ? (ObfuzSettings)arr[0] : CreateInstance<ObfuzSettings>();
|
2025-04-16 23:03:41 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|