From 1e8832ca7eaed78db499142fd37fb8ec0ce37c56 Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 22 May 2025 10:11:02 +0800 Subject: [PATCH] simplify sample DynamicSecretKey. remove hybridclr and obfuz4dhybridclr. --- Samples/DynamicSecretKey/Assets/Bootstrap.cs | 26 +- .../Assets/Editor/BuildCommand.cs | 28 -- .../Assets/Editor/BuildCommand.cs.meta | 11 - .../Assets/HotUpdate/Entry.cs | 9 - .../Obfuz/SymbolObfus/symbol-mapping.xml | 256 ++++++++++-------- .../DynamicSecretKey/Packages/manifest.json | 2 - .../ProjectSettings/Obfuz.asset | 1 + 7 files changed, 151 insertions(+), 182 deletions(-) delete mode 100644 Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs delete mode 100644 Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs.meta diff --git a/Samples/DynamicSecretKey/Assets/Bootstrap.cs b/Samples/DynamicSecretKey/Assets/Bootstrap.cs index d996327..c6257d9 100644 --- a/Samples/DynamicSecretKey/Assets/Bootstrap.cs +++ b/Samples/DynamicSecretKey/Assets/Bootstrap.cs @@ -1,19 +1,10 @@ using Obfuz; using Obfuz.EncryptionVM; -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; using UnityEngine; public class Bootstrap : MonoBehaviour { - // [ObfuzIgnore]指示Obfuz不要混淆这个函数 - // 初始化EncryptionService后被混淆的代码才能正常运行, - // 因此尽可能地早地初始化它。 [ObfuzIgnore] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] private static void SetUpStaticSecretKey() @@ -25,23 +16,18 @@ public class Bootstrap : MonoBehaviour private static void SetUpDynamicSecret() { + Debug.Log("SetUpDynamicSecret begin"); EncryptionService.Encryptor = new GeneratedEncryptionVirtualMachine(Resources.Load("Obfuz/defaultDynamicSecretKey").bytes); - // 设置其他动态EncryptionScope的Encryptor - // ... + Debug.Log("SetUpDynamicSecret end"); } - // Start is called before the first frame update void Start() { - // 在完成热更之后,加载热更DLL之前,加载Obfuz的动态密钥 + // 延迟加载,在使用HotUpdate程序集代码前才加载动态密钥。 + // 如果项目用到了热更新,一般来说在热更新完成后,加载 + // 热更新代码前才加载动态密钥。 SetUpDynamicSecret(); -#if UNITY_EDITOR - Assembly ass = AppDomain.CurrentDomain.GetAssemblies().First(ass => ass.GetName().Name == "HotUpdate"); -#else - Assembly ass = Assembly.Load(File.ReadAllBytes($"{Application.streamingAssetsPath}/HotUpdate.dll.bytes")); -#endif - Type entry = ass.GetType("Entry"); - this.gameObject.AddComponent(entry); + this.gameObject.AddComponent(); } } diff --git a/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs b/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs deleted file mode 100644 index 6b9e378..0000000 --- a/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs +++ /dev/null @@ -1,28 +0,0 @@ -using HybridCLR.Editor; -using Obfuz4HybridCLR; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using UnityEditor; -using UnityEngine; - -public static class BuildCommand -{ - [MenuItem("Build/CompileAndObfuscateAndCopyToStreamingAssets")] - public static void CompileAndObfuscateAndCopyToStreamingAssets() - { - BuildTarget target = EditorUserBuildSettings.activeBuildTarget; - ObfuscateUtil.CompileAndObfuscateHotUpdateAssemblies(target); - - Directory.CreateDirectory(Application.streamingAssetsPath); - - string hotUpdateDllPath = $"{SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target)}"; - foreach (string assName in SettingsUtil.HotUpdateAssemblyNamesIncludePreserved) - { - string srcFile = $"{hotUpdateDllPath}/{assName}.dll"; - string dstFile = $"{Application.streamingAssetsPath}/{assName}.dll.bytes"; - File.Copy(srcFile, dstFile, true); - Debug.Log($"[CompileAndObfuscate] Copy {srcFile} to {dstFile}"); - } - } -} diff --git a/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs.meta b/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs.meta deleted file mode 100644 index 5b56e51..0000000 --- a/Samples/DynamicSecretKey/Assets/Editor/BuildCommand.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: fd4b0e23f5090224eb49f190bb597c4b -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Samples/DynamicSecretKey/Assets/HotUpdate/Entry.cs b/Samples/DynamicSecretKey/Assets/HotUpdate/Entry.cs index 9c4233a..92ceca4 100644 --- a/Samples/DynamicSecretKey/Assets/HotUpdate/Entry.cs +++ b/Samples/DynamicSecretKey/Assets/HotUpdate/Entry.cs @@ -1,18 +1,9 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; public class Entry : MonoBehaviour { - // Start is called before the first frame update void Start() { Debug.Log("Entry Start"); } - - // Update is called once per frame - void Update() - { - - } } diff --git a/Samples/DynamicSecretKey/Assets/Obfuz/SymbolObfus/symbol-mapping.xml b/Samples/DynamicSecretKey/Assets/Obfuz/SymbolObfus/symbol-mapping.xml index dda5358..da6963a 100644 --- a/Samples/DynamicSecretKey/Assets/Obfuz/SymbolObfus/symbol-mapping.xml +++ b/Samples/DynamicSecretKey/Assets/Obfuz/SymbolObfus/symbol-mapping.xml @@ -13,6 +13,9 @@ + + + @@ -22,151 +25,180 @@ - - + + - - - - - - - - - - - + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - + - - - - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/DynamicSecretKey/Packages/manifest.json b/Samples/DynamicSecretKey/Packages/manifest.json index b48bf01..7f3dbb9 100644 --- a/Samples/DynamicSecretKey/Packages/manifest.json +++ b/Samples/DynamicSecretKey/Packages/manifest.json @@ -1,8 +1,6 @@ { "dependencies": { - "com.code-philosophy.hybridclr": "https://github.com/focus-creative-games/hybridclr_unity.git", "com.code-philosophy.obfuz": "https://github.com/focus-creative-games/obfuz.git?path=com.code-philosophy.obfuz", - "com.code-philosophy.obfuz4hybridclr": "https://github.com/focus-creative-games/obfuz.git?path=com.code-philosophy.obfuz4hybridclr", "com.unity.ide.visualstudio": "2.0.23", "com.unity.modules.assetbundle": "1.0.0", "com.unity.modules.imgui": "1.0.0", diff --git a/Samples/DynamicSecretKey/ProjectSettings/Obfuz.asset b/Samples/DynamicSecretKey/ProjectSettings/Obfuz.asset index 042c5e4..ab96620 100644 --- a/Samples/DynamicSecretKey/ProjectSettings/Obfuz.asset +++ b/Samples/DynamicSecretKey/ProjectSettings/Obfuz.asset @@ -19,6 +19,7 @@ MonoBehaviour: - HotUpdate nonObfuscatedButReferencingObfuscatedAssemblies: [] additionalAssemblySearchPaths: [] + obfuscateObfuzRuntime: 1 obfuscationPassSettings: enabledPasses: -1 ruleFiles: []