大规模重构,调整目录结构
parent
0686c0e6da
commit
f7b08cc6cb
|
@ -7,16 +7,16 @@ using System.Threading.Tasks;
|
|||
using UnityEditor.Build;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Compilation;
|
||||
using System.Reflection;
|
||||
using Obfuz.Utils;
|
||||
using FileUtil = Obfuz.Utils.FileUtil;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.BuildProcess
|
||||
{
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
public class ObfuzProcess : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
public class ObfuscationProcess : IPreprocessBuildWithReport, IPostprocessBuildWithReport
|
||||
{
|
||||
private static bool s_obfuscated = false;
|
||||
|
|
@ -72,7 +72,7 @@ namespace Obfuz.Emit
|
|||
if (_rvaTypeDef == null)
|
||||
{
|
||||
_module.EnableTypeDefFindCache = false;
|
||||
//_rvaTypeDef = _module.Find("$ObfuzRVA$", false);
|
||||
//_rvaTypeDef = _module.Find("$ObfuzRVA$", true);
|
||||
//if (_rvaTypeDef != null)
|
||||
//{
|
||||
// throw new Exception($"can't obfuscate a obfuscated assembly");
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
#if USE_HYBRIDCLR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.Menus
|
||||
{
|
||||
public static class HybridCLRMenu
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,12 +25,12 @@ namespace Obfuz.DynamicProxy
|
|||
_dynamicProxyObfuscator = new DefaultProxyCallObfuscator(_random);
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
_dynamicProxyObfuscator.Done();
|
||||
}
|
||||
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
|
@ -10,16 +10,16 @@ namespace Obfuz
|
|||
{
|
||||
public class CleanUpInstructionPass : ObfuscationPassBase
|
||||
{
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Process(ObfuscatorContext ctx)
|
||||
public override void Process(ObfuscationPassContext ctx)
|
||||
{
|
||||
foreach (ModuleDef mod in ctx.toObfuscatedModules)
|
||||
{
|
|
@ -16,13 +16,13 @@ namespace Obfuz.Virtualization
|
|||
private IDataObfuscationPolicy _dataObfuscatorPolicy;
|
||||
private IDataObfuscator _dataObfuscator;
|
||||
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
_dataObfuscatorPolicy = new ConfigDataObfuscationPolicy();
|
||||
_dataObfuscator = new DefaultDataObfuscator();
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
_dataObfuscator.Done();
|
||||
}
|
|
@ -6,18 +6,18 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz.ExprObfuscation
|
||||
namespace Obfuz.ExprObfus
|
||||
{
|
||||
public class ExprObfuscationPass : MethodBodyObfuscationPassBase
|
||||
{
|
||||
|
||||
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
|
@ -8,10 +8,10 @@ namespace Obfuz
|
|||
{
|
||||
public interface IObfuscationPass
|
||||
{
|
||||
void Start(ObfuscatorContext ctx);
|
||||
void Start(ObfuscationPassContext ctx);
|
||||
|
||||
void Stop(ObfuscatorContext ctx);
|
||||
void Stop(ObfuscationPassContext ctx);
|
||||
|
||||
void Process(ObfuscatorContext ctx);
|
||||
void Process(ObfuscationPassContext ctx);
|
||||
}
|
||||
}
|
|
@ -14,12 +14,12 @@ namespace Obfuz.MemEncrypt
|
|||
private readonly IEncryptionPolicy _encryptionPolicy = new ConfigEncryptionPolicy();
|
||||
private readonly IMemoryEncryptor _memoryEncryptor = new DefaultMemoryEncryptor();
|
||||
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ namespace Obfuz
|
|||
{
|
||||
protected abstract bool NeedObfuscateMethod(MethodDef method);
|
||||
|
||||
public override void Process(ObfuscatorContext ctx)
|
||||
public override void Process(ObfuscationPassContext ctx)
|
||||
{
|
||||
foreach (ModuleDef mod in ctx.toObfuscatedModules)
|
||||
{
|
|
@ -0,0 +1,13 @@
|
|||
using Obfuz.Emit;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
public abstract class ObfuscationPassBase : IObfuscationPass
|
||||
{
|
||||
public abstract void Start(ObfuscationPassContext ctx);
|
||||
|
||||
public abstract void Stop(ObfuscationPassContext ctx);
|
||||
|
||||
public abstract void Process(ObfuscationPassContext ctx);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using dnlib.DotNet;
|
||||
using Obfuz.Rename;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -9,7 +10,7 @@ using System.Threading.Tasks;
|
|||
namespace Obfuz
|
||||
{
|
||||
|
||||
public class ObfuscatorContext
|
||||
public class ObfuscationPassContext
|
||||
{
|
||||
public AssemblyCache assemblyCache;
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using dnlib.DotNet;
|
||||
using Obfuz.Rename;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
|
@ -15,17 +15,17 @@ namespace Obfuz.Rename
|
|||
_symbolRename = new SymbolRename(mappingXmlPath, obfuscationRuleFiles);
|
||||
}
|
||||
|
||||
public override void Start(ObfuscatorContext ctx)
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
_symbolRename.Init(ctx);
|
||||
}
|
||||
|
||||
public override void Stop(ObfuscatorContext ctx)
|
||||
public override void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
_symbolRename.Save();
|
||||
}
|
||||
|
||||
public override void Process(ObfuscatorContext ctx)
|
||||
public override void Process(ObfuscationPassContext ctx)
|
||||
{
|
||||
_symbolRename.Process();
|
||||
}
|
|
@ -61,7 +61,7 @@ namespace Obfuz
|
|||
_virtualMethodGroupCalculator = new VirtualMethodGroupCalculator();
|
||||
}
|
||||
|
||||
public void Init(ObfuscatorContext ctx)
|
||||
public void Init(ObfuscationPassContext ctx)
|
||||
{
|
||||
_assemblyCache = ctx.assemblyCache;
|
||||
_toObfuscatedModules = ctx.toObfuscatedModules;
|
||||
|
@ -75,7 +75,7 @@ namespace Obfuz
|
|||
BuildCustomAttributeArguments();
|
||||
}
|
||||
|
||||
private static List<AssemblyReferenceInfo> BuildAssemblyReferenceInfos(ObfuscatorContext ctx)
|
||||
private static List<AssemblyReferenceInfo> BuildAssemblyReferenceInfos(ObfuscationPassContext ctx)
|
||||
{
|
||||
var obfuzAssemblies = new List<AssemblyReferenceInfo>();
|
||||
foreach (ModuleDef mod in ctx.obfuscatedAndNotObfuscatedModules)
|
|
@ -9,7 +9,7 @@ namespace Obfuz.Rename
|
|||
private int _nextIndex;
|
||||
protected override void BuildNewName(StringBuilder nameBuilder, string originalName)
|
||||
{
|
||||
nameBuilder.Append($"{originalName}>{_nextIndex++}");
|
||||
nameBuilder.Append($"<{originalName}>{_nextIndex++}");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
using Obfuz.Emit;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
public abstract class ObfuscationPassBase : IObfuscationPass
|
||||
{
|
||||
public abstract void Start(ObfuscatorContext ctx);
|
||||
|
||||
public abstract void Stop(ObfuscatorContext ctx);
|
||||
|
||||
public abstract void Process(ObfuscatorContext ctx);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using dnlib.DotNet;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -21,9 +22,9 @@ namespace Obfuz
|
|||
private readonly List<ModuleDef> _toObfuscatedModules = new List<ModuleDef>();
|
||||
private readonly List<ModuleDef> _obfuscatedAndNotObfuscatedModules = new List<ModuleDef>();
|
||||
|
||||
private readonly ObfuzPipeline _pipeline = new ObfuzPipeline();
|
||||
private readonly Pipeline _pipeline = new Pipeline();
|
||||
|
||||
private ObfuscatorContext _ctx;
|
||||
private ObfuscationPassContext _ctx;
|
||||
|
||||
public Obfuscator(List<string> toObfuscatedAssemblyNames,
|
||||
List<string> notObfuscatedAssemblyNamesReferencingObfuscated,
|
||||
|
@ -43,8 +44,6 @@ namespace Obfuz
|
|||
}
|
||||
|
||||
_pipeline.AddPass(new CleanUpInstructionPass());
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
@ -58,8 +57,7 @@ namespace Obfuz
|
|||
{
|
||||
LoadAssemblies();
|
||||
|
||||
|
||||
_ctx = new ObfuscatorContext
|
||||
_ctx = new ObfuscationPassContext
|
||||
{
|
||||
assemblyCache = _assemblyCache,
|
||||
toObfuscatedModules = _toObfuscatedModules,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using Obfuz.DynamicProxy;
|
||||
using Obfuz.ExprObfuscation;
|
||||
using Obfuz.MemEncrypt;
|
||||
using Obfuz.Rename;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Obfuz.Virtualization;
|
||||
using UnityEditor;
|
||||
using Obfuz.ExprObfus;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
namespace Obfuz
|
||||
{
|
||||
public class ObfuzPipeline
|
||||
public class Pipeline
|
||||
{
|
||||
private readonly List<IObfuscationPass> _passes = new List<IObfuscationPass>();
|
||||
|
||||
public ObfuzPipeline AddPass(IObfuscationPass pass)
|
||||
public Pipeline AddPass(IObfuscationPass pass)
|
||||
{
|
||||
_passes.Add(pass);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Start(ObfuscatorContext ctx)
|
||||
public void Start(ObfuscationPassContext ctx)
|
||||
{
|
||||
foreach (var pass in _passes)
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace Obfuz
|
|||
}
|
||||
}
|
||||
|
||||
public void Stop(ObfuscatorContext ctx)
|
||||
public void Stop(ObfuscationPassContext ctx)
|
||||
{
|
||||
|
||||
foreach (var pass in _passes)
|
||||
|
@ -29,7 +29,7 @@ namespace Obfuz
|
|||
}
|
||||
}
|
||||
|
||||
public void Run(ObfuscatorContext ctx)
|
||||
public void Run(ObfuscationPassContext ctx)
|
||||
{
|
||||
foreach (var pass in _passes)
|
||||
{
|
|
@ -1,28 +0,0 @@
|
|||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class EditorStatusWatcher
|
||||
{
|
||||
public static Action OnEditorFocused;
|
||||
static bool isFocused;
|
||||
static EditorStatusWatcher() => EditorApplication.update += Update;
|
||||
static void Update()
|
||||
{
|
||||
if (isFocused != InternalEditorUtility.isApplicationActive)
|
||||
{
|
||||
isFocused = InternalEditorUtility.isApplicationActive;
|
||||
if (isFocused)
|
||||
{
|
||||
_ = ObfuzSettings.Instance;
|
||||
OnEditorFocused?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -42,10 +42,15 @@ namespace Obfuz
|
|||
|
||||
public override void OnActivate(string searchContext, VisualElement rootElement)
|
||||
{
|
||||
EditorStatusWatcher.OnEditorFocused += OnEditorFocused;
|
||||
InitGUI();
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
base.OnDeactivate();
|
||||
ObfuzSettings.Save();
|
||||
}
|
||||
|
||||
private void InitGUI()
|
||||
{
|
||||
var setting = ObfuzSettings.Instance;
|
||||
|
@ -60,51 +65,28 @@ namespace Obfuz
|
|||
_extraAssemblySearchDirs = _serializedObject.FindProperty("extraAssemblySearchDirs");
|
||||
}
|
||||
|
||||
private void OnEditorFocused()
|
||||
{
|
||||
InitGUI();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
public override void OnGUI(string searchContext)
|
||||
{
|
||||
using (CreateSettingsWindowGUIScope())
|
||||
if (_serializedObject == null||!_serializedObject.targetObject)
|
||||
{
|
||||
if (_serializedObject == null||!_serializedObject.targetObject)
|
||||
{
|
||||
InitGUI();
|
||||
}
|
||||
_serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(_enable);
|
||||
EditorGUILayout.PropertyField(_toObfuscatedAssemblyNames);
|
||||
EditorGUILayout.PropertyField(_notObfuscatedAssemblyNamesReferencingObfuscated);
|
||||
EditorGUILayout.PropertyField(_enabledObfuscationPasses);
|
||||
EditorGUILayout.PropertyField(_mappingFile);
|
||||
EditorGUILayout.PropertyField(_ruleFiles);
|
||||
EditorGUILayout.PropertyField(_extraAssemblySearchDirs);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
ObfuzSettings.Save();
|
||||
}
|
||||
InitGUI();
|
||||
}
|
||||
}
|
||||
_serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
private IDisposable CreateSettingsWindowGUIScope()
|
||||
{
|
||||
var unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
|
||||
var type = unityEditorAssembly.GetType("UnityEditor.SettingsWindow+GUIScope");
|
||||
return Activator.CreateInstance(type) as IDisposable;
|
||||
}
|
||||
EditorGUILayout.PropertyField(_enable);
|
||||
EditorGUILayout.PropertyField(_toObfuscatedAssemblyNames);
|
||||
EditorGUILayout.PropertyField(_notObfuscatedAssemblyNamesReferencingObfuscated);
|
||||
EditorGUILayout.PropertyField(_enabledObfuscationPasses);
|
||||
EditorGUILayout.PropertyField(_mappingFile);
|
||||
EditorGUILayout.PropertyField(_ruleFiles);
|
||||
EditorGUILayout.PropertyField(_extraAssemblySearchDirs);
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
base.OnDeactivate();
|
||||
EditorStatusWatcher.OnEditorFocused -= OnEditorFocused;
|
||||
ObfuzSettings.Save();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_serializedObject.ApplyModifiedProperties();
|
||||
ObfuzSettings.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public class AssemblyCache
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public abstract class AssemblyResolverBase : IAssemblyResolver
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public static class CollectionExtensions
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ namespace Obfuz
|
|||
}
|
||||
}
|
||||
|
||||
public static V GetValueOrDefault<K, V>(this IDictionary<K, V> dic, K key)
|
||||
public static V GetValueOrDefault<K, V>(this Dictionary<K, V> dic, K key)
|
||||
{
|
||||
return dic.TryGetValue(key, out V v) ? v : default(V);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public static class FileUtil
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public static class HashUtil
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public interface IAssemblyResolver
|
||||
{
|
||||
|
|
|
@ -11,12 +11,6 @@ using UnityEngine.UIElements;
|
|||
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public enum ThisArgType
|
||||
{
|
||||
None,
|
||||
ValueType,
|
||||
Class,
|
||||
}
|
||||
|
||||
public static class MetaUtil
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public class NameMatcher
|
||||
{
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public class PathAssemblyResolver : AssemblyResolverBase
|
||||
{
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace Obfuz.Utils
|
||||
{
|
||||
public enum ThisArgType
|
||||
{
|
||||
None,
|
||||
ValueType,
|
||||
Class,
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Obfuz
|
||||
namespace Obfuz.Utils
|
||||
{
|
||||
public static class TypeSigUtil
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue