混淆失败时打印错误日志,避免悄无声息的错误
parent
291bcd7529
commit
fafc7d11a9
|
@ -30,6 +30,7 @@ namespace Obfuz
|
|||
|
||||
public class ObfuscationEndEventArgs : EventArgs
|
||||
{
|
||||
public bool success;
|
||||
public string originalScriptAssembliesPath;
|
||||
public string obfuscatedScriptAssembliesPath;
|
||||
}
|
||||
|
@ -65,9 +66,10 @@ namespace Obfuz
|
|||
{
|
||||
return;
|
||||
}
|
||||
if (!s_obfuscated)
|
||||
string scriptAssembliesPath = GetScriptAssembliesPath();
|
||||
if (!s_obfuscated && Directory.Exists(scriptAssembliesPath))
|
||||
{
|
||||
RunObfuscate(GetScriptAssembliesPath());
|
||||
RunObfuscate(scriptAssembliesPath);
|
||||
s_obfuscated = true;
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +90,6 @@ namespace Obfuz
|
|||
|
||||
Debug.Log("Obfuscation begin...");
|
||||
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
string obfuscatedAssemblyOutputDir = settings.GetObfuscatedAssemblyOutputDir(buildTarget);
|
||||
OnObfuscationBegin?.Invoke(new ObfuscationBeginEventArgs
|
||||
{
|
||||
scriptAssembliesPath = scriptAssembliesPath,
|
||||
obfuscatedScriptAssembliesPath = obfuscatedAssemblyOutputDir,
|
||||
});
|
||||
|
||||
string backupPlayerScriptAssembliesPath = settings.GetOriginalAssemblyBackupDir(buildTarget);
|
||||
FileUtil.CopyDir(scriptAssembliesPath, backupPlayerScriptAssembliesPath);
|
||||
|
@ -118,6 +114,16 @@ namespace Obfuz
|
|||
};
|
||||
obfuscatorBuilder.InsertTopPriorityAssemblySearchDirs(assemblySearchDirs);
|
||||
|
||||
|
||||
OnObfuscationBegin?.Invoke(new ObfuscationBeginEventArgs
|
||||
{
|
||||
scriptAssembliesPath = scriptAssembliesPath,
|
||||
obfuscatedScriptAssembliesPath = obfuscatorBuilder.ObfuscatedAssemblyOutputDir,
|
||||
});
|
||||
bool succ = false;
|
||||
|
||||
try
|
||||
{
|
||||
Obfuscator obfuz = obfuscatorBuilder.Build();
|
||||
obfuz.Run();
|
||||
|
||||
|
@ -134,8 +140,17 @@ namespace Obfuz
|
|||
File.Copy(src, dst, true);
|
||||
Debug.Log($"obfuscate dll:{dst}");
|
||||
}
|
||||
succ = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
succ = false;
|
||||
Debug.LogException(e);
|
||||
Debug.LogError($"Obfuscation failed.");
|
||||
}
|
||||
OnObfuscationEnd?.Invoke(new ObfuscationEndEventArgs
|
||||
{
|
||||
success = succ,
|
||||
originalScriptAssembliesPath = backupPlayerScriptAssembliesPath,
|
||||
obfuscatedScriptAssembliesPath = scriptAssembliesPath,
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Obfuz
|
|||
|
||||
private readonly ObfuzPipeline _pipeline = new ObfuzPipeline();
|
||||
|
||||
private readonly ObfuscatorContext _ctx;
|
||||
private ObfuscatorContext _ctx;
|
||||
|
||||
public Obfuscator(List<string> toObfuscatedAssemblyNames,
|
||||
List<string> notObfuscatedAssemblyNamesReferencingObfuscated,
|
||||
|
@ -46,15 +46,6 @@ namespace Obfuz
|
|||
_pipeline.AddPass(new CleanUpInstructionPass());
|
||||
|
||||
|
||||
_ctx = new ObfuscatorContext
|
||||
{
|
||||
assemblyCache = _assemblyCache,
|
||||
assemblies = _obfuzAssemblies,
|
||||
toObfuscatedAssemblyNames = _toObfuscatedAssemblyNames,
|
||||
notObfuscatedAssemblyNamesReferencingObfuscated = _notObfuscatedAssemblyNamesReferencingObfuscated,
|
||||
obfuscatedAssemblyOutputDir = _obfuscatedAssemblyOutputDir,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
@ -67,6 +58,16 @@ namespace Obfuz
|
|||
private void OnPreObfuscation()
|
||||
{
|
||||
LoadAssemblies();
|
||||
|
||||
|
||||
_ctx = new ObfuscatorContext
|
||||
{
|
||||
assemblyCache = _assemblyCache,
|
||||
assemblies = _obfuzAssemblies,
|
||||
toObfuscatedAssemblyNames = _toObfuscatedAssemblyNames,
|
||||
notObfuscatedAssemblyNamesReferencingObfuscated = _notObfuscatedAssemblyNamesReferencingObfuscated,
|
||||
obfuscatedAssemblyOutputDir = _obfuscatedAssemblyOutputDir,
|
||||
};
|
||||
_pipeline.Start(_ctx);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue