change: 如果类型中包含有`[RuntimeInitializeOnLoadMethod]`并且LoadType等于或者早于AfterAssembliesLoaded的函数,则类型的静态构造函数不混淆

before-split
walon 2025-05-23 11:11:08 +08:00
parent d06caf5e38
commit 4d8737f01c
1 changed files with 30 additions and 13 deletions

View File

@ -27,20 +27,8 @@ namespace Obfuz
return false;
}
public bool IsInWhiteList(MethodDef method)
private bool DoesMethodContainsRuntimeInitializeOnLoadMethodAttributeAndLoadTypeGreaterEqualAfterAssembliesLoaded(MethodDef method)
{
if (IsInWhiteList(method.DeclaringType))
{
return true;
}
if (method.Name.StartsWith(ConstValues.ObfuzInternalSymbolNamePrefix))
{
return true;
}
if (MetaUtil.HasSelfOrInheritObfuzIgnoreScope(method, method.DeclaringType, ObfuzScope.MethodBody))
{
return true;
}
CustomAttribute ca = method.CustomAttributes.Find("UnityEngine.RuntimeInitializeOnLoadMethodAttribute");
if (ca != null && ca.ConstructorArguments.Count > 0)
{
@ -53,6 +41,35 @@ namespace Obfuz
return false;
}
public bool IsInWhiteList(MethodDef method)
{
TypeDef typeDef = method.DeclaringType;
if (IsInWhiteList(typeDef))
{
return true;
}
if (method.Name.StartsWith(ConstValues.ObfuzInternalSymbolNamePrefix))
{
return true;
}
if (MetaUtil.HasSelfOrInheritObfuzIgnoreScope(method, typeDef, ObfuzScope.MethodBody))
{
return true;
}
CustomAttribute ca = method.CustomAttributes.Find("UnityEngine.RuntimeInitializeOnLoadMethodAttribute");
if (DoesMethodContainsRuntimeInitializeOnLoadMethodAttributeAndLoadTypeGreaterEqualAfterAssembliesLoaded(method))
{
return true;
}
// don't obfuscate cctor when it has RuntimeInitializeOnLoadMethodAttribute with load type AfterAssembliesLoaded
if (method.IsStatic && method.Name == ".cctor" && typeDef.Methods.Any(m => DoesMethodContainsRuntimeInitializeOnLoadMethodAttributeAndLoadTypeGreaterEqualAfterAssembliesLoaded(m)))
{
return true;
}
return false;
}
public bool IsInWhiteList(TypeDef type)
{
if (type.Name.StartsWith(ConstValues.ObfuzInternalSymbolNamePrefix))