修复混淆了编译器生成的有特殊用意的Microsoft.CodeAnalysis.EmbeddedAttribute及声明了EmbeddedAttribute的CustomAttribute的bug

before-split
walon 2025-05-30 09:03:03 +08:00
parent 374a297e45
commit dcd38e288b
3 changed files with 22 additions and 2 deletions

View File

@ -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";
}
}

View File

@ -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<string> _fullIgnoreTypeNames = new HashSet<string>
{
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)

View File

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