重构Obfuscator和Obfusacation Pass参数,不再直接传递Settings,而是传递SettingsFacade,简化大量参数复制代码
parent
b6500147c2
commit
fb9ffae1e8
|
@ -15,19 +15,15 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
public class CallObfusPass : BasicBlockObfuscationPassBase
|
public class CallObfusPass : BasicBlockObfuscationPassBase
|
||||||
{
|
{
|
||||||
private readonly List<string> _configFiles;
|
private readonly CallObfuscationSettingsFacade _settings;
|
||||||
private readonly int _obfuscationLevel;
|
|
||||||
private readonly int _maxProxyMethodPerDispatchMethod;
|
|
||||||
private IObfuscator _dynamicProxyObfuscator;
|
private IObfuscator _dynamicProxyObfuscator;
|
||||||
private IObfuscationPolicy _dynamicProxyPolicy;
|
private IObfuscationPolicy _dynamicProxyPolicy;
|
||||||
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.CallObfus;
|
public override ObfuscationPassType Type => ObfuscationPassType.CallObfus;
|
||||||
|
|
||||||
public CallObfusPass(CallObfuscationSettings settings)
|
public CallObfusPass(CallObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_configFiles = settings.ruleFiles.ToList();
|
_settings = settings;
|
||||||
_obfuscationLevel = settings.obfuscationLevel;
|
|
||||||
_maxProxyMethodPerDispatchMethod = settings.maxProxyMethodCountPerDispatchMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
|
@ -38,8 +34,8 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
var ctx = ObfuscationPassContext.Current;
|
var ctx = ObfuscationPassContext.Current;
|
||||||
_dynamicProxyObfuscator = new DefaultCallProxyObfuscator(ctx.encryptionScopeProvider, ctx.constFieldAllocator, ctx.moduleEntityManager, _obfuscationLevel, _maxProxyMethodPerDispatchMethod);
|
_dynamicProxyObfuscator = new DefaultCallProxyObfuscator(ctx.encryptionScopeProvider, ctx.constFieldAllocator, ctx.moduleEntityManager, _settings);
|
||||||
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.assembliesToObfuscate, _configFiles);
|
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool NeedObfuscateMethod(MethodDef method)
|
protected override bool NeedObfuscateMethod(MethodDef method)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using dnlib.DotNet.Emit;
|
using dnlib.DotNet.Emit;
|
||||||
using Obfuz.Editor;
|
using Obfuz.Editor;
|
||||||
using Obfuz.Emit;
|
using Obfuz.Emit;
|
||||||
|
using Obfuz.Settings;
|
||||||
using Obfuz.Utils;
|
using Obfuz.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -35,7 +36,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
private ModuleDef _module;
|
private ModuleDef _module;
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||||
private readonly int _encryptionLevel;
|
private readonly CallObfuscationSettingsFacade _settings;
|
||||||
|
|
||||||
private EncryptionScopeInfo _encryptionScope;
|
private EncryptionScopeInfo _encryptionScope;
|
||||||
private bool _done;
|
private bool _done;
|
||||||
|
@ -88,17 +89,15 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
public List<CallInfo> methods = new List<CallInfo>();
|
public List<CallInfo> methods = new List<CallInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly int _maxProxyMethodPerDispatchMethod;
|
|
||||||
private readonly Dictionary<MethodSig, List<DispatchMethodInfo>> _dispatchMethods = new Dictionary<MethodSig, List<DispatchMethodInfo>>(SignatureEqualityComparer.Instance);
|
private readonly Dictionary<MethodSig, List<DispatchMethodInfo>> _dispatchMethods = new Dictionary<MethodSig, List<DispatchMethodInfo>>(SignatureEqualityComparer.Instance);
|
||||||
|
|
||||||
|
|
||||||
private TypeDef _proxyTypeDef;
|
private TypeDef _proxyTypeDef;
|
||||||
|
|
||||||
public ModuleCallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, int encryptionLevel, int maxProxyMethodPerDispatchMethod)
|
public ModuleCallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, CallObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
_encryptionScopeProvider = encryptionScopeProvider;
|
||||||
_encryptionLevel = encryptionLevel;
|
_settings = settings;
|
||||||
_maxProxyMethodPerDispatchMethod = maxProxyMethodPerDispatchMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init(ModuleDef mod)
|
public void Init(ModuleDef mod)
|
||||||
|
@ -160,7 +159,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
|
|
||||||
private int GenerateEncryptOps(IRandom random)
|
private int GenerateEncryptOps(IRandom random)
|
||||||
{
|
{
|
||||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, _encryptionScope.encryptor, _encryptionLevel);
|
return EncryptionUtil.GenerateEncryptionOpCodes(random, _encryptionScope.encryptor, _settings.obfuscationLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DispatchMethodInfo GetDispatchMethod(IMethod method)
|
private DispatchMethodInfo GetDispatchMethod(IMethod method)
|
||||||
|
@ -171,7 +170,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
dispatchMethods = new List<DispatchMethodInfo>();
|
dispatchMethods = new List<DispatchMethodInfo>();
|
||||||
_dispatchMethods.Add(methodSig, dispatchMethods);
|
_dispatchMethods.Add(methodSig, dispatchMethods);
|
||||||
}
|
}
|
||||||
if (dispatchMethods.Count == 0 || dispatchMethods.Last().methods.Count >= _maxProxyMethodPerDispatchMethod)
|
if (dispatchMethods.Count == 0 || dispatchMethods.Last().methods.Count >= _settings.maxProxyMethodCountPerDispatchMethod)
|
||||||
{
|
{
|
||||||
var newDispatchMethodInfo = new DispatchMethodInfo
|
var newDispatchMethodInfo = new DispatchMethodInfo
|
||||||
{
|
{
|
||||||
|
@ -261,20 +260,18 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||||
private GroupByModuleEntityManager _moduleEntityManager;
|
private GroupByModuleEntityManager _moduleEntityManager;
|
||||||
private readonly int _encryptionLevel;
|
private readonly CallObfuscationSettingsFacade _settings;
|
||||||
private readonly int _maxProxyMethodPerDispatchMethod;
|
|
||||||
|
|
||||||
public CallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel, int maxProxyMethodPerDispatchMethod)
|
public CallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, CallObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
_encryptionScopeProvider = encryptionScopeProvider;
|
||||||
_moduleEntityManager = moduleEntityManager;
|
_moduleEntityManager = moduleEntityManager;
|
||||||
_encryptionLevel = encryptionLevel;
|
_settings = settings;
|
||||||
_maxProxyMethodPerDispatchMethod = maxProxyMethodPerDispatchMethod;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleCallProxyAllocator GetModuleAllocator(ModuleDef mod)
|
private ModuleCallProxyAllocator GetModuleAllocator(ModuleDef mod)
|
||||||
{
|
{
|
||||||
return _moduleEntityManager.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_encryptionScopeProvider, _encryptionLevel, _maxProxyMethodPerDispatchMethod));
|
return _moduleEntityManager.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_encryptionScopeProvider, _settings));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProxyCallMethodData Allocate(ModuleDef mod, IMethod method, bool callVir)
|
public ProxyCallMethodData Allocate(ModuleDef mod, IMethod method, bool callVir)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Obfuz.Utils;
|
||||||
using Obfuz.Emit;
|
using Obfuz.Emit;
|
||||||
using Obfuz.Data;
|
using Obfuz.Data;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Obfuz.Settings;
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
namespace Obfuz.ObfusPasses.CallObfus
|
||||||
{
|
{
|
||||||
|
@ -15,12 +16,12 @@ namespace Obfuz.ObfusPasses.CallObfus
|
||||||
private readonly CallProxyAllocator _proxyCallAllocator;
|
private readonly CallProxyAllocator _proxyCallAllocator;
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||||
|
|
||||||
public DefaultCallProxyObfuscator(EncryptionScopeProvider encryptionScopeProvider, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel, int maxProxyMethodPerDispatchMethod)
|
public DefaultCallProxyObfuscator(EncryptionScopeProvider encryptionScopeProvider, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, CallObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
_encryptionScopeProvider = encryptionScopeProvider;
|
||||||
_constFieldAllocator = constFieldAllocator;
|
_constFieldAllocator = constFieldAllocator;
|
||||||
_moduleEntityManager = moduleEntityManager;
|
_moduleEntityManager = moduleEntityManager;
|
||||||
_proxyCallAllocator = new CallProxyAllocator(encryptionScopeProvider, moduleEntityManager, encryptionLevel, maxProxyMethodPerDispatchMethod);
|
_proxyCallAllocator = new CallProxyAllocator(encryptionScopeProvider, moduleEntityManager, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Done()
|
public override void Done()
|
||||||
|
|
|
@ -15,23 +15,21 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
|
|
||||||
public class ConstEncryptPass : BasicBlockObfuscationPassBase
|
public class ConstEncryptPass : BasicBlockObfuscationPassBase
|
||||||
{
|
{
|
||||||
private readonly List<string> _configFiles;
|
private readonly ConstEncryptionSettingsFacade _settings;
|
||||||
private readonly int _encryptionLevel;
|
|
||||||
private IEncryptPolicy _dataObfuscatorPolicy;
|
private IEncryptPolicy _dataObfuscatorPolicy;
|
||||||
private IConstEncryptor _dataObfuscator;
|
private IConstEncryptor _dataObfuscator;
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.ConstEncrypt;
|
public override ObfuscationPassType Type => ObfuscationPassType.ConstEncrypt;
|
||||||
|
|
||||||
public ConstEncryptPass(ConstEncryptionSettings settings)
|
public ConstEncryptPass(ConstEncryptionSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_configFiles = settings.ruleFiles.ToList();
|
_settings = settings;
|
||||||
_encryptionLevel = settings.encryptionLevel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
var ctx = ObfuscationPassContext.Current;
|
var ctx = ObfuscationPassContext.Current;
|
||||||
_dataObfuscatorPolicy = new ConfigurableEncryptPolicy(ctx.assembliesToObfuscate, _configFiles);
|
_dataObfuscatorPolicy = new ConfigurableEncryptPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||||
_dataObfuscator = new DefaultConstEncryptor(ctx.encryptionScopeProvider, ctx.rvaDataAllocator, ctx.constFieldAllocator, ctx.moduleEntityManager, _encryptionLevel);
|
_dataObfuscator = new DefaultConstEncryptor(ctx.encryptionScopeProvider, ctx.rvaDataAllocator, ctx.constFieldAllocator, ctx.moduleEntityManager, _settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Obfuz.Settings;
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
{
|
{
|
||||||
|
@ -16,15 +17,15 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
private readonly RvaDataAllocator _rvaDataAllocator;
|
||||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
private readonly ConstFieldAllocator _constFieldAllocator;
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||||
private readonly int _encryptionLevel;
|
private readonly ConstEncryptionSettingsFacade _settings;
|
||||||
|
|
||||||
public DefaultConstEncryptor(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel)
|
public DefaultConstEncryptor(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, ConstEncryptionSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
_encryptionScopeProvider = encryptionScopeProvider;
|
||||||
_rvaDataAllocator = rvaDataAllocator;
|
_rvaDataAllocator = rvaDataAllocator;
|
||||||
_constFieldAllocator = constFieldAllocator;
|
_constFieldAllocator = constFieldAllocator;
|
||||||
_moduleEntityManager = moduleEntityManager;
|
_moduleEntityManager = moduleEntityManager;
|
||||||
_encryptionLevel = encryptionLevel;
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRandom CreateRandomForValue(EncryptionScopeInfo encryptionScope, int value)
|
private IRandom CreateRandomForValue(EncryptionScopeInfo encryptionScope, int value)
|
||||||
|
@ -34,7 +35,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
|
|
||||||
private int GenerateEncryptionOperations(EncryptionScopeInfo encryptionScope, IRandom random)
|
private int GenerateEncryptionOperations(EncryptionScopeInfo encryptionScope, IRandom random)
|
||||||
{
|
{
|
||||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, encryptionScope.encryptor, _encryptionLevel);
|
return EncryptionUtil.GenerateEncryptionOpCodes(random, encryptionScope.encryptor, _settings.encryptionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GenerateSalt(IRandom random)
|
public int GenerateSalt(IRandom random)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using dnlib.DotNet.Emit;
|
using dnlib.DotNet.Emit;
|
||||||
using Obfuz.Emit;
|
using Obfuz.Emit;
|
||||||
|
using Obfuz.Settings;
|
||||||
using Obfuz.Utils;
|
using Obfuz.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
@ -14,13 +15,13 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
||||||
{
|
{
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
||||||
private readonly int _encryptionLevel;
|
private readonly FieldEncryptionSettingsFacade _settings;
|
||||||
|
|
||||||
public DefaultFieldEncryptor(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel)
|
public DefaultFieldEncryptor(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, FieldEncryptionSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
_encryptionScopeProvider = encryptionScopeProvider;
|
||||||
_moduleEntityManager = moduleEntityManager;
|
_moduleEntityManager = moduleEntityManager;
|
||||||
_encryptionLevel = encryptionLevel;
|
_settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultMetadataImporter GetMetadataImporter(MethodDef method)
|
private DefaultMetadataImporter GetMetadataImporter(MethodDef method)
|
||||||
|
@ -64,7 +65,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
||||||
|
|
||||||
private int GenerateEncryptionOperations(IRandom random, IEncryptor encryptor)
|
private int GenerateEncryptionOperations(IRandom random, IEncryptor encryptor)
|
||||||
{
|
{
|
||||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, encryptor, _encryptionLevel);
|
return EncryptionUtil.GenerateEncryptionOpCodes(random, encryptor, _settings.encryptionLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GenerateSalt(IRandom random)
|
public int GenerateSalt(IRandom random)
|
||||||
|
|
|
@ -12,17 +12,15 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
||||||
|
|
||||||
public class FieldEncryptPass : InstructionObfuscationPassBase
|
public class FieldEncryptPass : InstructionObfuscationPassBase
|
||||||
{
|
{
|
||||||
private readonly List<string> _configFiles;
|
private FieldEncryptionSettingsFacade _settings;
|
||||||
private readonly int _encryptionLevel;
|
|
||||||
private IEncryptPolicy _encryptionPolicy;
|
private IEncryptPolicy _encryptionPolicy;
|
||||||
private IFieldEncryptor _memoryEncryptor;
|
private IFieldEncryptor _memoryEncryptor;
|
||||||
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.FieldEncrypt;
|
public override ObfuscationPassType Type => ObfuscationPassType.FieldEncrypt;
|
||||||
|
|
||||||
public FieldEncryptPass(FieldEncryptionSettings settings)
|
public FieldEncryptPass(FieldEncryptionSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_configFiles = settings.ruleFiles.ToList();
|
_settings = settings;
|
||||||
_encryptionLevel = settings.encryptionLevel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ForceProcessAllAssembliesAndIgnoreAllPolicy => true;
|
protected override bool ForceProcessAllAssembliesAndIgnoreAllPolicy => true;
|
||||||
|
@ -30,8 +28,8 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
var ctx = ObfuscationPassContext.Current;
|
var ctx = ObfuscationPassContext.Current;
|
||||||
_memoryEncryptor = new DefaultFieldEncryptor(ctx.encryptionScopeProvider, ctx.moduleEntityManager, _encryptionLevel);
|
_memoryEncryptor = new DefaultFieldEncryptor(ctx.encryptionScopeProvider, ctx.moduleEntityManager, _settings);
|
||||||
_encryptionPolicy = new ConfigurableEncryptPolicy(ctx.assembliesToObfuscate, _configFiles);
|
_encryptionPolicy = new ConfigurableEncryptPolicy(ctx.coreSettings.assembliesToObfuscate, _settings.ruleFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.SymbolObfus;
|
public override ObfuscationPassType Type => ObfuscationPassType.SymbolObfus;
|
||||||
|
|
||||||
public SymbolObfusPass(SymbolObfuscationSettings settings)
|
public SymbolObfusPass(SymbolObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_symbolRename = new SymbolRename(settings);
|
_symbolRename = new SymbolRename(settings);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
public List<CANamedArgument> namedArguments;
|
public List<CANamedArgument> namedArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SymbolRename(SymbolObfuscationSettings settings)
|
public SymbolRename(SymbolObfuscationSettingsFacade settings)
|
||||||
{
|
{
|
||||||
_useConsistentNamespaceObfuscation = settings.useConsistentNamespaceObfuscation;
|
_useConsistentNamespaceObfuscation = settings.useConsistentNamespaceObfuscation;
|
||||||
_mappingXmlPath = settings.symbolMappingFile;
|
_mappingXmlPath = settings.symbolMappingFile;
|
||||||
|
@ -59,7 +59,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
_toObfuscatedModules = ctx.modulesToObfuscate;
|
_toObfuscatedModules = ctx.modulesToObfuscate;
|
||||||
_obfuscatedAndNotObfuscatedModules = ctx.allObfuscationRelativeModules;
|
_obfuscatedAndNotObfuscatedModules = ctx.allObfuscationRelativeModules;
|
||||||
_toObfuscatedModuleSet = new HashSet<ModuleDef>(ctx.modulesToObfuscate);
|
_toObfuscatedModuleSet = new HashSet<ModuleDef>(ctx.modulesToObfuscate);
|
||||||
var obfuscateRuleConfig = new ConfigurableRenamePolicy(ctx.assembliesToObfuscate, _obfuscationRuleFiles);
|
var obfuscateRuleConfig = new ConfigurableRenamePolicy(ctx.coreSettings.assembliesToObfuscate, _obfuscationRuleFiles);
|
||||||
_renamePolicy = new CacheRenamePolicy(new CombineRenamePolicy(new SupportPassPolicy(ctx.passPolicy), new SystemRenamePolicy(), new UnityRenamePolicy(), obfuscateRuleConfig));
|
_renamePolicy = new CacheRenamePolicy(new CombineRenamePolicy(new SupportPassPolicy(ctx.passPolicy), new SystemRenamePolicy(), new UnityRenamePolicy(), obfuscateRuleConfig));
|
||||||
BuildCustomAttributeArguments();
|
BuildCustomAttributeArguments();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,19 +61,14 @@ namespace Obfuz
|
||||||
{
|
{
|
||||||
public static ObfuscationPassContext Current { get; set; }
|
public static ObfuscationPassContext Current { get; set; }
|
||||||
|
|
||||||
|
public CoreSettingsFacade coreSettings;
|
||||||
|
|
||||||
public GroupByModuleEntityManager moduleEntityManager;
|
public GroupByModuleEntityManager moduleEntityManager;
|
||||||
|
|
||||||
public AssemblyCache assemblyCache;
|
public AssemblyCache assemblyCache;
|
||||||
|
|
||||||
public List<ModuleDef> modulesToObfuscate;
|
public List<ModuleDef> modulesToObfuscate;
|
||||||
public List<ModuleDef> allObfuscationRelativeModules;
|
public List<ModuleDef> allObfuscationRelativeModules;
|
||||||
|
|
||||||
public List<string> assembliesToObfuscate;
|
|
||||||
public List<string> nonObfuscatedButReferencingObfuscatedAssemblies;
|
|
||||||
|
|
||||||
public string obfuscatedAssemblyOutputPath;
|
|
||||||
|
|
||||||
public EncryptionScopeProvider encryptionScopeProvider;
|
public EncryptionScopeProvider encryptionScopeProvider;
|
||||||
public ConstFieldAllocator constFieldAllocator;
|
public ConstFieldAllocator constFieldAllocator;
|
||||||
public RvaDataAllocator rvaDataAllocator;
|
public RvaDataAllocator rvaDataAllocator;
|
||||||
|
|
|
@ -21,11 +21,9 @@ namespace Obfuz
|
||||||
|
|
||||||
public class Obfuscator
|
public class Obfuscator
|
||||||
{
|
{
|
||||||
private readonly string _obfuscatedAssemblyTempOutputPath;
|
private readonly CoreSettingsFacade _coreSettings;
|
||||||
private readonly string _obfuscatedAssemblyOutputPath;
|
private readonly List<string> _allObfuscationRelativeAssemblyNames;
|
||||||
|
private readonly HashSet<string> _assembliesUsingDynamicSecretKeys;
|
||||||
private readonly List<string> _assembliesToObfuscate;
|
|
||||||
private readonly List<string> _nonObfuscatedButReferencingObfuscatedAssemblies;
|
|
||||||
private readonly CombinedAssemblyResolver _assemblyResolver;
|
private readonly CombinedAssemblyResolver _assemblyResolver;
|
||||||
|
|
||||||
private readonly ConfigurablePassPolicy _passPolicy;
|
private readonly ConfigurablePassPolicy _passPolicy;
|
||||||
|
@ -33,38 +31,20 @@ namespace Obfuz
|
||||||
private readonly Pipeline _pipeline1 = new Pipeline();
|
private readonly Pipeline _pipeline1 = new Pipeline();
|
||||||
private readonly Pipeline _pipeline2 = new Pipeline();
|
private readonly Pipeline _pipeline2 = new Pipeline();
|
||||||
|
|
||||||
private readonly byte[] _defaultStaticByteSecretKey;
|
|
||||||
private readonly byte[] _defaultDynamicByteSecret;
|
|
||||||
private readonly HashSet<string> _assembliesUsingDynamicSecretKeys;
|
|
||||||
|
|
||||||
private readonly int _randomSeed;
|
|
||||||
private readonly string _encryptionVmGenerationSecretKey;
|
|
||||||
private readonly int _encryptionVmOpCodeCount;
|
|
||||||
private readonly string _encryptionVmCodeFile;
|
|
||||||
|
|
||||||
private ObfuscationPassContext _ctx;
|
private ObfuscationPassContext _ctx;
|
||||||
|
|
||||||
public Obfuscator(ObfuscatorBuilder builder)
|
public Obfuscator(ObfuscatorBuilder builder)
|
||||||
{
|
{
|
||||||
_defaultStaticByteSecretKey = KeyGenerator.GenerateKey(builder.DefaultStaticSecretKey, VirtualMachine.SecretKeyLength);
|
_coreSettings = builder.CoreSettingsFacade;
|
||||||
_defaultDynamicByteSecret = KeyGenerator.GenerateKey(builder.DefaultDynamicSecretKey, VirtualMachine.SecretKeyLength);
|
_allObfuscationRelativeAssemblyNames = _coreSettings.assembliesToObfuscate
|
||||||
_assembliesUsingDynamicSecretKeys = new HashSet<string>(builder.AssembliesUsingDynamicSecretKeys);
|
.Concat(_coreSettings.nonObfuscatedButReferencingObfuscatedAssemblies)
|
||||||
|
.ToList();
|
||||||
|
_assembliesUsingDynamicSecretKeys = new HashSet<string>(_coreSettings.assembliesUsingDynamicSecretKeys);
|
||||||
|
|
||||||
|
_assemblyResolver = new CombinedAssemblyResolver(new PathAssemblyResolver(_coreSettings.assemblySearchPaths.ToArray()), new UnityProjectManagedAssemblyResolver(_coreSettings.buildTarget));
|
||||||
|
_passPolicy = new ConfigurablePassPolicy(_coreSettings.assembliesToObfuscate, _coreSettings.enabledObfuscationPasses, _coreSettings.obfuscationPassRuleConfigFiles);
|
||||||
|
|
||||||
_randomSeed = builder.RandomSeed;
|
foreach (var pass in _coreSettings.obfuscationPasses)
|
||||||
_encryptionVmGenerationSecretKey = builder.EncryptionVmGenerationSecretKey;
|
|
||||||
_encryptionVmOpCodeCount = builder.EncryptionVmOpCodeCount;
|
|
||||||
_encryptionVmCodeFile = builder.EncryptionVmCodeFile;
|
|
||||||
|
|
||||||
_assembliesToObfuscate = builder.AssembliesToObfuscate;
|
|
||||||
_nonObfuscatedButReferencingObfuscatedAssemblies = builder.NonObfuscatedButReferencingObfuscatedAssemblies;
|
|
||||||
_obfuscatedAssemblyOutputPath = builder.ObfuscatedAssemblyOutputPath;
|
|
||||||
_obfuscatedAssemblyTempOutputPath = builder.ObfuscatedAssemblyTempOutputPath;
|
|
||||||
_assemblyResolver = new CombinedAssemblyResolver(new PathAssemblyResolver(builder.AssemblySearchPaths.ToArray()), new UnityProjectManagedAssemblyResolver(builder.BuildTarget));
|
|
||||||
|
|
||||||
_passPolicy = new ConfigurablePassPolicy(_assembliesToObfuscate, builder.EnableObfuscationPasses, builder.ObfuscationPassRuleConfigFiles);
|
|
||||||
|
|
||||||
foreach (var pass in builder.ObfuscationPasses)
|
|
||||||
{
|
{
|
||||||
if (pass is SymbolObfusPass symbolObfusPass)
|
if (pass is SymbolObfusPass symbolObfusPass)
|
||||||
{
|
{
|
||||||
|
@ -82,12 +62,12 @@ namespace Obfuz
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
Debug.Log($"Obfuscator Run. begin");
|
Debug.Log($"Obfuscator Run. begin");
|
||||||
FileUtil.RecreateDir(_obfuscatedAssemblyOutputPath);
|
FileUtil.RecreateDir(_coreSettings.obfuscatedAssemblyOutputPath);
|
||||||
FileUtil.RecreateDir(_obfuscatedAssemblyTempOutputPath);
|
FileUtil.RecreateDir(_coreSettings.obfuscatedAssemblyTempOutputPath);
|
||||||
RunPipeline(_pipeline1);
|
RunPipeline(_pipeline1);
|
||||||
_assemblyResolver.InsertFirst(new PathAssemblyResolver(_obfuscatedAssemblyTempOutputPath));
|
_assemblyResolver.InsertFirst(new PathAssemblyResolver(_coreSettings.obfuscatedAssemblyTempOutputPath));
|
||||||
RunPipeline(_pipeline2);
|
RunPipeline(_pipeline2);
|
||||||
FileUtil.CopyDir(_obfuscatedAssemblyTempOutputPath, _obfuscatedAssemblyOutputPath, true);
|
FileUtil.CopyDir(_coreSettings.obfuscatedAssemblyTempOutputPath, _coreSettings.obfuscatedAssemblyOutputPath, true);
|
||||||
Debug.Log($"Obfuscator Run. end");
|
Debug.Log($"Obfuscator Run. end");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,17 +84,18 @@ namespace Obfuz
|
||||||
|
|
||||||
private IEncryptor CreateEncryptionVirtualMachine(byte[] secretKey)
|
private IEncryptor CreateEncryptionVirtualMachine(byte[] secretKey)
|
||||||
{
|
{
|
||||||
var vmCreator = new VirtualMachineCreator(_encryptionVmGenerationSecretKey);
|
var vmCreator = new VirtualMachineCreator(_coreSettings.encryptionVmGenerationSecretKey);
|
||||||
var vm = vmCreator.CreateVirtualMachine(_encryptionVmOpCodeCount);
|
var vm = vmCreator.CreateVirtualMachine(_coreSettings.encryptionVmOpCodeCount);
|
||||||
var vmGenerator = new VirtualMachineCodeGenerator(vm);
|
var vmGenerator = new VirtualMachineCodeGenerator(vm);
|
||||||
|
|
||||||
if (!File.Exists(_encryptionVmCodeFile))
|
string encryptionVmCodeFile = _coreSettings.encryptionVmCodeFile;
|
||||||
|
if (!File.Exists(encryptionVmCodeFile))
|
||||||
{
|
{
|
||||||
throw new Exception($"EncryptionVm CodeFile:`{_encryptionVmCodeFile}` not exists! Please run `Obfuz/GenerateVm` to generate it!");
|
throw new Exception($"EncryptionVm CodeFile:`{encryptionVmCodeFile}` not exists! Please run `Obfuz/GenerateVm` to generate it!");
|
||||||
}
|
}
|
||||||
if (!vmGenerator.ValidateMatch(_encryptionVmCodeFile))
|
if (!vmGenerator.ValidateMatch(encryptionVmCodeFile))
|
||||||
{
|
{
|
||||||
throw new Exception($"EncryptionVm CodeFile:`{_encryptionVmCodeFile}` not match with encryptionVM settings! Please run `Obfuz/GenerateVm` to update it!");
|
throw new Exception($"EncryptionVm CodeFile:`{encryptionVmCodeFile}` not match with encryptionVM settings! Please run `Obfuz/GenerateVm` to update it!");
|
||||||
}
|
}
|
||||||
var vms = new VirtualMachineSimulator(vm, secretKey);
|
var vms = new VirtualMachineSimulator(vm, secretKey);
|
||||||
|
|
||||||
|
@ -249,19 +230,19 @@ namespace Obfuz
|
||||||
{
|
{
|
||||||
int[] intSecretKey = KeyGenerator.ConvertToIntKey(byteSecret);
|
int[] intSecretKey = KeyGenerator.ConvertToIntKey(byteSecret);
|
||||||
IEncryptor encryption = CreateEncryptionVirtualMachine(byteSecret);
|
IEncryptor encryption = CreateEncryptionVirtualMachine(byteSecret);
|
||||||
RandomCreator localRandomCreator = (seed) => new RandomWithKey(intSecretKey, _randomSeed ^ seed);
|
RandomCreator localRandomCreator = (seed) => new RandomWithKey(intSecretKey, _coreSettings.randomSeed ^ seed);
|
||||||
return new EncryptionScopeInfo(encryption, localRandomCreator);
|
return new EncryptionScopeInfo(encryption, localRandomCreator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private EncryptionScopeProvider CreateEncryptionScopeProvider()
|
private EncryptionScopeProvider CreateEncryptionScopeProvider()
|
||||||
{
|
{
|
||||||
var defaultStaticScope = CreateEncryptionScope(_defaultStaticByteSecretKey);
|
var defaultStaticScope = CreateEncryptionScope(_coreSettings.defaultStaticSecretKey);
|
||||||
var defaultDynamicScope = CreateEncryptionScope(_defaultDynamicByteSecret);
|
var defaultDynamicScope = CreateEncryptionScope(_coreSettings.defaultDynamicSecretKey);
|
||||||
foreach (string dynamicAssName in _assembliesUsingDynamicSecretKeys)
|
foreach (string dynamicAssName in _assembliesUsingDynamicSecretKeys)
|
||||||
{
|
{
|
||||||
if (!_assembliesToObfuscate.Contains(dynamicAssName))
|
if (!_coreSettings.assembliesToObfuscate.Contains(dynamicAssName))
|
||||||
{
|
{
|
||||||
throw new Exception($"Dynamic secret assembly `{dynamicAssName}` should be in the toObfuscatedAssemblyNames list!");
|
throw new Exception($"Dynamic secret assembly `{dynamicAssName}` should be in the assembliesToObfuscate list!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new EncryptionScopeProvider(defaultStaticScope, defaultDynamicScope, _assembliesUsingDynamicSecretKeys);
|
return new EncryptionScopeProvider(defaultStaticScope, defaultDynamicScope, _assembliesUsingDynamicSecretKeys);
|
||||||
|
@ -280,12 +261,10 @@ namespace Obfuz
|
||||||
var constFieldAllocator = new ConstFieldAllocator(encryptionScopeProvider, rvaDataAllocator, moduleEntityManager);
|
var constFieldAllocator = new ConstFieldAllocator(encryptionScopeProvider, rvaDataAllocator, moduleEntityManager);
|
||||||
_ctx = new ObfuscationPassContext
|
_ctx = new ObfuscationPassContext
|
||||||
{
|
{
|
||||||
|
coreSettings = _coreSettings,
|
||||||
assemblyCache = assemblyCache,
|
assemblyCache = assemblyCache,
|
||||||
modulesToObfuscate = modulesToObfuscate,
|
modulesToObfuscate = modulesToObfuscate,
|
||||||
allObfuscationRelativeModules = allObfuscationRelativeModules,
|
allObfuscationRelativeModules = allObfuscationRelativeModules,
|
||||||
assembliesToObfuscate = _assembliesToObfuscate,
|
|
||||||
nonObfuscatedButReferencingObfuscatedAssemblies = _nonObfuscatedButReferencingObfuscatedAssemblies,
|
|
||||||
obfuscatedAssemblyOutputPath = _obfuscatedAssemblyOutputPath,
|
|
||||||
moduleEntityManager = moduleEntityManager,
|
moduleEntityManager = moduleEntityManager,
|
||||||
|
|
||||||
encryptionScopeProvider = encryptionScopeProvider,
|
encryptionScopeProvider = encryptionScopeProvider,
|
||||||
|
@ -301,7 +280,7 @@ namespace Obfuz
|
||||||
|
|
||||||
private void LoadAssemblies(AssemblyCache assemblyCache, List<ModuleDef> modulesToObfuscate, List<ModuleDef> allObfuscationRelativeModules)
|
private void LoadAssemblies(AssemblyCache assemblyCache, List<ModuleDef> modulesToObfuscate, List<ModuleDef> allObfuscationRelativeModules)
|
||||||
{
|
{
|
||||||
foreach (string assName in _assembliesToObfuscate.Concat(_nonObfuscatedButReferencingObfuscatedAssemblies))
|
foreach (string assName in _allObfuscationRelativeAssemblyNames)
|
||||||
{
|
{
|
||||||
ModuleDefMD mod = assemblyCache.TryLoadModule(assName);
|
ModuleDefMD mod = assemblyCache.TryLoadModule(assName);
|
||||||
if (mod == null)
|
if (mod == null)
|
||||||
|
@ -309,7 +288,7 @@ namespace Obfuz
|
||||||
Debug.Log($"assembly: {assName} not found! ignore.");
|
Debug.Log($"assembly: {assName} not found! ignore.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (_assembliesToObfuscate.Contains(assName))
|
if (_coreSettings.assembliesToObfuscate.Contains(assName))
|
||||||
{
|
{
|
||||||
modulesToObfuscate.Add(mod);
|
modulesToObfuscate.Add(mod);
|
||||||
}
|
}
|
||||||
|
@ -322,7 +301,7 @@ namespace Obfuz
|
||||||
foreach (ModuleDef mod in _ctx.allObfuscationRelativeModules)
|
foreach (ModuleDef mod in _ctx.allObfuscationRelativeModules)
|
||||||
{
|
{
|
||||||
string assNameWithExt = mod.Name;
|
string assNameWithExt = mod.Name;
|
||||||
string outputFile = $"{_obfuscatedAssemblyTempOutputPath}/{assNameWithExt}";
|
string outputFile = $"{_coreSettings.obfuscatedAssemblyTempOutputPath}/{assNameWithExt}";
|
||||||
mod.Write(outputFile);
|
mod.Write(outputFile);
|
||||||
Debug.Log($"save module. name:{mod.Assembly.Name} output:{outputFile}");
|
Debug.Log($"save module. name:{mod.Assembly.Name} output:{outputFile}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ using Obfuz.ObfusPasses.ExprObfus;
|
||||||
using Obfuz.ObfusPasses.FieldEncrypt;
|
using Obfuz.ObfusPasses.FieldEncrypt;
|
||||||
using Obfuz.ObfusPasses.SymbolObfus;
|
using Obfuz.ObfusPasses.SymbolObfus;
|
||||||
using Obfuz.Settings;
|
using Obfuz.Settings;
|
||||||
|
using Obfuz.Utils;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -13,148 +14,45 @@ using UnityEditor;
|
||||||
|
|
||||||
namespace Obfuz
|
namespace Obfuz
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public class CoreSettingsFacade
|
||||||
|
{
|
||||||
|
public BuildTarget buildTarget;
|
||||||
|
|
||||||
|
public byte[] defaultStaticSecretKey;
|
||||||
|
public byte[] defaultDynamicSecretKey;
|
||||||
|
public List<string> assembliesUsingDynamicSecretKeys;
|
||||||
|
public int randomSeed;
|
||||||
|
|
||||||
|
public string encryptionVmGenerationSecretKey;
|
||||||
|
public int encryptionVmOpCodeCount;
|
||||||
|
public string encryptionVmCodeFile;
|
||||||
|
|
||||||
|
public List<string> assembliesToObfuscate;
|
||||||
|
public List<string> nonObfuscatedButReferencingObfuscatedAssemblies;
|
||||||
|
public List<string> assemblySearchPaths;
|
||||||
|
public string obfuscatedAssemblyOutputPath;
|
||||||
|
public string obfuscatedAssemblyTempOutputPath;
|
||||||
|
|
||||||
|
public ObfuscationPassType enabledObfuscationPasses;
|
||||||
|
public List<string> obfuscationPassRuleConfigFiles;
|
||||||
|
public List<IObfuscationPass> obfuscationPasses;
|
||||||
|
}
|
||||||
|
|
||||||
public class ObfuscatorBuilder
|
public class ObfuscatorBuilder
|
||||||
{
|
{
|
||||||
private BuildTarget _buildTarget;
|
private CoreSettingsFacade _coreSettingsFacade;
|
||||||
|
|
||||||
private string _defaultStaticSecretKey;
|
public CoreSettingsFacade CoreSettingsFacade => _coreSettingsFacade;
|
||||||
private string _defaultStaticSecretKeyOutputPath;
|
|
||||||
private string _defaultDynamicSecretKey;
|
|
||||||
private string _defaultDynamicSecretKeyOutputPath;
|
|
||||||
private List<string> _assembliesUsingDynamicSecretKeys = new List<string>();
|
|
||||||
|
|
||||||
private int _randomSeed;
|
|
||||||
private string _encryptionVmGenerationSecretKey;
|
|
||||||
private int _encryptionVmOpCodeCount;
|
|
||||||
private string _encryptionVmCodeFile;
|
|
||||||
|
|
||||||
private List<string> _assembliesToObfuscate = new List<string>();
|
|
||||||
private List<string> _nonObfuscatedButReferencingObfuscatedAssemblies = new List<string>();
|
|
||||||
private List<string> _assemblySearchPaths = new List<string>();
|
|
||||||
|
|
||||||
private string _obfuscatedAssemblyTempOutputPath;
|
|
||||||
private string _obfuscatedAssemblyOutputPath;
|
|
||||||
private List<string> _obfuscationPassRuleConfigFiles;
|
|
||||||
|
|
||||||
private ObfuscationPassType _enabledObfuscationPasses;
|
|
||||||
private List<IObfuscationPass> _obfuscationPasses = new List<IObfuscationPass>();
|
|
||||||
|
|
||||||
public BuildTarget BuildTarget
|
|
||||||
{
|
|
||||||
get => _buildTarget;
|
|
||||||
set => _buildTarget = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DefaultStaticSecretKey
|
|
||||||
{
|
|
||||||
get => _defaultStaticSecretKey;
|
|
||||||
set => _defaultStaticSecretKey = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DefaultStaticSecretKeyOutputPath
|
|
||||||
{
|
|
||||||
get => _defaultStaticSecretKeyOutputPath;
|
|
||||||
set => _defaultStaticSecretKeyOutputPath = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DefaultDynamicSecretKey
|
|
||||||
{
|
|
||||||
get => _defaultDynamicSecretKey;
|
|
||||||
set => _defaultDynamicSecretKey = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string DefaultDynamicSecretKeyOutputPath
|
|
||||||
{
|
|
||||||
get => _defaultDynamicSecretKeyOutputPath;
|
|
||||||
set => _defaultDynamicSecretKeyOutputPath = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> AssembliesUsingDynamicSecretKeys
|
|
||||||
{
|
|
||||||
get => _assembliesUsingDynamicSecretKeys;
|
|
||||||
set => _assembliesUsingDynamicSecretKeys = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int RandomSeed
|
|
||||||
{
|
|
||||||
get => _randomSeed;
|
|
||||||
set => _randomSeed = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string EncryptionVmGenerationSecretKey
|
|
||||||
{
|
|
||||||
get => _encryptionVmGenerationSecretKey;
|
|
||||||
set => _encryptionVmGenerationSecretKey = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int EncryptionVmOpCodeCount
|
|
||||||
{
|
|
||||||
get => _encryptionVmOpCodeCount;
|
|
||||||
set => _encryptionVmOpCodeCount = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string EncryptionVmCodeFile
|
|
||||||
{
|
|
||||||
get => _encryptionVmCodeFile;
|
|
||||||
set => _encryptionVmCodeFile = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> AssembliesToObfuscate
|
|
||||||
{
|
|
||||||
get => _assembliesToObfuscate;
|
|
||||||
set => _assembliesToObfuscate = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> NonObfuscatedButReferencingObfuscatedAssemblies
|
|
||||||
{
|
|
||||||
get => _nonObfuscatedButReferencingObfuscatedAssemblies;
|
|
||||||
set => _nonObfuscatedButReferencingObfuscatedAssemblies = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> AssemblySearchPaths
|
|
||||||
{
|
|
||||||
get => _assemblySearchPaths;
|
|
||||||
set => _assemblySearchPaths = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ObfuscatedAssemblyOutputPath
|
|
||||||
{
|
|
||||||
get => _obfuscatedAssemblyOutputPath;
|
|
||||||
set => _obfuscatedAssemblyOutputPath = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ObfuscatedAssemblyTempOutputPath
|
|
||||||
{
|
|
||||||
get => _obfuscatedAssemblyTempOutputPath;
|
|
||||||
set => _obfuscatedAssemblyTempOutputPath = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType EnableObfuscationPasses
|
|
||||||
{
|
|
||||||
get => _enabledObfuscationPasses;
|
|
||||||
set => _enabledObfuscationPasses = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<string> ObfuscationPassRuleConfigFiles
|
|
||||||
{
|
|
||||||
get => _obfuscationPassRuleConfigFiles;
|
|
||||||
set => _obfuscationPassRuleConfigFiles = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<IObfuscationPass> ObfuscationPasses
|
|
||||||
{
|
|
||||||
get => _obfuscationPasses;
|
|
||||||
set => _obfuscationPasses = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertTopPriorityAssemblySearchPaths(List<string> assemblySearchPaths)
|
public void InsertTopPriorityAssemblySearchPaths(List<string> assemblySearchPaths)
|
||||||
{
|
{
|
||||||
_assemblySearchPaths.InsertRange(0, assemblySearchPaths);
|
_coreSettingsFacade.assemblySearchPaths.InsertRange(0, assemblySearchPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObfuscatorBuilder AddPass(IObfuscationPass pass)
|
public ObfuscatorBuilder AddPass(IObfuscationPass pass)
|
||||||
{
|
{
|
||||||
_obfuscationPasses.Add(pass);
|
_coreSettingsFacade.obfuscationPasses.Add(pass);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,8 +107,6 @@ namespace Obfuz
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform, please report to us"
|
#error "Unsupported platform, please report to us"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
"Managed/UnityEngine",
|
|
||||||
};
|
};
|
||||||
return searchPaths.Select(path => Path.Combine(applicationContentsPath, path)).ToList();
|
return searchPaths.Select(path => Path.Combine(applicationContentsPath, path)).ToList();
|
||||||
}
|
}
|
||||||
|
@ -222,36 +118,38 @@ namespace Obfuz
|
||||||
: settings.assemblySettings.additionalAssemblySearchPaths.ToList();
|
: settings.assemblySettings.additionalAssemblySearchPaths.ToList();
|
||||||
var builder = new ObfuscatorBuilder
|
var builder = new ObfuscatorBuilder
|
||||||
{
|
{
|
||||||
_buildTarget = target,
|
_coreSettingsFacade = new CoreSettingsFacade()
|
||||||
_defaultStaticSecretKey = settings.secretSettings.defaultStaticSecretKey,
|
{
|
||||||
_defaultStaticSecretKeyOutputPath = settings.secretSettings.staticSecretKeyOutputPath,
|
buildTarget = target,
|
||||||
_defaultDynamicSecretKey = settings.secretSettings.defaultDynamicSecretKey,
|
defaultStaticSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultStaticSecretKey, VirtualMachine.SecretKeyLength),
|
||||||
_defaultDynamicSecretKeyOutputPath = settings.secretSettings.dynamicSecretKeyOutputPath,
|
defaultDynamicSecretKey = KeyGenerator.GenerateKey(settings.secretSettings.defaultDynamicSecretKey, VirtualMachine.SecretKeyLength),
|
||||||
_assembliesUsingDynamicSecretKeys = settings.secretSettings.assembliesUsingDynamicSecretKeys.ToList(),
|
assembliesUsingDynamicSecretKeys = settings.secretSettings.assembliesUsingDynamicSecretKeys.ToList(),
|
||||||
_randomSeed = settings.secretSettings.randomSeed,
|
randomSeed = settings.secretSettings.randomSeed,
|
||||||
_encryptionVmGenerationSecretKey = settings.encryptionVMSettings.codeGenerationSecretKey,
|
encryptionVmGenerationSecretKey = settings.encryptionVMSettings.codeGenerationSecretKey,
|
||||||
_encryptionVmOpCodeCount = settings.encryptionVMSettings.encryptionOpCodeCount,
|
encryptionVmOpCodeCount = settings.encryptionVMSettings.encryptionOpCodeCount,
|
||||||
_encryptionVmCodeFile = settings.encryptionVMSettings.codeOutputPath,
|
encryptionVmCodeFile = settings.encryptionVMSettings.codeOutputPath,
|
||||||
_assembliesToObfuscate = settings.assemblySettings.GetAssembliesToObfuscate(),
|
assembliesToObfuscate = settings.assemblySettings.GetAssembliesToObfuscate(),
|
||||||
_nonObfuscatedButReferencingObfuscatedAssemblies = settings.assemblySettings.nonObfuscatedButReferencingObfuscatedAssemblies.ToList(),
|
nonObfuscatedButReferencingObfuscatedAssemblies = settings.assemblySettings.nonObfuscatedButReferencingObfuscatedAssemblies.ToList(),
|
||||||
_assemblySearchPaths = searchPaths,
|
assemblySearchPaths = searchPaths,
|
||||||
_obfuscatedAssemblyOutputPath = settings.GetObfuscatedAssemblyOutputPath(target),
|
obfuscatedAssemblyOutputPath = settings.GetObfuscatedAssemblyOutputPath(target),
|
||||||
_obfuscatedAssemblyTempOutputPath = settings.GetObfuscatedAssemblyTempOutputPath(target),
|
obfuscatedAssemblyTempOutputPath = settings.GetObfuscatedAssemblyTempOutputPath(target),
|
||||||
_enabledObfuscationPasses = settings.obfuscationPassSettings.enabledPasses,
|
enabledObfuscationPasses = settings.obfuscationPassSettings.enabledPasses,
|
||||||
_obfuscationPassRuleConfigFiles = settings.obfuscationPassSettings.ruleFiles.ToList(),
|
obfuscationPassRuleConfigFiles = settings.obfuscationPassSettings.ruleFiles.ToList(),
|
||||||
|
obfuscationPasses = new List<IObfuscationPass>(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
ObfuscationPassType obfuscationPasses = settings.obfuscationPassSettings.enabledPasses;
|
ObfuscationPassType obfuscationPasses = settings.obfuscationPassSettings.enabledPasses;
|
||||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.ConstEncrypt))
|
if (obfuscationPasses.HasFlag(ObfuscationPassType.ConstEncrypt))
|
||||||
{
|
{
|
||||||
builder.AddPass(new ConstEncryptPass(settings.constEncryptSettings));
|
builder.AddPass(new ConstEncryptPass(settings.constEncryptSettings.ToFacade()));
|
||||||
}
|
}
|
||||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.FieldEncrypt))
|
if (obfuscationPasses.HasFlag(ObfuscationPassType.FieldEncrypt))
|
||||||
{
|
{
|
||||||
builder.AddPass(new FieldEncryptPass(settings.fieldEncryptSettings));
|
builder.AddPass(new FieldEncryptPass(settings.fieldEncryptSettings.ToFacade()));
|
||||||
}
|
}
|
||||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.CallObfus))
|
if (obfuscationPasses.HasFlag(ObfuscationPassType.CallObfus))
|
||||||
{
|
{
|
||||||
builder.AddPass(new CallObfusPass(settings.callObfusSettings));
|
builder.AddPass(new CallObfusPass(settings.callObfusSettings.ToFacade()));
|
||||||
}
|
}
|
||||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.ExprObfus))
|
if (obfuscationPasses.HasFlag(ObfuscationPassType.ExprObfus))
|
||||||
{
|
{
|
||||||
|
@ -259,7 +157,7 @@ namespace Obfuz
|
||||||
}
|
}
|
||||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.SymbolObfus))
|
if (obfuscationPasses.HasFlag(ObfuscationPassType.SymbolObfus))
|
||||||
{
|
{
|
||||||
builder.AddPass(new SymbolObfusPass(settings.symbolObfusSettings));
|
builder.AddPass(new SymbolObfusPass(settings.symbolObfusSettings.ToFacade()));
|
||||||
}
|
}
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,13 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz.Settings
|
namespace Obfuz.Settings
|
||||||
{
|
{
|
||||||
|
public class CallObfuscationSettingsFacade
|
||||||
|
{
|
||||||
|
public List<string> ruleFiles;
|
||||||
|
public int obfuscationLevel;
|
||||||
|
public int maxProxyMethodCountPerDispatchMethod;
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class CallObfuscationSettings
|
public class CallObfuscationSettings
|
||||||
{
|
{
|
||||||
|
@ -19,5 +26,15 @@ namespace Obfuz.Settings
|
||||||
|
|
||||||
[Tooltip("rule config xml files")]
|
[Tooltip("rule config xml files")]
|
||||||
public string[] ruleFiles;
|
public string[] ruleFiles;
|
||||||
|
|
||||||
|
public CallObfuscationSettingsFacade ToFacade()
|
||||||
|
{
|
||||||
|
return new CallObfuscationSettingsFacade
|
||||||
|
{
|
||||||
|
ruleFiles = ruleFiles.ToList(),
|
||||||
|
obfuscationLevel = obfuscationLevel,
|
||||||
|
maxProxyMethodCountPerDispatchMethod = maxProxyMethodCountPerDispatchMethod,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,12 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz.Settings
|
namespace Obfuz.Settings
|
||||||
{
|
{
|
||||||
|
public class ConstEncryptionSettingsFacade
|
||||||
|
{
|
||||||
|
public int encryptionLevel;
|
||||||
|
public List<string> ruleFiles;
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ConstEncryptionSettings
|
public class ConstEncryptionSettings
|
||||||
{
|
{
|
||||||
|
@ -16,5 +22,14 @@ namespace Obfuz.Settings
|
||||||
|
|
||||||
[Tooltip("config xml files")]
|
[Tooltip("config xml files")]
|
||||||
public string[] ruleFiles;
|
public string[] ruleFiles;
|
||||||
|
|
||||||
|
public ConstEncryptionSettingsFacade ToFacade()
|
||||||
|
{
|
||||||
|
return new ConstEncryptionSettingsFacade
|
||||||
|
{
|
||||||
|
ruleFiles = ruleFiles.ToList(),
|
||||||
|
encryptionLevel = encryptionLevel,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,12 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz.Settings
|
namespace Obfuz.Settings
|
||||||
{
|
{
|
||||||
|
public class FieldEncryptionSettingsFacade
|
||||||
|
{
|
||||||
|
public int encryptionLevel;
|
||||||
|
public List<string> ruleFiles;
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class FieldEncryptionSettings
|
public class FieldEncryptionSettings
|
||||||
{
|
{
|
||||||
|
@ -16,5 +22,14 @@ namespace Obfuz.Settings
|
||||||
|
|
||||||
[Tooltip("rule config xml files")]
|
[Tooltip("rule config xml files")]
|
||||||
public string[] ruleFiles;
|
public string[] ruleFiles;
|
||||||
|
|
||||||
|
public FieldEncryptionSettingsFacade ToFacade()
|
||||||
|
{
|
||||||
|
return new FieldEncryptionSettingsFacade
|
||||||
|
{
|
||||||
|
ruleFiles = ruleFiles.ToList(),
|
||||||
|
encryptionLevel = encryptionLevel,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz.Settings
|
namespace Obfuz.Settings
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public class ObfuzSettings : ScriptableObject
|
public class ObfuzSettings : ScriptableObject
|
||||||
{
|
{
|
||||||
[Tooltip("enable Obfuz")]
|
[Tooltip("enable Obfuz")]
|
||||||
|
|
|
@ -7,6 +7,15 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace Obfuz.Settings
|
namespace Obfuz.Settings
|
||||||
{
|
{
|
||||||
|
public class SymbolObfuscationSettingsFacade
|
||||||
|
{
|
||||||
|
public bool debug;
|
||||||
|
public string obfuscatedNamePrefix;
|
||||||
|
public bool useConsistentNamespaceObfuscation;
|
||||||
|
public string symbolMappingFile;
|
||||||
|
public List<string> ruleFiles;
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class SymbolObfuscationSettings
|
public class SymbolObfuscationSettings
|
||||||
{
|
{
|
||||||
|
@ -23,5 +32,17 @@ namespace Obfuz.Settings
|
||||||
|
|
||||||
[Tooltip("rule files")]
|
[Tooltip("rule files")]
|
||||||
public string[] ruleFiles;
|
public string[] ruleFiles;
|
||||||
|
|
||||||
|
public SymbolObfuscationSettingsFacade ToFacade()
|
||||||
|
{
|
||||||
|
return new SymbolObfuscationSettingsFacade
|
||||||
|
{
|
||||||
|
debug = debug,
|
||||||
|
obfuscatedNamePrefix = obfuscatedNamePrefix,
|
||||||
|
useConsistentNamespaceObfuscation = useConsistentNamespaceObfuscation,
|
||||||
|
symbolMappingFile = symbolMappingFile,
|
||||||
|
ruleFiles = ruleFiles.ToList(),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,13 +98,13 @@ namespace Obfuz.Unity
|
||||||
};
|
};
|
||||||
obfuscatorBuilder.InsertTopPriorityAssemblySearchPaths(assemblySearchDirs);
|
obfuscatorBuilder.InsertTopPriorityAssemblySearchPaths(assemblySearchDirs);
|
||||||
|
|
||||||
ValidateReferences(stagingAreaTempManagedDllDir, new HashSet<string>(obfuscatorBuilder.AssembliesToObfuscate), obfuscationRelativeAssemblyNames);
|
ValidateReferences(stagingAreaTempManagedDllDir, new HashSet<string>(obfuscatorBuilder.CoreSettingsFacade.assembliesToObfuscate), obfuscationRelativeAssemblyNames);
|
||||||
|
|
||||||
|
|
||||||
OnObfuscationBegin?.Invoke(new ObfuscationBeginEventArgs
|
OnObfuscationBegin?.Invoke(new ObfuscationBeginEventArgs
|
||||||
{
|
{
|
||||||
scriptAssembliesPath = stagingAreaTempManagedDllDir,
|
scriptAssembliesPath = stagingAreaTempManagedDllDir,
|
||||||
obfuscatedScriptAssembliesPath = obfuscatorBuilder.ObfuscatedAssemblyOutputPath,
|
obfuscatedScriptAssembliesPath = obfuscatorBuilder.CoreSettingsFacade.obfuscatedAssemblyOutputPath,
|
||||||
});
|
});
|
||||||
bool succ = false;
|
bool succ = false;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ namespace Obfuz.Unity
|
||||||
|
|
||||||
foreach (var dllName in obfuscationRelativeAssemblyNames)
|
foreach (var dllName in obfuscationRelativeAssemblyNames)
|
||||||
{
|
{
|
||||||
string src = $"{obfuscatorBuilder.ObfuscatedAssemblyOutputPath}/{dllName}.dll";
|
string src = $"{obfuscatorBuilder.CoreSettingsFacade.obfuscatedAssemblyOutputPath}/{dllName}.dll";
|
||||||
string dst = $"{stagingAreaTempManagedDllDir}/{dllName}.dll";
|
string dst = $"{stagingAreaTempManagedDllDir}/{dllName}.dll";
|
||||||
|
|
||||||
if (!File.Exists(src))
|
if (!File.Exists(src))
|
||||||
|
|
Loading…
Reference in New Issue