大规模重构

backup
walon 2025-05-04 19:55:10 +08:00
parent f7b08cc6cb
commit d741eed042
55 changed files with 111 additions and 101 deletions

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public class ConfigProxyCallPolicy : ProxyCallPolicyBase public class ConfigProxyCallPolicy : ProxyCallPolicyBase
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using Obfuz.Utils; using Obfuz.Utils;
using Obfuz.Emit; using Obfuz.Emit;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public class DefaultProxyCallObfuscator : ProxyCallObfuscatorBase public class DefaultProxyCallObfuscator : ProxyCallObfuscatorBase
{ {

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public interface IProxyCallObfuscator public interface IProxyCallObfuscator
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public interface IProxyCallPolicy public interface IProxyCallPolicy
{ {

View File

@ -2,7 +2,7 @@
using dnlib.DotNet; using dnlib.DotNet;
using System.Collections.Generic; using System.Collections.Generic;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public abstract class ProxyCallObfuscatorBase : IProxyCallObfuscator public abstract class ProxyCallObfuscatorBase : IProxyCallObfuscator
{ {

View File

@ -10,9 +10,9 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine.Assertions; using UnityEngine.Assertions;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public class ProxyCallPass : MethodBodyObfuscationPassBase public class ProxyCallPass : InstructionObfuscationPassBase
{ {
private readonly IRandom _random; private readonly IRandom _random;
private readonly IProxyCallPolicy _dynamicProxyPolicy; private readonly IProxyCallPolicy _dynamicProxyPolicy;

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.DynamicProxy namespace Obfuz.ObfusPasses.CallObfus
{ {
public abstract class ProxyCallPolicyBase : IProxyCallPolicy public abstract class ProxyCallPolicyBase : IProxyCallPolicy
{ {

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz namespace Obfuz.ObfusPasses.CleanUp
{ {
public class CleanUpInstructionPass : ObfuscationPassBase public class CleanUpInstructionPass : ObfuscationPassBase
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public class ConfigDataObfuscationPolicy : DataObfuscationPolicyBase public class ConfigDataObfuscationPolicy : DataObfuscationPolicyBase
{ {

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public abstract class DataObfuscationPolicyBase : IDataObfuscationPolicy public abstract class DataObfuscationPolicyBase : IDataObfuscationPolicy
{ {

View File

@ -8,10 +8,10 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine.Assertions; using UnityEngine.Assertions;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public class DataVirtualizationPass : MethodBodyObfuscationPassBase public class DataVirtualizationPass : InstructionObfuscationPassBase
{ {
private IDataObfuscationPolicy _dataObfuscatorPolicy; private IDataObfuscationPolicy _dataObfuscatorPolicy;
private IDataObfuscator _dataObfuscator; private IDataObfuscator _dataObfuscator;

View File

@ -5,7 +5,7 @@ using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public class DefaultDataObfuscator : IDataObfuscator public class DefaultDataObfuscator : IDataObfuscator
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public interface IDataObfuscationPolicy public interface IDataObfuscationPolicy
{ {

View File

@ -3,7 +3,7 @@ using dnlib.DotNet.Emit;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Obfuz.Virtualization namespace Obfuz.ObfusPasses.ConstObfus
{ {
public interface IDataObfuscator public interface IDataObfuscator
{ {

View File

@ -6,9 +6,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.ExprObfus namespace Obfuz.ObfusPasses.ExprObfus
{ {
public class ExprObfuscationPass : MethodBodyObfuscationPassBase public class ExprObfuscationPass : InstructionObfuscationPassBase
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz namespace Obfuz.ObfusPasses
{ {
public interface IObfuscationPass public interface IObfuscationPass
{ {

View File

@ -3,9 +3,9 @@ using dnlib.DotNet;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Obfuz namespace Obfuz.ObfusPasses
{ {
public abstract class MethodBodyObfuscationPassBase : ObfuscationPassBase public abstract class InstructionObfuscationPassBase : ObfuscationPassBase
{ {
protected abstract bool NeedObfuscateMethod(MethodDef method); protected abstract bool NeedObfuscateMethod(MethodDef method);

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public class ConfigEncryptionPolicy : EncryptionPolicyBase public class ConfigEncryptionPolicy : EncryptionPolicyBase
{ {

View File

@ -6,7 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.Assertions; using UnityEngine.Assertions;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public class DefaultMemoryEncryptor : MemoryEncryptorBase public class DefaultMemoryEncryptor : MemoryEncryptorBase
{ {

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public abstract class EncryptionPolicyBase : IEncryptionPolicy public abstract class EncryptionPolicyBase : IEncryptionPolicy
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public interface IEncryptionPolicy public interface IEncryptionPolicy
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public class MemoryEncryptionContext public class MemoryEncryptionContext
{ {

View File

@ -1,15 +1,15 @@
using dnlib.DotNet; using dnlib.DotNet;
using dnlib.DotNet.Emit; using dnlib.DotNet.Emit;
using Obfuz; using Obfuz;
using Obfuz.MemEncrypt; using Obfuz.ObfusPasses.MemEncrypt;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public class MemoryEncryptionPass : MethodBodyObfuscationPassBase public class MemoryEncryptionPass : InstructionObfuscationPassBase
{ {
private readonly IEncryptionPolicy _encryptionPolicy = new ConfigEncryptionPolicy(); private readonly IEncryptionPolicy _encryptionPolicy = new ConfigEncryptionPolicy();
private readonly IMemoryEncryptor _memoryEncryptor = new DefaultMemoryEncryptor(); private readonly IMemoryEncryptor _memoryEncryptor = new DefaultMemoryEncryptor();

View File

@ -2,7 +2,7 @@
using dnlib.DotNet.Emit; using dnlib.DotNet.Emit;
using System.Collections.Generic; using System.Collections.Generic;
namespace Obfuz.MemEncrypt namespace Obfuz.ObfusPasses.MemEncrypt
{ {
public abstract class MemoryEncryptorBase : IMemoryEncryptor public abstract class MemoryEncryptorBase : IMemoryEncryptor
{ {

View File

@ -1,6 +1,6 @@
using Obfuz.Emit; using Obfuz.Emit;
namespace Obfuz namespace Obfuz.ObfusPasses
{ {
public abstract class ObfuscationPassBase : IObfuscationPass public abstract class ObfuscationPassBase : IObfuscationPass
{ {

View File

@ -1,5 +1,5 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Rename; using Obfuz.ObfusPasses.SymbolObfus;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -7,7 +7,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz namespace Obfuz.ObfusPasses
{ {
public class ObfuscationPassContext public class ObfuscationPassContext

View File

@ -0,0 +1,23 @@
using System;
namespace Obfuz.ObfusPasses
{
[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,
}
}

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class CacheRenamePolicy : RenamePolicyBase public class CacheRenamePolicy : RenamePolicyBase
{ {

View File

@ -1,7 +1,7 @@
using dnlib.DotNet; using dnlib.DotNet;
using System.Linq; using System.Linq;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class CombineRenamePolicy : IRenamePolicy public class CombineRenamePolicy : IRenamePolicy
{ {

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public interface INameMaker public interface INameMaker
{ {

View File

@ -1,4 +1,4 @@
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public interface INameScope public interface INameScope
{ {

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public interface IRenamePolicy public interface IRenamePolicy
{ {

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class NameMaker : NameMakerBase public class NameMaker : NameMakerBase

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public abstract class NameMakerBase : INameMaker public abstract class NameMakerBase : INameMaker
{ {

View File

@ -5,7 +5,7 @@ using System.Runtime.Remoting.Messaging;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public static class NameMakerFactory public static class NameMakerFactory
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class NameScope : NameScopeBase public class NameScope : NameScopeBase

View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public abstract class NameScopeBase : INameScope public abstract class NameScopeBase : INameScope
{ {

View File

@ -1,5 +1,4 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Rename;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -9,7 +8,7 @@ using System.Threading.Tasks;
using System.Xml; using System.Xml;
using UnityEngine; using UnityEngine;
namespace Obfuz namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class ObfuscateRuleConfig : RenamePolicyBase public class ObfuscateRuleConfig : RenamePolicyBase

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public abstract class RenamePolicyBase : IRenamePolicy public abstract class RenamePolicyBase : IRenamePolicy
{ {

View File

@ -1,5 +1,4 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Rename;
using Obfuz.Utils; using Obfuz.Utils;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -10,7 +9,7 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using UnityEngine; using UnityEngine;
namespace Obfuz namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class RenameRecordMap public class RenameRecordMap

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class RenameSymbolPass : ObfuscationPassBase public class RenameSymbolPass : ObfuscationPassBase
{ {

View File

@ -1,5 +1,5 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Rename; using Obfuz.ObfusPasses.SymbolObfus;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections; using System.Collections;
@ -12,10 +12,8 @@ using UnityEditor.SceneManagement;
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions; using UnityEngine.Assertions;
namespace Obfuz namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class SymbolRename public class SymbolRename
{ {
class AssemblyReferenceInfo class AssemblyReferenceInfo

View File

@ -1,6 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class SystemRenamePolicy : RenamePolicyBase public class SystemRenamePolicy : RenamePolicyBase
{ {

View File

@ -1,6 +1,6 @@
using System.Text; using System.Text;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class TestNameMaker : NameMakerBase public class TestNameMaker : NameMakerBase
{ {

View File

@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class UnityRenamePolicy : RenamePolicyBase public class UnityRenamePolicy : RenamePolicyBase

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Obfuz.Rename namespace Obfuz.ObfusPasses.SymbolObfus
{ {
public class VirtualMethodGroup public class VirtualMethodGroup

View File

@ -1,5 +1,6 @@
using dnlib.DotNet; using dnlib.DotNet;
using Obfuz.Emit; using Obfuz.Emit;
using Obfuz.ObfusPasses;
using Obfuz.Utils; using Obfuz.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -42,8 +43,6 @@ namespace Obfuz
{ {
_pipeline.AddPass(pass); _pipeline.AddPass(pass);
} }
_pipeline.AddPass(new CleanUpInstructionPass());
} }
public void Run() public void Run()

View File

@ -1,11 +1,14 @@
using Obfuz.DynamicProxy; using Obfuz.ObfusPasses;
using Obfuz.MemEncrypt; using Obfuz.ObfusPasses.CallObfus;
using Obfuz.Rename; using Obfuz.ObfusPasses.CleanUp;
using Obfuz.ObfusPasses.ConstObfus;
using Obfuz.ObfusPasses.ExprObfus;
using Obfuz.ObfusPasses.MemEncrypt;
using Obfuz.ObfusPasses.SymbolObfus;
using Obfuz.Settings;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Obfuz.Virtualization;
using UnityEditor; using UnityEditor;
using Obfuz.ExprObfus;
namespace Obfuz namespace Obfuz
{ {
@ -92,6 +95,7 @@ namespace Obfuz
{ {
builder.AddPass(new RenameSymbolPass(settings.ruleFiles.ToList(), settings.mappingFile)); builder.AddPass(new RenameSymbolPass(settings.ruleFiles.ToList(), settings.mappingFile));
} }
builder.AddPass(new CleanUpInstructionPass());
return builder; return builder;
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using Obfuz.ObfusPasses;
using System.Collections.Generic;
namespace Obfuz namespace Obfuz
{ {

View File

@ -1,4 +1,4 @@
using System; using Obfuz.ObfusPasses;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Messaging;
@ -6,26 +6,8 @@ using UnityEditor;
using UnityEditorInternal; using UnityEditorInternal;
using UnityEngine; using UnityEngine;
namespace Obfuz namespace Obfuz.Settings
{ {
[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
{ {

View File

@ -5,7 +5,7 @@ using UnityEditor.Presets;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements; using UnityEngine.UIElements;
namespace Obfuz namespace Obfuz.Settings
{ {
public class ObfuzSettingsProvider : SettingsProvider public class ObfuzSettingsProvider : SettingsProvider
{ {

View File

@ -0,0 +1,8 @@
namespace Obfuz.Unity
{
public class ObfuscationBeginEventArgs
{
public string scriptAssembliesPath;
public string obfuscatedScriptAssembliesPath;
}
}

View File

@ -0,0 +1,9 @@
namespace Obfuz.Unity
{
public class ObfuscationEndEventArgs
{
public bool success;
public string originalScriptAssembliesPath;
public string obfuscatedScriptAssembliesPath;
}
}

View File

@ -11,8 +11,9 @@ using UnityEngine;
using UnityEditor.Compilation; using UnityEditor.Compilation;
using Obfuz.Utils; using Obfuz.Utils;
using FileUtil = Obfuz.Utils.FileUtil; using FileUtil = Obfuz.Utils.FileUtil;
using Obfuz.Settings;
namespace Obfuz.BuildProcess namespace Obfuz.Unity
{ {
#if UNITY_2019_1_OR_NEWER #if UNITY_2019_1_OR_NEWER
@ -22,19 +23,6 @@ namespace Obfuz.BuildProcess
public int callbackOrder => 10000; public int callbackOrder => 10000;
public class ObfuscationBeginEventArgs : EventArgs
{
public string scriptAssembliesPath;
public string obfuscatedScriptAssembliesPath;
}
public class ObfuscationEndEventArgs : EventArgs
{
public bool success;
public string originalScriptAssembliesPath;
public string obfuscatedScriptAssembliesPath;
}
public static event Action<ObfuscationBeginEventArgs> OnObfuscationBegin; public static event Action<ObfuscationBeginEventArgs> OnObfuscationBegin;
public static event Action<ObfuscationEndEventArgs> OnObfuscationEnd; public static event Action<ObfuscationEndEventArgs> OnObfuscationEnd;

View File

@ -1,7 +1,7 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Obfuz namespace Obfuz.Unity
{ {
public static class ObfuzMenu public static class ObfuzMenu
{ {