修复MonoBehavoiur和ScriptableObject的属性没有混淆的bug

dev
walon 2025-06-28 10:49:30 +08:00
parent 7a7ef72728
commit a833cf26e1
2 changed files with 8 additions and 3 deletions

View File

@ -123,14 +123,14 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies
}; };
private readonly CachedDictionary<TypeDef, bool> _computeDeclaringTypeDisableAllMemberRenamingCache; private readonly CachedDictionary<TypeDef, bool> _computeDeclaringTypeDisableAllMemberRenamingCache;
private readonly CachedDictionary<TypeDef, bool> _isInheritScriptCache; private readonly CachedDictionary<TypeDef, bool> _isSerializableCache;
private readonly CachedDictionary<TypeDef, bool> _isInheritFromMonoBehaviourCache; private readonly CachedDictionary<TypeDef, bool> _isInheritFromMonoBehaviourCache;
private readonly CachedDictionary<TypeDef, bool> _isScriptOrSerializableTypeCache; private readonly CachedDictionary<TypeDef, bool> _isScriptOrSerializableTypeCache;
public UnityRenamePolicy() public UnityRenamePolicy()
{ {
_computeDeclaringTypeDisableAllMemberRenamingCache = new CachedDictionary<TypeDef, bool>(ComputeDeclaringTypeDisableAllMemberRenaming); _computeDeclaringTypeDisableAllMemberRenamingCache = new CachedDictionary<TypeDef, bool>(ComputeDeclaringTypeDisableAllMemberRenaming);
_isInheritScriptCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsScriptType); _isSerializableCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsSerializableType);
_isInheritFromMonoBehaviourCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsInheritFromMonoBehaviour); _isInheritFromMonoBehaviourCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsInheritFromMonoBehaviour);
_isScriptOrSerializableTypeCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsScriptOrSerializableType); _isScriptOrSerializableTypeCache = new CachedDictionary<TypeDef, bool>(MetaUtil.IsScriptOrSerializableType);
} }
@ -252,7 +252,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies
public override bool NeedRename(PropertyDef propertyDef) public override bool NeedRename(PropertyDef propertyDef)
{ {
TypeDef typeDef = propertyDef.DeclaringType; TypeDef typeDef = propertyDef.DeclaringType;
if (_isScriptOrSerializableTypeCache.GetValue(typeDef)) if (_isSerializableCache.GetValue(typeDef))
{ {
bool isGetterPublic = propertyDef.GetMethod != null && propertyDef.GetMethod.IsPublic && !propertyDef.GetMethod.IsStatic; bool isGetterPublic = propertyDef.GetMethod != null && propertyDef.GetMethod.IsPublic && !propertyDef.GetMethod.IsStatic;
bool isSetterPublic = propertyDef.SetMethod != null && propertyDef.SetMethod.IsPublic && !propertyDef.SetMethod.IsStatic; bool isSetterPublic = propertyDef.SetMethod != null && propertyDef.SetMethod.IsPublic && !propertyDef.SetMethod.IsStatic;

View File

@ -177,6 +177,11 @@ namespace Obfuz.Utils
return false; return false;
} }
public static bool IsSerializableType(TypeDef type)
{
return type.IsSerializable;
}
public static bool IsScriptOrSerializableType(TypeDef type) public static bool IsScriptOrSerializableType(TypeDef type)
{ {
return type.IsSerializable || IsScriptType(type); return type.IsSerializable || IsScriptType(type);