重构ConstObfus为ConstEncrypt
parent
3094532eaa
commit
6fecb30c23
|
@ -1,7 +1,7 @@
|
|||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.ObfusPasses.ConstObfus.Policies;
|
||||
using Obfuz.ObfusPasses.ConstEncrypt.Policies;
|
||||
using Obfuz.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -11,24 +11,24 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
|
||||
public class ConstObfusPass : BasicBlockObfuscationPassBase
|
||||
public class ConstEncryptPass : BasicBlockObfuscationPassBase
|
||||
{
|
||||
private readonly string _configFile;
|
||||
private IObfuscationPolicy _dataObfuscatorPolicy;
|
||||
private IDataObfuscator _dataObfuscator;
|
||||
private IEncryptPolicy _dataObfuscatorPolicy;
|
||||
private IConstEncryptor _dataObfuscator;
|
||||
|
||||
public ConstObfusPass(ConstObfusSettings settings)
|
||||
public ConstEncryptPass(ConstEncryptSettings settings)
|
||||
{
|
||||
_configFile = settings.configFile;
|
||||
}
|
||||
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
_dataObfuscatorPolicy = new ConfigurableObfuscationPolicy(ctx.toObfuscatedAssemblyNames, _configFile);
|
||||
_dataObfuscator = new DefaultConstObfuscator();
|
||||
_dataObfuscatorPolicy = new ConfigurableEncryptPolicy(ctx.toObfuscatedAssemblyNames, _configFile);
|
||||
_dataObfuscator = new DefaultConstEncryptor();
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
|
@ -8,16 +8,16 @@ using System.Collections.Generic;
|
|||
using NUnit.Framework;
|
||||
using System.Text;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
public class DefaultConstObfuscator : IDataObfuscator
|
||||
public class DefaultConstEncryptor : IConstEncryptor
|
||||
{
|
||||
private readonly IRandom _random;
|
||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
||||
private readonly IEncryptor _encryptor;
|
||||
|
||||
public DefaultConstObfuscator()
|
||||
public DefaultConstEncryptor()
|
||||
{
|
||||
_random = new RandomWithKey(new byte[] { 0x1, 0x2, 0x3, 0x4 }, 0x5);
|
||||
_encryptor = new DefaultEncryptor(new byte[] { 0x1A, 0x2B, 0x3C, 0x4D });
|
|
@ -3,9 +3,9 @@ using dnlib.DotNet.Emit;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
public interface IDataObfuscator
|
||||
public interface IConstEncryptor
|
||||
{
|
||||
void ObfuscateInt(MethodDef method, bool needCacheValue, int value, List<Instruction> obfuscatedInstructions);
|
||||
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
public struct ConstCachePolicy
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace Obfuz.ObfusPasses.ConstObfus
|
|||
public bool cacheStringNotInLoop;
|
||||
}
|
||||
|
||||
public interface IObfuscationPolicy
|
||||
public interface IEncryptPolicy
|
||||
{
|
||||
bool NeedObfuscateMethod(MethodDef method);
|
||||
|
|
@ -8,9 +8,9 @@ using System.Threading.Tasks;
|
|||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus.Policies
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt.Policies
|
||||
{
|
||||
public class ConfigurableObfuscationPolicy : ObfuscationPolicyBase
|
||||
public class ConfigurableEncryptPolicy : EncryptPolicyBase
|
||||
{
|
||||
private readonly List<string> _toObfuscatedAssemblyNames;
|
||||
|
||||
|
@ -140,7 +140,7 @@ namespace Obfuz.ObfusPasses.ConstObfus.Policies
|
|||
private readonly Dictionary<string, AssemblySpec> _assemblySpecs = new Dictionary<string, AssemblySpec>();
|
||||
private readonly Dictionary<MethodDef, ObfuscationRule> _methodRuleCache = new Dictionary<MethodDef, ObfuscationRule>();
|
||||
|
||||
public ConfigurableObfuscationPolicy(List<string> toObfuscatedAssemblyNames, string xmlConfigFile)
|
||||
public ConfigurableEncryptPolicy(List<string> toObfuscatedAssemblyNames, string xmlConfigFile)
|
||||
{
|
||||
_toObfuscatedAssemblyNames = toObfuscatedAssemblyNames;
|
||||
LoadConfig(xmlConfigFile);
|
|
@ -1,8 +1,8 @@
|
|||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstObfus.Policies
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt.Policies
|
||||
{
|
||||
public abstract class ObfuscationPolicyBase : IObfuscationPolicy
|
||||
public abstract class EncryptPolicyBase : IEncryptPolicy
|
||||
{
|
||||
public abstract bool NeedObfuscateMethod(MethodDef method);
|
||||
public abstract ConstCachePolicy GetMethodConstCachePolicy(MethodDef method);
|
|
@ -1,7 +1,7 @@
|
|||
using Obfuz.ObfusPasses;
|
||||
using Obfuz.ObfusPasses.CallObfus;
|
||||
using Obfuz.ObfusPasses.CleanUp;
|
||||
using Obfuz.ObfusPasses.ConstObfus;
|
||||
using Obfuz.ObfusPasses.ConstEncrypt;
|
||||
using Obfuz.ObfusPasses.ExprObfus;
|
||||
using Obfuz.ObfusPasses.MemEncrypt;
|
||||
using Obfuz.ObfusPasses.SymbolObfus;
|
||||
|
@ -85,7 +85,7 @@ namespace Obfuz
|
|||
}
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.ConstEncryption))
|
||||
{
|
||||
builder.AddPass(new ConstObfusPass(settings.constObfusSettings));
|
||||
builder.AddPass(new ConstEncryptPass(settings.constEncryptSettings));
|
||||
}
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.ExprObfuscation))
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ using UnityEngine;
|
|||
namespace Obfuz.Settings
|
||||
{
|
||||
[Serializable]
|
||||
public class ConstObfusSettings
|
||||
public class ConstEncryptSettings
|
||||
{
|
||||
[Tooltip("config xml file")]
|
||||
public string configFile;
|
|
@ -29,8 +29,8 @@ namespace Obfuz.Settings
|
|||
[Tooltip("symbol obfuscation settings")]
|
||||
public SymbolObfusSettings symbolObfusSettings;
|
||||
|
||||
[Tooltip("const obfuscation settings")]
|
||||
public ConstObfusSettings constObfusSettings;
|
||||
[Tooltip("const encryption settings")]
|
||||
public ConstEncryptSettings constEncryptSettings;
|
||||
|
||||
public string ObfuzRootDir => $"Library/Obfuz";
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace Obfuz.Settings
|
|||
private SerializedProperty _enabledObfuscationPasses;
|
||||
|
||||
private SerializedProperty _symbolObfusSettings;
|
||||
private SerializedProperty _constObfusSettings;
|
||||
private SerializedProperty _constEncryptSettings;
|
||||
|
||||
public ObfuzSettingsProvider() : base("Project/Obfuz", SettingsScope.Project)
|
||||
{
|
||||
|
@ -65,7 +65,7 @@ namespace Obfuz.Settings
|
|||
_enabledObfuscationPasses = _serializedObject.FindProperty("enabledObfuscationPasses");
|
||||
|
||||
_symbolObfusSettings = _serializedObject.FindProperty("symbolObfusSettings");
|
||||
_constObfusSettings = _serializedObject.FindProperty("constObfusSettings");
|
||||
_constEncryptSettings = _serializedObject.FindProperty("constEncryptSettings");
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
|
@ -84,7 +84,7 @@ namespace Obfuz.Settings
|
|||
EditorGUILayout.PropertyField(_enabledObfuscationPasses);
|
||||
|
||||
EditorGUILayout.PropertyField(_symbolObfusSettings);
|
||||
EditorGUILayout.PropertyField(_constObfusSettings);
|
||||
EditorGUILayout.PropertyField(_constEncryptSettings);
|
||||
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
|
|
Loading…
Reference in New Issue