修复在Unity 2019上的编译错误
parent
2921f83fb8
commit
d8537e17b5
|
@ -189,9 +189,9 @@ namespace Obfuz
|
||||||
ObfuscationPassType passType = ObfuscationPassType.None;
|
ObfuscationPassType passType = ObfuscationPassType.None;
|
||||||
foreach (var passName in obfuscationPassTypesStr.Split('|'))
|
foreach (var passName in obfuscationPassTypesStr.Split('|'))
|
||||||
{
|
{
|
||||||
if (Enum.TryParse(typeof(ObfuscationPassType), passName, out var pass))
|
if (Enum.TryParse< ObfuscationPassType>(passName, out var pass))
|
||||||
{
|
{
|
||||||
passType |= (ObfuscationPassType)pass;
|
passType |= pass;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace Obfuz.EncryptionVM
|
||||||
{");
|
{");
|
||||||
foreach (var opCode in _vm.opCodes)
|
foreach (var opCode in _vm.opCodes)
|
||||||
{
|
{
|
||||||
lines.Add(@$" case {opCode.code}:
|
lines.Add($@" case {opCode.code}:
|
||||||
{{
|
{{
|
||||||
// {opCode.function.GetType().Name}");
|
// {opCode.function.GetType().Name}");
|
||||||
AppendEncryptCode(lines, opCode.function);
|
AppendEncryptCode(lines, opCode.function);
|
||||||
|
@ -101,7 +101,7 @@ namespace Obfuz.EncryptionVM
|
||||||
{");
|
{");
|
||||||
foreach (var opCode in _vm.opCodes)
|
foreach (var opCode in _vm.opCodes)
|
||||||
{
|
{
|
||||||
lines.Add(@$" case {opCode.code}:
|
lines.Add($@" case {opCode.code}:
|
||||||
{{
|
{{
|
||||||
// {opCode.function.GetType().Name}");
|
// {opCode.function.GetType().Name}");
|
||||||
AppendDecryptCode(lines, opCode.function);
|
AppendDecryptCode(lines, opCode.function);
|
||||||
|
@ -132,7 +132,7 @@ namespace Obfuz.EncryptionVM
|
||||||
{
|
{
|
||||||
public class GeneratedEncryptionVirtualMachine : Obfuz.EncryptorBase
|
public class GeneratedEncryptionVirtualMachine : Obfuz.EncryptorBase
|
||||||
{");
|
{");
|
||||||
lines.Add(@$"
|
lines.Add($@"
|
||||||
private const int kOpCodeBits = {_opCodeBits};
|
private const int kOpCodeBits = {_opCodeBits};
|
||||||
|
|
||||||
private const int kOpCodeCount = {_opCodeCount};
|
private const int kOpCodeCount = {_opCodeCount};
|
||||||
|
|
|
@ -213,22 +213,22 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
{
|
{
|
||||||
case "int":
|
case "int":
|
||||||
{
|
{
|
||||||
notEncryptInts.AddRange(value.Split(",").Select(s => int.Parse(s.Trim())));
|
notEncryptInts.AddRange(value.Split(',').Select(s => int.Parse(s.Trim())));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "long":
|
case "long":
|
||||||
{
|
{
|
||||||
notEncryptLongs.AddRange(value.Split(",").Select(s => long.Parse(s.Trim())));
|
notEncryptLongs.AddRange(value.Split(',').Select(s => long.Parse(s.Trim())));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "string":
|
case "string":
|
||||||
{
|
{
|
||||||
notEncryptStrings.AddRange(value.Split(",").Select(s => s.Trim()));
|
notEncryptStrings.AddRange(value.Split(',').Select(s => s.Trim()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "int-range":
|
case "int-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, int-range {value} is invalid");
|
throw new Exception($"Invalid xml file, int-range {value} is invalid");
|
||||||
|
@ -238,7 +238,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
}
|
}
|
||||||
case "long-range":
|
case "long-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, long-range {value} is invalid");
|
throw new Exception($"Invalid xml file, long-range {value} is invalid");
|
||||||
|
@ -248,7 +248,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
}
|
}
|
||||||
case "float-range":
|
case "float-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, float-range {value} is invalid");
|
throw new Exception($"Invalid xml file, float-range {value} is invalid");
|
||||||
|
@ -258,7 +258,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
}
|
}
|
||||||
case "double-range":
|
case "double-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, double-range {value} is invalid");
|
throw new Exception($"Invalid xml file, double-range {value} is invalid");
|
||||||
|
@ -268,7 +268,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
}
|
}
|
||||||
case "string-length-range":
|
case "string-length-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, string-length-range {value} is invalid");
|
throw new Exception($"Invalid xml file, string-length-range {value} is invalid");
|
||||||
|
@ -278,7 +278,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||||
}
|
}
|
||||||
case "array-length-range":
|
case "array-length-range":
|
||||||
{
|
{
|
||||||
var parts = value.Split(",");
|
var parts = value.Split(',');
|
||||||
if (parts.Length != 2)
|
if (parts.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"Invalid xml file, array-length-range {value} is invalid");
|
throw new Exception($"Invalid xml file, array-length-range {value} is invalid");
|
||||||
|
|
|
@ -711,7 +711,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus.Policies
|
||||||
|
|
||||||
public ConfigurableRenamePolicy(List<string> obfuscationAssemblyNames, List<string> xmlFiles)
|
public ConfigurableRenamePolicy(List<string> obfuscationAssemblyNames, List<string> xmlFiles)
|
||||||
{
|
{
|
||||||
this._obfuscationAssemblyNames = obfuscationAssemblyNames.ToHashSet();
|
_obfuscationAssemblyNames = new HashSet<string>(obfuscationAssemblyNames);
|
||||||
LoadXmls(xmlFiles);
|
LoadXmls(xmlFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ namespace Obfuz.ObfusPasses.SymbolObfus
|
||||||
_assemblyCache = ctx.assemblyCache;
|
_assemblyCache = ctx.assemblyCache;
|
||||||
_toObfuscatedModules = ctx.toObfuscatedModules;
|
_toObfuscatedModules = ctx.toObfuscatedModules;
|
||||||
_obfuscatedAndNotObfuscatedModules = ctx.obfuscatedAndNotObfuscatedModules;
|
_obfuscatedAndNotObfuscatedModules = ctx.obfuscatedAndNotObfuscatedModules;
|
||||||
_toObfuscatedModuleSet = ctx.toObfuscatedModules.ToHashSet();
|
_toObfuscatedModuleSet = new HashSet<ModuleDef>(ctx.toObfuscatedModules);
|
||||||
var obfuscateRuleConfig = new ConfigurableRenamePolicy(ctx.toObfuscatedAssemblyNames, _obfuscationRuleFiles);
|
var obfuscateRuleConfig = new ConfigurableRenamePolicy(ctx.toObfuscatedAssemblyNames, _obfuscationRuleFiles);
|
||||||
_renamePolicy = new CacheRenamePolicy(new CombineRenamePolicy(new SupportPassPolicy(ctx.passPolicy), new SystemRenamePolicy(), new UnityRenamePolicy(), obfuscateRuleConfig));
|
_renamePolicy = new CacheRenamePolicy(new CombineRenamePolicy(new SupportPassPolicy(ctx.passPolicy), new SystemRenamePolicy(), new UnityRenamePolicy(), obfuscateRuleConfig));
|
||||||
BuildCustomAttributeArguments();
|
BuildCustomAttributeArguments();
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using dnlib.DotNet;
|
using dnlib.DotNet;
|
||||||
using dnlib.Protection;
|
|
||||||
using Obfuz.Data;
|
using Obfuz.Data;
|
||||||
using Obfuz.Emit;
|
using Obfuz.Emit;
|
||||||
using Obfuz.EncryptionVM;
|
using Obfuz.EncryptionVM;
|
||||||
|
@ -14,7 +13,6 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static UnityEditor.ObjectChangeEventStream;
|
|
||||||
|
|
||||||
namespace Obfuz
|
namespace Obfuz
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,11 @@ namespace Obfuz.Unity
|
||||||
|
|
||||||
public void OnPostBuildPlayerScriptDLLs(BuildReport report)
|
public void OnPostBuildPlayerScriptDLLs(BuildReport report)
|
||||||
{
|
{
|
||||||
|
#if UNITY_2019
|
||||||
|
RunObfuscate(report.files);
|
||||||
|
#else
|
||||||
RunObfuscate(report.GetFiles());
|
RunObfuscate(report.GetFiles());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void BackupOriginalDlls(string srcDir, string dstDir, HashSet<string> dllNames)
|
private static void BackupOriginalDlls(string srcDir, string dstDir, HashSet<string> dllNames)
|
||||||
|
@ -57,7 +61,7 @@ namespace Obfuz.Unity
|
||||||
Debug.Log("Obfuscation begin...");
|
Debug.Log("Obfuscation begin...");
|
||||||
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
|
|
||||||
var obfuscationRelativeAssemblyNames = settings.assemblySettings.GetObfuscationRelativeAssemblyNames().ToHashSet();
|
var obfuscationRelativeAssemblyNames = new HashSet<string>(settings.assemblySettings.GetObfuscationRelativeAssemblyNames());
|
||||||
string stagingAreaTempManagedDllDir = Path.GetDirectoryName(files.First(file => file.path.EndsWith(".dll")).path);
|
string stagingAreaTempManagedDllDir = Path.GetDirectoryName(files.First(file => file.path.EndsWith(".dll")).path);
|
||||||
string backupPlayerScriptAssembliesPath = settings.GetOriginalAssemblyBackupDir(buildTarget);
|
string backupPlayerScriptAssembliesPath = settings.GetOriginalAssemblyBackupDir(buildTarget);
|
||||||
BackupOriginalDlls(stagingAreaTempManagedDllDir, backupPlayerScriptAssembliesPath, obfuscationRelativeAssemblyNames);
|
BackupOriginalDlls(stagingAreaTempManagedDllDir, backupPlayerScriptAssembliesPath, obfuscationRelativeAssemblyNames);
|
||||||
|
|
|
@ -4,7 +4,6 @@ using Obfuz.Utils;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static UnityEditor.ObjectChangeEventStream;
|
|
||||||
using FileUtil = Obfuz.Utils.FileUtil;
|
using FileUtil = Obfuz.Utils.FileUtil;
|
||||||
|
|
||||||
namespace Obfuz.Unity
|
namespace Obfuz.Unity
|
||||||
|
|
|
@ -13,7 +13,8 @@ namespace Obfuz.Utils
|
||||||
public static byte[] GenerateKey(string initialString, int keyLength)
|
public static byte[] GenerateKey(string initialString, int keyLength)
|
||||||
{
|
{
|
||||||
byte[] initialBytes = Encoding.UTF8.GetBytes(initialString);
|
byte[] initialBytes = Encoding.UTF8.GetBytes(initialString);
|
||||||
using var sha512 = SHA512.Create();
|
using (var sha512 = SHA512.Create())
|
||||||
|
{
|
||||||
byte[] hash = sha512.ComputeHash(initialBytes);
|
byte[] hash = sha512.ComputeHash(initialBytes);
|
||||||
byte[] key = new byte[keyLength];
|
byte[] key = new byte[keyLength];
|
||||||
int bytesCopied = 0;
|
int bytesCopied = 0;
|
||||||
|
@ -30,6 +31,7 @@ namespace Obfuz.Utils
|
||||||
}
|
}
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static int[] ConvertToIntKey(byte[] key)
|
public static int[] ConvertToIntKey(byte[] key)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,24 +55,28 @@ namespace Obfuz
|
||||||
Buffer.BlockCopy(data, offset, array, 0, length);
|
Buffer.BlockCopy(data, offset, array, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int CastFloatAsInt(float value)
|
public static unsafe int CastFloatAsInt(float value)
|
||||||
{
|
{
|
||||||
return UnsafeUtility.As<float, int>(ref value);
|
int* intValue = (int*)&value;
|
||||||
|
return *intValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float CastIntAsFloat(int value)
|
public static unsafe float CastIntAsFloat(int value)
|
||||||
{
|
{
|
||||||
return UnsafeUtility.As<int, float>(ref value);
|
float* floatValue = (float*)&value;
|
||||||
|
return *floatValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long CastDoubleAsLong(double value)
|
public static unsafe long CastDoubleAsLong(double value)
|
||||||
{
|
{
|
||||||
return UnsafeUtility.As<double, long>(ref value);
|
long* longValue = (long*)&value;
|
||||||
|
return *longValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double CastLongAsDouble(long value)
|
public static unsafe double CastLongAsDouble(long value)
|
||||||
{
|
{
|
||||||
return UnsafeUtility.As<long, double>(ref value);
|
double* doubleValue = (double*)&value;
|
||||||
|
return *doubleValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,49 +40,49 @@ namespace Obfuz
|
||||||
return ((long)decryptedHigh << 32) | (uint)decryptedLow;
|
return ((long)decryptedHigh << 32) | (uint)decryptedLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual float Encrypt(float value, int opts, int salt)
|
public virtual unsafe float Encrypt(float value, int opts, int salt)
|
||||||
{
|
{
|
||||||
if (float.IsNaN(value) || float.IsInfinity(value))
|
if (float.IsNaN(value) || float.IsInfinity(value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
ref int intValue = ref UnsafeUtility.As<float, int>(ref value);
|
ref int intValue = ref *(int*)&value;
|
||||||
int xorValue = ((1 << 23) - 1) & Decrypt(0xABCD, opts, salt);
|
int xorValue = ((1 << 23) - 1) & Decrypt(0xABCD, opts, salt);
|
||||||
intValue ^= xorValue;
|
intValue ^= xorValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual float Decrypt(float value, int opts, int salt)
|
public virtual unsafe float Decrypt(float value, int opts, int salt)
|
||||||
{
|
{
|
||||||
if (float.IsNaN(value) || float.IsInfinity(value))
|
if (float.IsNaN(value) || float.IsInfinity(value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
ref int intValue = ref UnsafeUtility.As<float, int>(ref value);
|
ref int intValue = ref *(int*)&value;
|
||||||
int xorValue = ((1 << 23) - 1) & Decrypt(0xABCD, opts, salt);
|
int xorValue = ((1 << 23) - 1) & Decrypt(0xABCD, opts, salt);
|
||||||
intValue ^= xorValue;
|
intValue ^= xorValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual double Encrypt(double value, int opts, int salt)
|
public virtual unsafe double Encrypt(double value, int opts, int salt)
|
||||||
{
|
{
|
||||||
if (double.IsNaN(value) || double.IsInfinity(value))
|
if (double.IsNaN(value) || double.IsInfinity(value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
ref long longValue = ref UnsafeUtility.As<double, long>(ref value);
|
ref long longValue = ref *(long*)&value;
|
||||||
long xorValue = ((1L << 52) - 1) & Decrypt(0xAABBCCDDL, opts, salt);
|
long xorValue = ((1L << 52) - 1) & Decrypt(0xAABBCCDDL, opts, salt);
|
||||||
longValue ^= xorValue;
|
longValue ^= xorValue;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual double Decrypt(double value, int opts, int salt)
|
public virtual unsafe double Decrypt(double value, int opts, int salt)
|
||||||
{
|
{
|
||||||
if (double.IsNaN(value) || double.IsInfinity(value))
|
if (double.IsNaN(value) || double.IsInfinity(value))
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
ref long longValue = ref UnsafeUtility.As<double, long>(ref value);
|
ref long longValue = ref *(long*)&value;
|
||||||
long xorValue = ((1L << 52) - 1) & Decrypt(0xAABBCCDDL, opts, salt);
|
long xorValue = ((1L << 52) - 1) & Decrypt(0xAABBCCDDL, opts, salt);
|
||||||
longValue ^= xorValue;
|
longValue ^= xorValue;
|
||||||
return value;
|
return value;
|
||||||
|
|
|
@ -24,9 +24,9 @@ namespace Obfuz
|
||||||
double Decrypt(double value, int opts, int salt);
|
double Decrypt(double value, int opts, int salt);
|
||||||
|
|
||||||
byte[] Encrypt(byte[] value, int offset, int length, int opts, int salt);
|
byte[] Encrypt(byte[] value, int offset, int length, int opts, int salt);
|
||||||
public byte[] Decrypt(byte[] value, int offset, int byteLength, int ops, int salt);
|
byte[] Decrypt(byte[] value, int offset, int byteLength, int ops, int salt);
|
||||||
|
|
||||||
public byte[] Encrypt(string value, int ops, int salt);
|
byte[] Encrypt(string value, int ops, int salt);
|
||||||
public string DecryptString(byte[] value, int offset, int stringBytesLength, int ops, int salt);
|
string DecryptString(byte[] value, int offset, int stringBytesLength, int ops, int salt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue