重构,允许通过 enabledObfuscationPasses设置开启哪些Pass

backup
walon 2025-05-03 22:00:59 +08:00
parent c30abd5977
commit 291bcd7529
4 changed files with 46 additions and 10 deletions

View File

@ -43,11 +43,6 @@ namespace Obfuz
_pipeline.AddPass(pass); _pipeline.AddPass(pass);
} }
//_pipeline.AddPass(new MemoryEncryptionPass());
////_pipeline.AddPass(new ProxyCallPass());
//_pipeline.AddPass(new ExprObfuscationPass());
//_pipeline.AddPass(new DataVirtualizationPass());
//_pipeline.AddPass(new RenameSymbolPass());
_pipeline.AddPass(new CleanUpInstructionPass()); _pipeline.AddPass(new CleanUpInstructionPass());

View File

@ -71,11 +71,27 @@ namespace Obfuz
_assemblySearchDirs = settings.extraAssemblySearchDirs.ToList(), _assemblySearchDirs = settings.extraAssemblySearchDirs.ToList(),
_obfuscatedAssemblyOutputDir = settings.GetObfuscatedAssemblyOutputDir(target), _obfuscatedAssemblyOutputDir = settings.GetObfuscatedAssemblyOutputDir(target),
}; };
builder.AddPass(new MemoryEncryptionPass()); ObfuscationPassType obfuscationPasses = settings.enabledObfuscationPasses;
builder.AddPass(new ProxyCallPass()); if (obfuscationPasses.HasFlag(ObfuscationPassType.MemoryEncryption))
builder.AddPass(new ExprObfuscationPass()); {
builder.AddPass(new DataVirtualizationPass()); builder.AddPass(new MemoryEncryptionPass());
builder.AddPass(new RenameSymbolPass(settings.ruleFiles.ToList(), settings.mappingFile)); }
if (obfuscationPasses.HasFlag(ObfuscationPassType.CallProxy))
{
builder.AddPass(new ProxyCallPass());
}
if (obfuscationPasses.HasFlag(ObfuscationPassType.ConstEncryption))
{
builder.AddPass(new DataVirtualizationPass());
}
if (obfuscationPasses.HasFlag(ObfuscationPassType.ExprObfuscation))
{
builder.AddPass(new ExprObfuscationPass());
}
if (obfuscationPasses.HasFlag(ObfuscationPassType.SymbolObfuscation))
{
builder.AddPass(new RenameSymbolPass(settings.ruleFiles.ToList(), settings.mappingFile));
}
return builder; return builder;
} }
} }

View File

@ -31,6 +31,7 @@ namespace Obfuz
private SerializedProperty _enable; private SerializedProperty _enable;
private SerializedProperty _toObfuscatedAssemblyNames; private SerializedProperty _toObfuscatedAssemblyNames;
private SerializedProperty _notObfuscatedAssemblyNamesReferencingObfuscated; private SerializedProperty _notObfuscatedAssemblyNamesReferencingObfuscated;
private SerializedProperty _enabledObfuscationPasses;
private SerializedProperty _mappingFile; private SerializedProperty _mappingFile;
private SerializedProperty _ruleFiles; private SerializedProperty _ruleFiles;
private SerializedProperty _extraAssemblySearchDirs; private SerializedProperty _extraAssemblySearchDirs;
@ -53,6 +54,7 @@ namespace Obfuz
_enable = _serializedObject.FindProperty("enable"); _enable = _serializedObject.FindProperty("enable");
_toObfuscatedAssemblyNames = _serializedObject.FindProperty("toObfuscatedAssemblyNames"); _toObfuscatedAssemblyNames = _serializedObject.FindProperty("toObfuscatedAssemblyNames");
_notObfuscatedAssemblyNamesReferencingObfuscated = _serializedObject.FindProperty("notObfuscatedAssemblyNamesReferencingObfuscated"); _notObfuscatedAssemblyNamesReferencingObfuscated = _serializedObject.FindProperty("notObfuscatedAssemblyNamesReferencingObfuscated");
_enabledObfuscationPasses = _serializedObject.FindProperty("enabledObfuscationPasses");
_mappingFile = _serializedObject.FindProperty("mappingFile"); _mappingFile = _serializedObject.FindProperty("mappingFile");
_ruleFiles = _serializedObject.FindProperty("ruleFiles"); _ruleFiles = _serializedObject.FindProperty("ruleFiles");
_extraAssemblySearchDirs = _serializedObject.FindProperty("extraAssemblySearchDirs"); _extraAssemblySearchDirs = _serializedObject.FindProperty("extraAssemblySearchDirs");
@ -78,6 +80,7 @@ namespace Obfuz
EditorGUILayout.PropertyField(_enable); EditorGUILayout.PropertyField(_enable);
EditorGUILayout.PropertyField(_toObfuscatedAssemblyNames); EditorGUILayout.PropertyField(_toObfuscatedAssemblyNames);
EditorGUILayout.PropertyField(_notObfuscatedAssemblyNamesReferencingObfuscated); EditorGUILayout.PropertyField(_notObfuscatedAssemblyNamesReferencingObfuscated);
EditorGUILayout.PropertyField(_enabledObfuscationPasses);
EditorGUILayout.PropertyField(_mappingFile); EditorGUILayout.PropertyField(_mappingFile);
EditorGUILayout.PropertyField(_ruleFiles); EditorGUILayout.PropertyField(_ruleFiles);
EditorGUILayout.PropertyField(_extraAssemblySearchDirs); EditorGUILayout.PropertyField(_extraAssemblySearchDirs);

View File

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Messaging;
@ -7,6 +8,24 @@ using UnityEngine;
namespace Obfuz namespace Obfuz
{ {
[Flags]
public enum ObfuscationPassType
{
None = 0,
ConstEncryption = 0x1,
MemoryEncryption = 0x2,
SymbolObfuscation = 0x100,
CallProxy = 0x200,
ExprObfuscation = 0x400,
ControlFlowObfuscation = 0x800,
AllDataEncryption = ConstEncryption | MemoryEncryption,
AllCodeObfuscation = SymbolObfuscation | CallProxy | ExprObfuscation | ControlFlowObfuscation,
All = AllDataEncryption | AllCodeObfuscation,
}
public class ObfuzSettings : ScriptableObject public class ObfuzSettings : ScriptableObject
{ {
@ -19,6 +38,9 @@ namespace Obfuz
[Tooltip("name of assemblies not obfuscated but reference assemblies to obfuscated ")] [Tooltip("name of assemblies not obfuscated but reference assemblies to obfuscated ")]
public string[] notObfuscatedAssemblyNamesReferencingObfuscated; public string[] notObfuscatedAssemblyNamesReferencingObfuscated;
[Tooltip("enable obfuscation pass")]
public ObfuscationPassType enabledObfuscationPasses = ObfuscationPassType.All;
[Tooltip("path of mapping.xml")] [Tooltip("path of mapping.xml")]
public string mappingFile = "Assets/Obfuz/mapping.xml"; public string mappingFile = "Assets/Obfuz/mapping.xml";