change: 如果类型中包含有`[RuntimeInitializeOnLoadMethod]`并且LoadType等于或者早于AfterAssembliesLoaded的函数,则类型的静态构造函数不混淆
parent
d06caf5e38
commit
4d8737f01c
|
@ -27,20 +27,8 @@ namespace Obfuz
|
||||||
return false;
|
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");
|
CustomAttribute ca = method.CustomAttributes.Find("UnityEngine.RuntimeInitializeOnLoadMethodAttribute");
|
||||||
if (ca != null && ca.ConstructorArguments.Count > 0)
|
if (ca != null && ca.ConstructorArguments.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +41,35 @@ namespace Obfuz
|
||||||
return false;
|
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)
|
public bool IsInWhiteList(TypeDef type)
|
||||||
{
|
{
|
||||||
if (type.Name.StartsWith(ConstValues.ObfuzInternalSymbolNamePrefix))
|
if (type.Name.StartsWith(ConstValues.ObfuzInternalSymbolNamePrefix))
|
||||||
|
|
Loading…
Reference in New Issue