From e19dbe1dc8c48b325c894511073ebce504e78932 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 23 May 2025 08:31:43 +0800 Subject: [PATCH] =?UTF-8?q?SymbolObfus:=20=E4=B8=8D=E6=B7=B7=E6=B7=86Unity?= =?UTF-8?q?.Behaviour.BlackboardEnum=E7=89=B9=E6=80=A7=E6=A0=87=E6=B3=A8?= =?UTF-8?q?=E7=9A=84=E6=9E=9A=E4=B8=BE=E7=B1=BB=E5=9E=8B=E5=90=8D=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E6=9E=9A=E4=B8=BE=E9=A1=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SymbolObfus/Policies/UnityRenamePolicy.cs | 33 ++++++++++++++++--- .../Editor/Utils/MetaUtil.cs | 11 +++++-- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs index c404ff1..247ad24 100644 --- a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs +++ b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs @@ -125,17 +125,35 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies "OnSubmit", "OnCancel", }; + + private bool IsUnitySourceGeneratedAssemblyType(TypeDef typeDef) + { + if (typeDef.Name.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_")) + { + return true; + } + if (typeDef.DeclaringType != null) + { + return IsUnitySourceGeneratedAssemblyType(typeDef.DeclaringType); + } + return false; + } + public override bool NeedRename(TypeDef typeDef) { if (MetaUtil.IsScriptOrSerializableType(typeDef)) { return false; } - if (typeDef.FullName.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_")) + if (typeDef.Methods.Any(m => MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(m))) { return false; } - if (typeDef.Methods.Any(m => MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(m))) + if (typeDef.IsEnum && MetaUtil.HasBlackboardEnumAttribute(typeDef)) + { + return false; + } + if (IsUnitySourceGeneratedAssemblyType(typeDef)) { return false; } @@ -144,7 +162,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies public override bool NeedRename(MethodDef methodDef) { - if (MetaUtil.IsInheritFromUnityObject(methodDef.DeclaringType)) + TypeDef typeDef = methodDef.DeclaringType; + if (MetaUtil.IsInheritFromUnityObject(typeDef)) { return !s_monoBehaviourEvents.Contains(methodDef.Name); } @@ -152,7 +171,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return false; } - if (methodDef.DeclaringType.FullName.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_")) + if (IsUnitySourceGeneratedAssemblyType(typeDef)) { return false; } @@ -166,7 +185,11 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return !MetaUtil.IsSerializableField(fieldDef); } - if (fieldDef.DeclaringType.FullName.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_")) + if (typeDef.IsEnum && MetaUtil.HasBlackboardEnumAttribute(typeDef)) + { + return false; + } + if (IsUnitySourceGeneratedAssemblyType(typeDef)) { return false; } diff --git a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs index 3103322..c4cf534 100644 --- a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs +++ b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs @@ -853,17 +853,22 @@ namespace Obfuz.Utils public static bool HasCompilerGeneratedAttribute(IHasCustomAttribute obj) { - return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.CompilerGeneratedAttribute"); + return obj.CustomAttributes.Find("System.Runtime.CompilerServices.CompilerGeneratedAttribute") != null; } public static bool HasEncryptFieldAttribute(IHasCustomAttribute obj) { - return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.EncryptFieldAttribute"); + return obj.CustomAttributes.Find("Obfuz.EncryptFieldAttribute") != null; } public static bool HasRuntimeInitializeOnLoadMethodAttribute(MethodDef method) { - return method.CustomAttributes.Any(ca => ca.AttributeType.FullName == "UnityEngine.RuntimeInitializeOnLoadMethodAttribute"); + return method.CustomAttributes.Find("UnityEngine.RuntimeInitializeOnLoadMethodAttribute") != null; + } + + public static bool HasBlackboardEnumAttribute(TypeDef typeDef) + { + return typeDef.CustomAttributes.Find("Unity.Behavior.BlackboardEnumAttribute") != null; } } }