fix: disable call obfuscation for not public called method when publish mono backend because mono has more strict access checking, trying access private method in other class will raise MethodAccess Exception
parent
305a56b3db
commit
9c450d7f07
|
@ -360,12 +360,32 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
return isWhiteList;
|
return isWhiteList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool IsTypeSelfAndParentPublic(TypeDef type)
|
||||||
|
{
|
||||||
|
if (type.DeclaringType != null && !IsTypeSelfAndParentPublic(type.DeclaringType))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return type.IsPublic;
|
||||||
|
}
|
||||||
|
|
||||||
public override bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop)
|
public override bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop)
|
||||||
{
|
{
|
||||||
if (IsInWhiteList(calledMethod))
|
if (IsInWhiteList(calledMethod))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 false;
|
||||||
|
}
|
||||||
|
}
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(callerMethod);
|
ObfuscationRule rule = GetMethodObfuscationRule(callerMethod);
|
||||||
if (currentInLoop && rule.obfuscateCallInLoop == false)
|
if (currentInLoop && rule.obfuscateCallInLoop == false)
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace Obfuz.Utils
|
||||||
|
{
|
||||||
|
public static class PlatformUtil
|
||||||
|
{
|
||||||
|
public static bool IsMonoBackend()
|
||||||
|
{
|
||||||
|
return PlayerSettings.GetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup)
|
||||||
|
== ScriptingImplementation.Mono2x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 85d01014c084c56498d292d3b16351d2
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue