From c3ed85fb3f4974a10a29df728e95825ec2616b7a Mon Sep 17 00:00:00 2001 From: walon Date: Thu, 29 May 2025 16:16:32 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=B8=8D=E6=B7=B7=E6=B7=86`[Serializable]`?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84=E7=B1=BB=E5=9E=8B=E5=90=8D=20-=20?= =?UTF-8?q?=E4=B8=8D=E6=B7=B7=E6=B7=86=E4=BB=8EMonoBehaviour=E5=92=8CScrip?= =?UTF-8?q?tableObject=E7=BB=A7=E6=89=BF=E6=88=96=E5=B8=A6`[Serializable]`?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E7=9A=84public=E9=9D=9E=E9=9D=99?= =?UTF-8?q?=E6=80=81=E6=88=90=E5=91=98=E5=AD=97=E6=AE=B5=E5=92=8Cproperty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SymbolObfus/Policies/UnityRenamePolicy.cs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 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 12091cf..0bad7eb 100644 --- a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs +++ b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs @@ -129,12 +129,14 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies private readonly CachedDictionary _computeDeclaringTypeDisableAllMemberRenamingCache; private readonly CachedDictionary _isInheritScriptCache; private readonly CachedDictionary _isInheritFromMonoBehaviourCache; + private readonly CachedDictionary _isScriptOrSerializableTypeCache; public UnityRenamePolicy() { _computeDeclaringTypeDisableAllMemberRenamingCache = new CachedDictionary(ComputeDeclaringTypeDisableAllMemberRenaming); _isInheritScriptCache = new CachedDictionary(MetaUtil.IsScriptType); _isInheritFromMonoBehaviourCache = new CachedDictionary(MetaUtil.IsInheritFromMonoBehaviour); + _isScriptOrSerializableTypeCache = new CachedDictionary(MetaUtil.IsScriptOrSerializableType); } private bool IsUnitySourceGeneratedAssemblyType(TypeDef typeDef) @@ -185,7 +187,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies public override bool NeedRename(TypeDef typeDef) { - if (_isInheritScriptCache.GetValue(typeDef)) + if (_isScriptOrSerializableTypeCache.GetValue(typeDef)) { return false; } @@ -225,9 +227,16 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies public override bool NeedRename(FieldDef fieldDef) { TypeDef typeDef = fieldDef.DeclaringType; - if (MetaUtil.IsScriptOrSerializableType(typeDef)) + if (_isScriptOrSerializableTypeCache.GetValue(typeDef)) { - return !MetaUtil.IsSerializableField(fieldDef); + if (fieldDef.IsPublic && !fieldDef.IsStatic) + { + return false; + } + if (!fieldDef.IsStatic && MetaUtil.IsSerializableField(fieldDef)) + { + return false; + } } if (_computeDeclaringTypeDisableAllMemberRenamingCache.GetValue(typeDef)) { @@ -239,5 +248,21 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies } return true; } + + public override bool NeedRename(PropertyDef propertyDef) + { + TypeDef typeDef = propertyDef.DeclaringType; + if (_isScriptOrSerializableTypeCache.GetValue(typeDef)) + { + bool isGetterPublic = propertyDef.GetMethod != null && propertyDef.GetMethod.IsPublic && !propertyDef.GetMethod.IsStatic; + bool isSetterPublic = propertyDef.SetMethod != null && propertyDef.SetMethod.IsPublic && !propertyDef.SetMethod.IsStatic; + + if (isGetterPublic || isSetterPublic) + { + return false; + } + } + return true; + } } }