From dcd38e288b69dddc4b890c690a49752474bd88fa Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 30 May 2025 09:03:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=B7=E6=B7=86=E4=BA=86?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E5=99=A8=E7=94=9F=E6=88=90=E7=9A=84=E6=9C=89?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E7=94=A8=E6=84=8F=E7=9A=84Microsoft.CodeAnal?= =?UTF-8?q?ysis.EmbeddedAttribute=E5=8F=8A=E5=A3=B0=E6=98=8E=E4=BA=86Embed?= =?UTF-8?q?dedAttribute=E7=9A=84CustomAttribute=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- com.code-philosophy.obfuz/Editor/ConstValues.cs | 4 ++++ .../SymbolObfus/Policies/SystemRenamePolicy.cs | 12 +++++++++++- com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs | 8 +++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/com.code-philosophy.obfuz/Editor/ConstValues.cs b/com.code-philosophy.obfuz/Editor/ConstValues.cs index 276826e..9219f73 100644 --- a/com.code-philosophy.obfuz/Editor/ConstValues.cs +++ b/com.code-philosophy.obfuz/Editor/ConstValues.cs @@ -14,6 +14,10 @@ namespace Obfuz.Editor public const string ObfuzIgnoreAttributeFullName = "Obfuz.ObfuzIgnoreAttribute"; + public const string ObfuzScopeFullName = "Obfuz.ObfuzScope"; + public const string EncryptFieldAttributeFullName = "Obfuz.EncryptFieldAttribute"; + + public const string EmbeddedAttributeFullName = "Microsoft.CodeAnalysis.EmbeddedAttribute"; } } diff --git a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/SystemRenamePolicy.cs b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/SystemRenamePolicy.cs index fcbebff..1d05bcd 100644 --- a/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/SystemRenamePolicy.cs +++ b/com.code-philosophy.obfuz/Editor/ObfusPasses/SymbolObfus/Policies/SystemRenamePolicy.cs @@ -1,5 +1,7 @@ using dnlib.DotNet; +using Obfuz.Editor; using Obfuz.Utils; +using System.Collections.Generic; namespace Obfuz.ObfusPasses.SymbolObfus.Policies { @@ -12,9 +14,17 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies _obfuzIgnoreScopeComputeCache = obfuzIgnoreScopeComputeCache; } + private readonly HashSet _fullIgnoreTypeNames = new HashSet + { + ConstValues.ObfuzIgnoreAttributeFullName, + ConstValues.ObfuzScopeFullName, + ConstValues.EncryptFieldAttributeFullName, + ConstValues.EmbeddedAttributeFullName, + }; + private bool IsFullIgnoreObfuscatedType(TypeDef typeDef) { - return typeDef.FullName == "Obfuz.ObfuzIgnoreAttribute" || typeDef.FullName == "Obfuz.ObfuzScope" || typeDef.FullName == "Obfuz.EncryptFieldAttribute"; + return _fullIgnoreTypeNames.Contains(typeDef.FullName) || MetaUtil.HasMicrosoftCodeAnalysisEmbeddedAttribute(typeDef); } public override bool NeedRename(TypeDef typeDef) diff --git a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs index 432ed6d..20c2603 100644 --- a/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs +++ b/com.code-philosophy.obfuz/Editor/Utils/MetaUtil.cs @@ -1,4 +1,5 @@ using dnlib.DotNet; +using Obfuz.Editor; using System; using System.Collections.Generic; using System.IO; @@ -837,7 +838,7 @@ namespace Obfuz.Utils public static bool HasEncryptFieldAttribute(IHasCustomAttribute obj) { - return obj.CustomAttributes.Find("Obfuz.EncryptFieldAttribute") != null; + return obj.CustomAttributes.Find(ConstValues.EncryptFieldAttributeFullName) != null; } public static bool HasRuntimeInitializeOnLoadMethodAttribute(MethodDef method) @@ -859,5 +860,10 @@ namespace Obfuz.Utils { return obj.CustomAttributes.Find("Unity.Jobs.DOTSCompilerGeneratedAttribute") != null; } + + public static bool HasMicrosoftCodeAnalysisEmbeddedAttribute(IHasCustomAttribute obj) + { + return obj.CustomAttributes.Find("Microsoft.CodeAnalysis.EmbeddedAttribute") != null; + } } }