new: 新增CompatibilitySettings,允许指定生成与mono或il2cpp兼容的混淆代码
parent
daff29ea94
commit
e12a0e26dc
|
@ -20,7 +20,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
public static CallObfuscationSettingsFacade CurrentSettings { get; private set; }
|
public static CallObfuscationSettingsFacade CurrentSettings { get; private set; }
|
||||||
|
|
||||||
private readonly CallObfuscationSettingsFacade _settings;
|
private readonly CallObfuscationSettingsFacade _settings;
|
||||||
private readonly SpecialWhiteListMethodCalculator _specialWhiteListMethodCache;
|
private SpecialWhiteListMethodCalculator _specialWhiteListMethodCache;
|
||||||
|
|
||||||
private IObfuscator _dynamicProxyObfuscator;
|
private IObfuscator _dynamicProxyObfuscator;
|
||||||
private IObfuscationPolicy _dynamicProxyPolicy;
|
private IObfuscationPolicy _dynamicProxyPolicy;
|
||||||
|
@ -31,8 +31,6 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
CurrentSettings = settings;
|
CurrentSettings = settings;
|
||||||
|
|
||||||
_specialWhiteListMethodCache = new SpecialWhiteListMethodCalculator(settings.obfuscateCallToMethodInMscorlib);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
|
@ -43,6 +41,8 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
var ctx = ObfuscationPassContext.Current;
|
var ctx = ObfuscationPassContext.Current;
|
||||||
|
|
||||||
|
_specialWhiteListMethodCache = new SpecialWhiteListMethodCalculator(ctx.coreSettings.targetRuntime, _settings.obfuscateCallToMethodInMscorlib);
|
||||||
_dynamicProxyObfuscator = CreateObfuscator(ctx, _settings.proxyMode);
|
_dynamicProxyObfuscator = CreateObfuscator(ctx, _settings.proxyMode);
|
||||||
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
|
using Obfuz.Settings;
|
||||||
using Obfuz.Utils;
|
using Obfuz.Utils;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
@ -6,11 +7,13 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
class SpecialWhiteListMethodCalculator
|
class SpecialWhiteListMethodCalculator
|
||||||
{
|
{
|
||||||
|
private readonly RuntimeType _targetRuntime;
|
||||||
private readonly bool _obfuscateCallToMethodInMscorlib;
|
private readonly bool _obfuscateCallToMethodInMscorlib;
|
||||||
private readonly CachedDictionary<IMethod, bool> _specialWhiteListMethodCache;
|
private readonly CachedDictionary<IMethod, bool> _specialWhiteListMethodCache;
|
||||||
|
|
||||||
public SpecialWhiteListMethodCalculator(bool obfuscateCallToMethodInMscorlib)
|
public SpecialWhiteListMethodCalculator(RuntimeType targetRuntime, bool obfuscateCallToMethodInMscorlib)
|
||||||
{
|
{
|
||||||
|
_targetRuntime = targetRuntime;
|
||||||
_obfuscateCallToMethodInMscorlib = obfuscateCallToMethodInMscorlib;
|
_obfuscateCallToMethodInMscorlib = obfuscateCallToMethodInMscorlib;
|
||||||
_specialWhiteListMethodCache = new CachedDictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes, this.ComputeIsInWhiteList);
|
_specialWhiteListMethodCache = new CachedDictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes, this.ComputeIsInWhiteList);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +49,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
MethodDef calledMethodDef = calledMethod.ResolveMethodDef();
|
MethodDef calledMethodDef = calledMethod.ResolveMethodDef();
|
||||||
// mono has more strict access control, calls non-public method will raise exception.
|
// mono has more strict access control, calls non-public method will raise exception.
|
||||||
if (PlatformUtil.IsMonoBackend())
|
if (_targetRuntime == RuntimeType.Mono)
|
||||||
{
|
{
|
||||||
if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType)))
|
if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType)))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Obfuz.EncryptionVM;
|
using dnlib.DotNet.Writer;
|
||||||
|
using Obfuz.EncryptionVM;
|
||||||
using Obfuz.ObfusPasses;
|
using Obfuz.ObfusPasses;
|
||||||
using Obfuz.ObfusPasses.CallObfus;
|
using Obfuz.ObfusPasses.CallObfus;
|
||||||
using Obfuz.ObfusPasses.ConstEncrypt;
|
using Obfuz.ObfusPasses.ConstEncrypt;
|
||||||
|
@ -15,6 +16,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz
|
namespace Obfuz
|
||||||
{
|
{
|
||||||
|
@ -22,6 +24,7 @@ namespace Obfuz
|
||||||
public class CoreSettingsFacade
|
public class CoreSettingsFacade
|
||||||
{
|
{
|
||||||
public BuildTarget buildTarget;
|
public BuildTarget buildTarget;
|
||||||
|
public RuntimeType targetRuntime;
|
||||||
|
|
||||||
public byte[] defaultStaticSecretKey;
|
public byte[] defaultStaticSecretKey;
|
||||||
public byte[] defaultDynamicSecretKey;
|
public byte[] defaultDynamicSecretKey;
|
||||||
|
@ -152,11 +155,20 @@ namespace Obfuz
|
||||||
bool exists = Directory.Exists(path);
|
bool exists = Directory.Exists(path);
|
||||||
UnityEngine.Debug.Log($"search path:{path} exists:{exists}");
|
UnityEngine.Debug.Log($"search path:{path} exists:{exists}");
|
||||||
}
|
}
|
||||||
|
RuntimeType targetRuntime = settings.compatibilitySettings.targetRuntime != RuntimeType.ActivatedScriptingBackend ?
|
||||||
|
settings.compatibilitySettings.targetRuntime :
|
||||||
|
(PlatformUtil.IsMonoBackend() ? RuntimeType.Mono : RuntimeType.IL2CPP);
|
||||||
|
if (searchPathIncludeUnityEditorDll && targetRuntime != RuntimeType.Mono)
|
||||||
|
{
|
||||||
|
Debug.LogError($"obfuscate dll for editor, but ObfuzSettings.CompatibilitySettings.targetRuntime isn't RuntimeType.Mono. Use RuntimeType.Mono for targetRuntime automatically.");
|
||||||
|
targetRuntime = RuntimeType.Mono;
|
||||||
|
}
|
||||||
var builder = new ObfuscatorBuilder
|
var builder = new ObfuscatorBuilder
|
||||||
{
|
{
|
||||||
_coreSettingsFacade = new CoreSettingsFacade()
|
_coreSettingsFacade = new CoreSettingsFacade()
|
||||||
{
|
{
|
||||||
buildTarget = target,
|
buildTarget = target,
|
||||||
|
targetRuntime = targetRuntime,
|
||||||
defaultStaticSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultStaticSecretKey, VirtualMachine.SecretKeyLength),
|
defaultStaticSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultStaticSecretKey, VirtualMachine.SecretKeyLength),
|
||||||
defaultDynamicSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultDynamicSecretKey, VirtualMachine.SecretKeyLength),
|
defaultDynamicSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultDynamicSecretKey, VirtualMachine.SecretKeyLength),
|
||||||
assembliesUsingDynamicSecretKeys = settings.secretSettings.assembliesUsingDynamicSecretKeys.ToList(),
|
assembliesUsingDynamicSecretKeys = settings.secretSettings.assembliesUsingDynamicSecretKeys.ToList(),
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Obfuz.Settings
|
||||||
|
{
|
||||||
|
public enum RuntimeType
|
||||||
|
{
|
||||||
|
ActivatedScriptingBackend,
|
||||||
|
IL2CPP,
|
||||||
|
Mono,
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class CompatibilitySettings
|
||||||
|
{
|
||||||
|
public RuntimeType targetRuntime;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a69af5ef930cf749bfc8e9941a0f4e8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -11,6 +11,9 @@ namespace Obfuz.Settings
|
||||||
[Tooltip("build pipeline settings")]
|
[Tooltip("build pipeline settings")]
|
||||||
public BuildPipelineSettings buildPipelineSettings;
|
public BuildPipelineSettings buildPipelineSettings;
|
||||||
|
|
||||||
|
[Tooltip("compatibility settings")]
|
||||||
|
public CompatibilitySettings compatibilitySettings;
|
||||||
|
|
||||||
[Tooltip("assembly settings")]
|
[Tooltip("assembly settings")]
|
||||||
public AssemblySettings assemblySettings;
|
public AssemblySettings assemblySettings;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace Obfuz.Settings
|
||||||
|
|
||||||
private SerializedObject _serializedObject;
|
private SerializedObject _serializedObject;
|
||||||
private SerializedProperty _buildPipelineSettings;
|
private SerializedProperty _buildPipelineSettings;
|
||||||
|
private SerializedProperty _compatibilitySettings;
|
||||||
|
|
||||||
private SerializedProperty _assemblySettings;
|
private SerializedProperty _assemblySettings;
|
||||||
private SerializedProperty _obfuscationPassSettings;
|
private SerializedProperty _obfuscationPassSettings;
|
||||||
|
@ -66,6 +67,7 @@ namespace Obfuz.Settings
|
||||||
_serializedObject?.Dispose();
|
_serializedObject?.Dispose();
|
||||||
_serializedObject = new SerializedObject(setting);
|
_serializedObject = new SerializedObject(setting);
|
||||||
_buildPipelineSettings = _serializedObject.FindProperty("buildPipelineSettings");
|
_buildPipelineSettings = _serializedObject.FindProperty("buildPipelineSettings");
|
||||||
|
_compatibilitySettings = _serializedObject.FindProperty("compatibilitySettings");
|
||||||
|
|
||||||
_assemblySettings = _serializedObject.FindProperty("assemblySettings");
|
_assemblySettings = _serializedObject.FindProperty("assemblySettings");
|
||||||
_obfuscationPassSettings = _serializedObject.FindProperty("obfuscationPassSettings");
|
_obfuscationPassSettings = _serializedObject.FindProperty("obfuscationPassSettings");
|
||||||
|
@ -98,6 +100,7 @@ namespace Obfuz.Settings
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(_buildPipelineSettings);
|
EditorGUILayout.PropertyField(_buildPipelineSettings);
|
||||||
|
EditorGUILayout.PropertyField(_compatibilitySettings);
|
||||||
|
|
||||||
EditorGUILayout.PropertyField(_assemblySettings);
|
EditorGUILayout.PropertyField(_assemblySettings);
|
||||||
EditorGUILayout.PropertyField(_obfuscationPassSettings);
|
EditorGUILayout.PropertyField(_obfuscationPassSettings);
|
||||||
|
|
Loading…
Reference in New Issue