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; + } } }