SymbolObfus: 不混淆带有`[RuntimeInitializeOnLoadMethod]`的函数及它的父类名(否则Unity无法根据类型和函数名找到此函数)

before-split
walon 2025-05-23 08:18:21 +08:00
parent 0efc98fb4d
commit c1beb962f5
2 changed files with 14 additions and 0 deletions

View File

@ -2,6 +2,7 @@
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -134,6 +135,10 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies
{ {
return false; return false;
} }
if (typeDef.Methods.Any(m => MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(m)))
{
return false;
}
return true; return true;
} }
@ -143,6 +148,10 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies
{ {
return !s_monoBehaviourEvents.Contains(methodDef.Name); return !s_monoBehaviourEvents.Contains(methodDef.Name);
} }
if (MetaUtil.HasRuntimeInitializeOnLoadMethodAttribute(methodDef))
{
return false;
}
if (methodDef.DeclaringType.FullName.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_")) if (methodDef.DeclaringType.FullName.StartsWith("UnitySourceGeneratedAssemblyMonoScriptTypes_"))
{ {
return false; return false;

View File

@ -860,5 +860,10 @@ namespace Obfuz.Utils
{ {
return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.EncryptFieldAttribute"); return obj.CustomAttributes.Any(ca => ca.AttributeType.FullName == "Obfuz.EncryptFieldAttribute");
} }
public static bool HasRuntimeInitializeOnLoadMethodAttribute(MethodDef method)
{
return method.CustomAttributes.Any(ca => ca.AttributeType.FullName == "UnityEngine.RuntimeInitializeOnLoadMethodAttribute");
}
} }
} }