From 4d8737f01c774f7b97c8e30a5e524b89df05632f Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 23 May 2025 11:11:08 +0800 Subject: [PATCH] =?UTF-8?q?change:=20=E5=A6=82=E6=9E=9C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=AD=E5=8C=85=E5=90=AB=E6=9C=89`[RuntimeInitializeOnLoadMe?= =?UTF-8?q?thod]`=E5=B9=B6=E4=B8=94LoadType=E7=AD=89=E4=BA=8E=E6=88=96?= =?UTF-8?q?=E8=80=85=E6=97=A9=E4=BA=8EAfterAssembliesLoaded=E7=9A=84?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E5=88=99=E7=B1=BB=E5=9E=8B=E7=9A=84?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E4=B8=8D?= =?UTF-8?q?=E6=B7=B7=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/ObfuscationMethodWhitelist.cs | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/com.code-philosophy.obfuz/Editor/ObfuscationMethodWhitelist.cs b/com.code-philosophy.obfuz/Editor/ObfuscationMethodWhitelist.cs index 2edb3ef..34a937e 100644 --- a/com.code-philosophy.obfuz/Editor/ObfuscationMethodWhitelist.cs +++ b/com.code-philosophy.obfuz/Editor/ObfuscationMethodWhitelist.cs @@ -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))