change: add ObfuscationProcess.ValidateReferences to check assemblies which reference to obfuscated assemblies must have been added to `ObfuzSettings.AssemblySettings.NonObfuscatedButReferencingObfuscatedAssemblies`.
parent
1e8832ca7e
commit
09fdd3052d
|
@ -12,6 +12,7 @@ using UnityEditor.Compilation;
|
|||
using Obfuz.Utils;
|
||||
using FileUtil = Obfuz.Utils.FileUtil;
|
||||
using Obfuz.Settings;
|
||||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.Unity
|
||||
{
|
||||
|
@ -49,6 +50,27 @@ namespace Obfuz.Unity
|
|||
}
|
||||
}
|
||||
|
||||
public static void ValidateReferences(string stagingAreaTempManagedDllDir, HashSet<string> assembliesToObfuscated, HashSet<string> obfuscationRelativeAssemblyNames)
|
||||
{
|
||||
var modCtx = ModuleDef.CreateModuleContext();
|
||||
var asmResolver = (AssemblyResolver)modCtx.AssemblyResolver;
|
||||
|
||||
foreach (string assFile in Directory.GetFiles(stagingAreaTempManagedDllDir, "*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
ModuleDefMD mod = ModuleDefMD.Load(File.ReadAllBytes(assFile), modCtx);
|
||||
string modName = mod.Assembly.Name;
|
||||
foreach (AssemblyRef assRef in mod.GetAssemblyRefs())
|
||||
{
|
||||
string refAssName = assRef.Name;
|
||||
if (assembliesToObfuscated.Contains(refAssName) && !obfuscationRelativeAssemblyNames.Contains(modName))
|
||||
{
|
||||
throw new BuildFailedException($"assembly:{modName} references to obfuscated assembly:{refAssName}, but it's not been added to ObfuzSettings.AssemblySettings.NonObfuscatedButReferencingObfuscatedAssemblies.");
|
||||
}
|
||||
}
|
||||
mod.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void RunObfuscate(BuildFile[] files)
|
||||
{
|
||||
ObfuzSettings settings = ObfuzSettings.Instance;
|
||||
|
@ -76,6 +98,8 @@ namespace Obfuz.Unity
|
|||
};
|
||||
obfuscatorBuilder.InsertTopPriorityAssemblySearchPaths(assemblySearchDirs);
|
||||
|
||||
ValidateReferences(stagingAreaTempManagedDllDir, new HashSet<string>(obfuscatorBuilder.AssembliesToObfuscate), obfuscationRelativeAssemblyNames);
|
||||
|
||||
|
||||
OnObfuscationBegin?.Invoke(new ObfuscationBeginEventArgs
|
||||
{
|
||||
|
|
|
@ -12,6 +12,7 @@ using HybridCLR.Editor.Installer;
|
|||
using System.IO;
|
||||
using HybridCLR.Editor.ABI;
|
||||
using UnityEngine;
|
||||
using Obfuz.Unity;
|
||||
|
||||
namespace Obfuz4HybridCLR
|
||||
{
|
||||
|
@ -38,9 +39,12 @@ namespace Obfuz4HybridCLR
|
|||
string hotUpdateDllPath = SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target);
|
||||
BashUtil.RemoveDir(hotUpdateDllPath);
|
||||
CompileDllCommand.CompileDll(target);
|
||||
|
||||
AssemblySettings assemblySettings = ObfuzSettings.Instance.assemblySettings;
|
||||
ObfuscationProcess.ValidateReferences(hotUpdateDllPath, new HashSet<string>(assemblySettings.GetAssembliesToObfuscate()), new HashSet<string>(assemblySettings.GetObfuscationRelativeAssemblyNames()));
|
||||
var assemblySearchPaths = new List<string>
|
||||
{
|
||||
SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target),
|
||||
hotUpdateDllPath,
|
||||
};
|
||||
Obfuscate(target, assemblySearchPaths, hotUpdateDllPath);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue