From aefec5c0245c4a1fbae69b64f9b9669213f636a8 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 11 Sep 2026 12:01:30 +0800 Subject: [PATCH] fix: don't rename inherit enclosing types and nested types of types with `[BurstCompile]` --- .../SymbolObfus/Policies/UnityRenamePolicy.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs b/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs index 114baec..3811ba0 100644 --- a/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs +++ b/Editor/ObfusPasses/SymbolObfus/Policies/UnityRenamePolicy.cs @@ -146,6 +146,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies private readonly CachedDictionary _isSerializableCache; private readonly CachedDictionary _isInheritFromMonoBehaviourOrScriptableObjectCache; private readonly CachedDictionary _isScriptOrSerializableTypeCache; + private readonly CachedDictionary _isAnyNestedTypeHasBurstCompileAttributeCache; + private readonly CachedDictionary _isInheritAnyNestingOrAnyNestedTypeHasBurstCompileAttributeCache; public UnityRenamePolicy() { @@ -153,6 +155,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies _isSerializableCache = new CachedDictionary(MetaUtil.IsSerializableType); _isInheritFromMonoBehaviourOrScriptableObjectCache = new CachedDictionary(MetaUtil.IsScriptType); _isScriptOrSerializableTypeCache = new CachedDictionary(MetaUtil.IsScriptOrSerializableType); + _isAnyNestedTypeHasBurstCompileAttributeCache = new CachedDictionary(IsAnyNestedTypeHasBurstCompileAttribute); + _isInheritAnyNestingOrAnyNestedTypeHasBurstCompileAttributeCache = new CachedDictionary(IsAnyNestingOrNestedTypeHasBurstCompileAttribute); } private bool IsUnitySourceGeneratedAssemblyType(TypeDef typeDef) @@ -197,6 +201,30 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies return false; } + private bool IsInheritAnyNestingTypeHasBurstCompileAttribute(TypeDef typeDef) + { + if (typeDef.Module.IsCoreLibraryModule == true) + { + return false; + } + if (MetaUtil.HasBurstCompileAttribute(typeDef)) + { + return true; + } + TypeDef parentTypeDef = typeDef.DeclaringType; + return parentTypeDef != null && IsInheritAnyNestingTypeHasBurstCompileAttribute(parentTypeDef); + } + + private bool IsAnyNestedTypeHasBurstCompileAttribute(TypeDef typeDef) + { + return typeDef.NestedTypes.Any(nestedType => MetaUtil.HasBurstCompileAttribute(nestedType) || _isAnyNestedTypeHasBurstCompileAttributeCache.GetValue(nestedType)); + } + + private bool IsAnyNestingOrNestedTypeHasBurstCompileAttribute(TypeDef typeDef) + { + return IsInheritAnyNestingTypeHasBurstCompileAttribute(typeDef) || _isAnyNestedTypeHasBurstCompileAttributeCache.GetValue(typeDef); + } + public override bool NeedRename(TypeDef typeDef) { if (_isScriptOrSerializableTypeCache.GetValue(typeDef)) @@ -207,7 +235,8 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies { return false; } - if (MetaUtil.HasBurstCompileAttribute(typeDef)) + // if any declaring type or any nested type has BurstCompile attribute, we should not rename this type + if (_isInheritAnyNestingOrAnyNestedTypeHasBurstCompileAttributeCache.GetValue(typeDef)) { return false; }