diff --git a/Editor/ObfusPasses/CallObfus/CallObfusPass.cs b/Editor/ObfusPasses/CallObfus/CallObfusPass.cs index 5527337..8cc37dc 100644 --- a/Editor/ObfusPasses/CallObfus/CallObfusPass.cs +++ b/Editor/ObfusPasses/CallObfus/CallObfusPass.cs @@ -93,10 +93,10 @@ namespace Obfuz.ObfusPasses.CallObfus private bool ComputeIsInWhiteList(IMethod calledMethod) { + MethodDef calledMethodDef = calledMethod.ResolveMethodDef(); // mono has more strict access control, calls non-public method will raise exception. if (PlatformUtil.IsMonoBackend()) { - MethodDef calledMethodDef = calledMethod.ResolveMethodDef(); if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType))) { return true; @@ -125,6 +125,12 @@ namespace Obfuz.ObfusPasses.CallObfus } TypeDef typeDef = declaringType.ResolveTypeDef(); + + if (!_settings.obfuscateCallToMethodInMscorlib && typeDef.Module.IsCoreLibraryModule == true) + { + return true; + } + if (typeDef.IsDelegate || typeDef.IsEnum) return true; diff --git a/Editor/Settings/CallObfuscationSettings.cs b/Editor/Settings/CallObfuscationSettings.cs index 3bc2150..983a32f 100644 --- a/Editor/Settings/CallObfuscationSettings.cs +++ b/Editor/Settings/CallObfuscationSettings.cs @@ -10,6 +10,7 @@ namespace Obfuz.Settings public List ruleFiles; public int obfuscationLevel; public int maxProxyMethodCountPerDispatchMethod; + public bool obfuscateCallToMethodInMscorlib; } [Serializable] @@ -22,6 +23,9 @@ namespace Obfuz.Settings [Tooltip("The maximum number of proxy methods that can be generated per dispatch method. This helps to limit the complexity of the generated code and improve performance.")] public int maxProxyMethodCountPerDispatchMethod = 100; + [Tooltip("Whether to obfuscate calls to methods in mscorlib. This can help to protect against reverse engineering, but may cause compatibility issues with some libraries.")] + public bool obfuscateCallToMethodInMscorlib; + [Tooltip("rule config xml files")] public string[] ruleFiles; @@ -32,6 +36,7 @@ namespace Obfuz.Settings ruleFiles = ruleFiles?.ToList() ?? new List(), obfuscationLevel = obfuscationLevel, maxProxyMethodCountPerDispatchMethod = maxProxyMethodCountPerDispatchMethod, + obfuscateCallToMethodInMscorlib = obfuscateCallToMethodInMscorlib, }; } }