remove Obfuz project
parent
8f8422864b
commit
2453acc1d3
|
@ -1,29 +0,0 @@
|
||||||
using Obfuz;
|
|
||||||
using Obfuz.EncryptionVM;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
|
|
||||||
public class Bootstrap : MonoBehaviour
|
|
||||||
{
|
|
||||||
[ObfuzIgnore]
|
|
||||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
|
|
||||||
private static void SetUpStaticSecret()
|
|
||||||
{
|
|
||||||
Debug.Log("SetUpStaticSecret begin");
|
|
||||||
EncryptionService<DefaultStaticEncryptionScope>.Encryptor = new GeneratedEncryptionVirtualMachine(Resources.Load<TextAsset>("Obfuz/defaultStaticSecretKey").bytes);
|
|
||||||
Debug.Log("SetUpStaticSecret end");
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Add(int a, int b)
|
|
||||||
{
|
|
||||||
return a + b;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
int a = Add(100, 200);
|
|
||||||
Debug.Log($"a = {a}");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 639006a739675484884778c298eebdc4
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 5eee1172624990e4cb08bd171f20cbaf
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 406c63e9d464ca544ac337bc8fcce30e
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 75e20a8abe7b86247837ffce1117762a
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,482 +0,0 @@
|
||||||
<mapping>
|
|
||||||
<assembly name="Assembly-CSharp">
|
|
||||||
<type fullName="Bootstrap" newFullName="" status="NotRenamed">
|
|
||||||
<method signature="int Bootstrap::Add([Assembly-CSharp]Bootstrap, int, int)" newName="$a" oldStackTraceSignature="Bootstrap:Add(Int32, Int32)" newStackTraceSignature="Bootstrap:$a(Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine" newFullName="$a.$A" status="Renamed">
|
|
||||||
<field signature="int kOpCodeBits" newName="$a" />
|
|
||||||
<field signature="int kOpCodeCount" newName="$A" />
|
|
||||||
<field signature="int kOpCodeMask" newName="$b" />
|
|
||||||
<field signature="int[] _secretKey" newName="$B" />
|
|
||||||
<property signature="int OpCodeCount" newName="$E" />
|
|
||||||
<method signature="int Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine::get_OpCodeCount([Assembly-CSharp]Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine)" newName="$d" oldStackTraceSignature="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine:get_OpCodeCount()" newStackTraceSignature="$a.$A:$d()" />
|
|
||||||
<method signature="int Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine::Encrypt([Assembly-CSharp]Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine, int, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine:Encrypt(Int32, Int32, Int32)" newStackTraceSignature="$a.$A:$D(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine::Decrypt([Assembly-CSharp]Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine, int, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine:Decrypt(Int32, Int32, Int32)" newStackTraceSignature="$a.$A:$e(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine::ExecuteEncrypt([Assembly-CSharp]Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine, int, int, int)" newName="$c" oldStackTraceSignature="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine:ExecuteEncrypt(Int32, Int32, Int32)" newStackTraceSignature="$a.$A:$c(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine::ExecuteDecrypt([Assembly-CSharp]Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine, int, int, int)" newName="$C" oldStackTraceSignature="Obfuz.EncryptionVM.GeneratedEncryptionVirtualMachine:ExecuteDecrypt(Int32, Int32, Int32)" newStackTraceSignature="$a.$A:$C(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="<PrivateImplementationDetails>" newFullName="$b" status="Renamed">
|
|
||||||
<field signature="[Assembly-CSharp]<PrivateImplementationDetails>/__StaticArrayInitTypeSize=86 230748DE32A7B14F2A36EEA88E8693F9862DC7AC35B0BA73ACB9E47C6A6EC891" newName="$a" />
|
|
||||||
<field signature="[Assembly-CSharp]<PrivateImplementationDetails>/__StaticArrayInitTypeSize=72 A9CE10ECCCBCA424528AF2C7F835672596125B19DA54C2D7FBBFA1840795ACE2" newName="$A" />
|
|
||||||
</type>
|
|
||||||
<type fullName="<PrivateImplementationDetails>/__StaticArrayInitTypeSize=72" newFullName="$b/$a" status="Renamed" />
|
|
||||||
<type fullName="<PrivateImplementationDetails>/__StaticArrayInitTypeSize=86" newFullName="$b/$B" status="Renamed" />
|
|
||||||
<type fullName="$ObfuzRVA$DataHolder4096" newFullName="$C" status="Renamed" />
|
|
||||||
<type fullName="$Obfuz$RVA$" newFullName="$d" status="Renamed">
|
|
||||||
<field signature="[Assembly-CSharp]$ObfuzRVA$DataHolder4096 $RVA_Data0" newName="$a" />
|
|
||||||
<field signature="byte[] $RVA_Value0" newName="$A" />
|
|
||||||
</type>
|
|
||||||
<type fullName="$Obfuz$ConstFieldHolder$0" newFullName="$D" status="Renamed">
|
|
||||||
<field signature="string $Obfuz$RVA_Value0" newName="$a" />
|
|
||||||
</type>
|
|
||||||
<type fullName="$Obfuz$ProxyCall" newFullName="$e" status="Renamed">
|
|
||||||
<method signature="int $Obfuz$ProxyCall::$Obfuz$ProxyCall$Dispatch$0(object, int, int, int, int)" newName="$a" oldStackTraceSignature="$Obfuz$ProxyCall:$Obfuz$ProxyCall$Dispatch$0(Object, Int32, Int32, Int32, Int32)" newStackTraceSignature="$e:$a(Object, Int32, Int32, Int32, Int32)" />
|
|
||||||
<method signature="int $Obfuz$ProxyCall::$Obfuz$ProxyCall$Dispatch$1(object, int, int, int)" newName="$A" oldStackTraceSignature="$Obfuz$ProxyCall:$Obfuz$ProxyCall$Dispatch$1(Object, Int32, Int32, Int32)" newStackTraceSignature="$e:$A(Object, Int32, Int32, Int32)" />
|
|
||||||
<method signature="void $Obfuz$ProxyCall::$Obfuz$ProxyCall$Dispatch$2(object, int)" newName="$b" oldStackTraceSignature="$Obfuz$ProxyCall:$Obfuz$ProxyCall$Dispatch$2(Object, Int32)" newStackTraceSignature="$e:$b(Object, Int32)" />
|
|
||||||
</type>
|
|
||||||
</assembly>
|
|
||||||
<assembly name="Obfuz.Runtime">
|
|
||||||
<type fullName="Obfuz.ConstUtility" newFullName="$A.$a" status="Renamed">
|
|
||||||
<method signature="int Obfuz.ConstUtility::GetInt(byte[], int)" newName="$a" oldStackTraceSignature="Obfuz.ConstUtility:GetInt(Byte[], Int32)" newStackTraceSignature="$A.$a:$a(Byte[], Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.ConstUtility::GetLong(byte[], int)" newName="$A" oldStackTraceSignature="Obfuz.ConstUtility:GetLong(Byte[], Int32)" newStackTraceSignature="$A.$a:$A(Byte[], Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.ConstUtility::GetFloat(byte[], int)" newName="$b" oldStackTraceSignature="Obfuz.ConstUtility:GetFloat(Byte[], Int32)" newStackTraceSignature="$A.$a:$b(Byte[], Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.ConstUtility::GetDouble(byte[], int)" newName="$B" oldStackTraceSignature="Obfuz.ConstUtility:GetDouble(Byte[], Int32)" newStackTraceSignature="$A.$a:$B(Byte[], Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.ConstUtility::GetString(byte[], int, int)" newName="$c" oldStackTraceSignature="Obfuz.ConstUtility:GetString(Byte[], Int32, Int32)" newStackTraceSignature="$A.$a:$c(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.ConstUtility::GetBytes(byte[], int, int)" newName="$C" oldStackTraceSignature="Obfuz.ConstUtility:GetBytes(Byte[], Int32, Int32)" newStackTraceSignature="$A.$a:$C(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int[] Obfuz.ConstUtility::GetInts(byte[], int, int)" newName="$d" oldStackTraceSignature="Obfuz.ConstUtility:GetInts(Byte[], Int32, Int32)" newStackTraceSignature="$A.$a:$d(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.ConstUtility::InitializeArray(System.Array, byte[], int, int)" newName="$D" oldStackTraceSignature="Obfuz.ConstUtility:InitializeArray(Array, Byte[], Int32, Int32)" newStackTraceSignature="$A.$a:$D(Array, Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.ConstUtility::CastFloatAsInt(float)" newName="$e" oldStackTraceSignature="Obfuz.ConstUtility:CastFloatAsInt(Single)" newStackTraceSignature="$A.$a:$e(Single)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.ConstUtility::CastIntAsFloat(int)" newName="$E" oldStackTraceSignature="Obfuz.ConstUtility:CastIntAsFloat(Int32)" newStackTraceSignature="$A.$a:$E(Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.ConstUtility::CastDoubleAsLong(double)" newName="$f" oldStackTraceSignature="Obfuz.ConstUtility:CastDoubleAsLong(Double)" newStackTraceSignature="$A.$a:$f(Double)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.ConstUtility::CastLongAsDouble(long)" newName="$F" oldStackTraceSignature="Obfuz.ConstUtility:CastLongAsDouble(Int64)" newStackTraceSignature="$A.$a:$F(Int64)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.IEncryptionScope" newFullName="$A.$A" status="Renamed" />
|
|
||||||
<type fullName="Obfuz.EncryptionScopeBase" newFullName="$A.$b" status="Renamed">
|
|
||||||
<method signature="void Obfuz.EncryptionScopeBase::ForcePreserveAOT([Obfuz.Runtime]Obfuz.EncryptionScopeBase)" newName="$a" oldStackTraceSignature="Obfuz.EncryptionScopeBase:ForcePreserveAOT()" newStackTraceSignature="$A.$b:$a()" />
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.DefaultDynamicEncryptionScope" newFullName="$A.$B" status="Renamed">
|
|
||||||
<method signature="void Obfuz.DefaultDynamicEncryptionScope::ForcePreserveAOT([Obfuz.Runtime]Obfuz.DefaultDynamicEncryptionScope&)" newName="$a" oldStackTraceSignature="Obfuz.DefaultDynamicEncryptionScope:ForcePreserveAOT()" newStackTraceSignature="$A.$B:$a()" />
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.DefaultStaticEncryptionScope" newFullName="$A.$c" status="Renamed">
|
|
||||||
<method signature="void Obfuz.DefaultStaticEncryptionScope::ForcePreserveAOT([Obfuz.Runtime]Obfuz.DefaultStaticEncryptionScope&)" newName="$a" oldStackTraceSignature="Obfuz.DefaultStaticEncryptionScope:ForcePreserveAOT()" newStackTraceSignature="$A.$c:$a()" />
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.EncryptionService`1" newFullName="$A.$C" status="Renamed">
|
|
||||||
<field signature="[Obfuz.Runtime]Obfuz.IEncryptor _encryptor" newName="$a" />
|
|
||||||
<property signature="[Obfuz.Runtime]Obfuz.IEncryptor Encryptor" newName="$L" />
|
|
||||||
<method signature="[Obfuz.Runtime]Obfuz.IEncryptor Obfuz.EncryptionService`1::get_Encryptor()" newName="$A" oldStackTraceSignature="Obfuz.EncryptionService`1:get_Encryptor()" newStackTraceSignature="$A.$C:$A()" />
|
|
||||||
<method signature="void Obfuz.EncryptionService`1::set_Encryptor([Obfuz.Runtime]Obfuz.IEncryptor)" newName="$b" oldStackTraceSignature="Obfuz.EncryptionService`1:set_Encryptor(IEncryptor)" newStackTraceSignature="$A.$C:$b($D)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.EncryptionService`1::EncryptBlock(byte[], int, int)" newName="$B" oldStackTraceSignature="Obfuz.EncryptionService`1:EncryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$C:$B(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.EncryptionService`1::DecryptBlock(byte[], int, int)" newName="$c" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$C:$c(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionService`1::Encrypt(int, int, int)" newName="$C" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$C(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionService`1::Decrypt(int, int, int)" newName="$d" oldStackTraceSignature="Obfuz.EncryptionService`1:Decrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$d(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.EncryptionService`1::Encrypt(long, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$C:$D(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.EncryptionService`1::Decrypt(long, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptionService`1:Decrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$C:$e(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.EncryptionService`1::Encrypt(float, int, int)" newName="$E" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$C:$E(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.EncryptionService`1::Decrypt(float, int, int)" newName="$f" oldStackTraceSignature="Obfuz.EncryptionService`1:Decrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$C:$f(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.EncryptionService`1::Encrypt(double, int, int)" newName="$F" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$C:$F(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.EncryptionService`1::Decrypt(double, int, int)" newName="$g" oldStackTraceSignature="Obfuz.EncryptionService`1:Decrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$C:$g(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptionService`1::Encrypt(byte[], int, int, int, int)" newName="$G" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$G(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptionService`1::Decrypt(byte[], int, int, int, int)" newName="$h" oldStackTraceSignature="Obfuz.EncryptionService`1:Decrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$h(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptionService`1::Encrypt(string, int, int)" newName="$H" oldStackTraceSignature="Obfuz.EncryptionService`1:Encrypt(String, Int32, Int32)" newStackTraceSignature="$A.$C:$H(String, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.EncryptionService`1::DecryptString(byte[], int, int, int, int)" newName="$i" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptString(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$i(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptionService`1::DecryptFromRvaInt(byte[], int, int, int)" newName="$I" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaInt(Byte[], Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$I(Byte[], Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.EncryptionService`1::DecryptFromRvaLong(byte[], int, int, int)" newName="$j" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaLong(Byte[], Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$j(Byte[], Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.EncryptionService`1::DecryptFromRvaFloat(byte[], int, int, int)" newName="$J" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaFloat(Byte[], Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$J(Byte[], Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.EncryptionService`1::DecryptFromRvaDouble(byte[], int, int, int)" newName="$k" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaDouble(Byte[], Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$k(Byte[], Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.EncryptionService`1::DecryptFromRvaString(byte[], int, int, int, int)" newName="$K" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaString(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$K(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptionService`1::DecryptFromRvaBytes(byte[], int, int, int, int)" newName="$l" oldStackTraceSignature="Obfuz.EncryptionService`1:DecryptFromRvaBytes(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$C:$l(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.EncryptorBase" newFullName="$A.$d" status="Renamed">
|
|
||||||
<property signature="int OpCodeCount" newName="$d" />
|
|
||||||
<method signature="int Obfuz.EncryptorBase::get_OpCodeCount([Obfuz.Runtime]Obfuz.EncryptorBase)" newName="$d" oldStackTraceSignature="Obfuz.EncryptorBase:get_OpCodeCount()" newStackTraceSignature="$A.$d:$d()" />
|
|
||||||
<method signature="int[] Obfuz.EncryptorBase::ConvertToIntKey(byte[])" newName="$a" oldStackTraceSignature="Obfuz.EncryptorBase:ConvertToIntKey(Byte[])" newStackTraceSignature="$A.$d:$a(Byte[])">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, int, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$d:$D(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.EncryptorBase::Decrypt([Obfuz.Runtime]Obfuz.EncryptorBase, int, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptorBase:Decrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$d:$e(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, long, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$d:$D(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.EncryptorBase::Decrypt([Obfuz.Runtime]Obfuz.EncryptorBase, long, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptorBase:Decrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$d:$e(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, float, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$d:$D(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.EncryptorBase::Decrypt([Obfuz.Runtime]Obfuz.EncryptorBase, float, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptorBase:Decrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$d:$e(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, double, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$d:$D(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.EncryptorBase::Decrypt([Obfuz.Runtime]Obfuz.EncryptorBase, double, int, int)" newName="$e" oldStackTraceSignature="Obfuz.EncryptorBase:Decrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$d:$e(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, byte[], int, int, int, int)" newName="$A" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$d:$A(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptorBase::Decrypt([Obfuz.Runtime]Obfuz.EncryptorBase, byte[], int, int, int, int)" newName="$b" oldStackTraceSignature="Obfuz.EncryptorBase:Decrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$d:$b(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.EncryptorBase::Encrypt([Obfuz.Runtime]Obfuz.EncryptorBase, string, int, int)" newName="$D" oldStackTraceSignature="Obfuz.EncryptorBase:Encrypt(String, Int32, Int32)" newStackTraceSignature="$A.$d:$D(String, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.EncryptorBase::DecryptString([Obfuz.Runtime]Obfuz.EncryptorBase, byte[], int, int, int, int)" newName="$B" oldStackTraceSignature="Obfuz.EncryptorBase:DecryptString(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$d:$B(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.EncryptorBase::EncryptBlock([Obfuz.Runtime]Obfuz.EncryptorBase, byte[], int, int)" newName="$c" oldStackTraceSignature="Obfuz.EncryptorBase:EncryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$d:$c(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.EncryptorBase::DecryptBlock([Obfuz.Runtime]Obfuz.EncryptorBase, byte[], int, int)" newName="$C" oldStackTraceSignature="Obfuz.EncryptorBase:DecryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$d:$C(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.IEncryptor" newFullName="$A.$D" status="Renamed">
|
|
||||||
<property signature="int OpCodeCount" newName="$a" />
|
|
||||||
<method signature="int Obfuz.IEncryptor::get_OpCodeCount([Obfuz.Runtime]Obfuz.IEncryptor)" newName="$d" oldStackTraceSignature="Obfuz.IEncryptor:get_OpCodeCount()" newStackTraceSignature="$A.$D:$d()" />
|
|
||||||
<method signature="void Obfuz.IEncryptor::EncryptBlock([Obfuz.Runtime]Obfuz.IEncryptor, byte[], int, int)" newName="$c" oldStackTraceSignature="Obfuz.IEncryptor:EncryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$D:$c(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="void Obfuz.IEncryptor::DecryptBlock([Obfuz.Runtime]Obfuz.IEncryptor, byte[], int, int)" newName="$C" oldStackTraceSignature="Obfuz.IEncryptor:DecryptBlock(Byte[], Int32, Int32)" newStackTraceSignature="$A.$D:$C(Byte[], Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, int, int, int)" newName="$D" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$D:$D(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.IEncryptor::Decrypt([Obfuz.Runtime]Obfuz.IEncryptor, int, int, int)" newName="$e" oldStackTraceSignature="Obfuz.IEncryptor:Decrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$D:$e(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, long, int, int)" newName="$D" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$D:$D(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.IEncryptor::Decrypt([Obfuz.Runtime]Obfuz.IEncryptor, long, int, int)" newName="$e" oldStackTraceSignature="Obfuz.IEncryptor:Decrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$D:$e(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, float, int, int)" newName="$D" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$D:$D(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.IEncryptor::Decrypt([Obfuz.Runtime]Obfuz.IEncryptor, float, int, int)" newName="$e" oldStackTraceSignature="Obfuz.IEncryptor:Decrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$D:$e(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, double, int, int)" newName="$D" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$D:$D(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.IEncryptor::Decrypt([Obfuz.Runtime]Obfuz.IEncryptor, double, int, int)" newName="$e" oldStackTraceSignature="Obfuz.IEncryptor:Decrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$D:$e(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, byte[], int, int, int, int)" newName="$A" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$D:$A(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.IEncryptor::Decrypt([Obfuz.Runtime]Obfuz.IEncryptor, byte[], int, int, int, int)" newName="$b" oldStackTraceSignature="Obfuz.IEncryptor:Decrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$D:$b(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.IEncryptor::Encrypt([Obfuz.Runtime]Obfuz.IEncryptor, string, int, int)" newName="$D" oldStackTraceSignature="Obfuz.IEncryptor:Encrypt(String, Int32, Int32)" newStackTraceSignature="$A.$D:$D(String, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.IEncryptor::DecryptString([Obfuz.Runtime]Obfuz.IEncryptor, byte[], int, int, int, int)" newName="$B" oldStackTraceSignature="Obfuz.IEncryptor:DecryptString(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$D:$B(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="Obfuz.NullEncryptor" newFullName="$A.$e" status="Renamed">
|
|
||||||
<field signature="byte[] _key" newName="$a" />
|
|
||||||
<property signature="int OpCodeCount" newName="$A" />
|
|
||||||
<method signature="int Obfuz.NullEncryptor::get_OpCodeCount([Obfuz.Runtime]Obfuz.NullEncryptor)" newName="$d" oldStackTraceSignature="Obfuz.NullEncryptor:get_OpCodeCount()" newStackTraceSignature="$A.$e:$d()" />
|
|
||||||
<method signature="int Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, int, int, int)" newName="$D" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$e:$D(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="int Obfuz.NullEncryptor::Decrypt([Obfuz.Runtime]Obfuz.NullEncryptor, int, int, int)" newName="$e" oldStackTraceSignature="Obfuz.NullEncryptor:Decrypt(Int32, Int32, Int32)" newStackTraceSignature="$A.$e:$e(Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, long, int, int)" newName="$D" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$e:$D(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="long Obfuz.NullEncryptor::Decrypt([Obfuz.Runtime]Obfuz.NullEncryptor, long, int, int)" newName="$e" oldStackTraceSignature="Obfuz.NullEncryptor:Decrypt(Int64, Int32, Int32)" newStackTraceSignature="$A.$e:$e(Int64, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, float, int, int)" newName="$D" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$e:$D(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="float Obfuz.NullEncryptor::Decrypt([Obfuz.Runtime]Obfuz.NullEncryptor, float, int, int)" newName="$e" oldStackTraceSignature="Obfuz.NullEncryptor:Decrypt(Single, Int32, Int32)" newStackTraceSignature="$A.$e:$e(Single, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, double, int, int)" newName="$D" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$e:$D(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="double Obfuz.NullEncryptor::Decrypt([Obfuz.Runtime]Obfuz.NullEncryptor, double, int, int)" newName="$e" oldStackTraceSignature="Obfuz.NullEncryptor:Decrypt(Double, Int32, Int32)" newStackTraceSignature="$A.$e:$e(Double, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, byte[], int, int, int, int)" newName="$A" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$e:$A(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.NullEncryptor::Decrypt([Obfuz.Runtime]Obfuz.NullEncryptor, byte[], int, int, int, int)" newName="$b" oldStackTraceSignature="Obfuz.NullEncryptor:Decrypt(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$e:$b(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="byte[] Obfuz.NullEncryptor::Encrypt([Obfuz.Runtime]Obfuz.NullEncryptor, string, int, int)" newName="$D" oldStackTraceSignature="Obfuz.NullEncryptor:Encrypt(String, Int32, Int32)" newStackTraceSignature="$A.$e:$D(String, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
</method>
|
|
||||||
<method signature="string Obfuz.NullEncryptor::DecryptString([Obfuz.Runtime]Obfuz.NullEncryptor, byte[], int, int, int, int)" newName="$B" oldStackTraceSignature="Obfuz.NullEncryptor:DecryptString(Byte[], Int32, Int32, Int32, Int32)" newStackTraceSignature="$A.$e:$B(Byte[], Int32, Int32, Int32, Int32)">
|
|
||||||
<param index="1" newName="1" />
|
|
||||||
<param index="2" newName="1" />
|
|
||||||
<param index="3" newName="1" />
|
|
||||||
<param index="4" newName="1" />
|
|
||||||
<param index="5" newName="1" />
|
|
||||||
</method>
|
|
||||||
</type>
|
|
||||||
<type fullName="<PrivateImplementationDetails>" newFullName="$E" status="Renamed">
|
|
||||||
<field signature="[Obfuz.Runtime]<PrivateImplementationDetails>/__StaticArrayInitTypeSize=485 4D86FB4619BF2F4465F6F979AAB9FA9ADA0C5BAD12F8BDB94477A09FDBC2AC08" newName="$a" />
|
|
||||||
<field signature="[Obfuz.Runtime]<PrivateImplementationDetails>/__StaticArrayInitTypeSize=287 D7732D9B8DD2D1E9FB31DE85ABBC286035E9C1E538CCB1A668625C2C343E4D26" newName="$A" />
|
|
||||||
</type>
|
|
||||||
<type fullName="<PrivateImplementationDetails>/__StaticArrayInitTypeSize=287" newFullName="$E/$f" status="Renamed" />
|
|
||||||
<type fullName="<PrivateImplementationDetails>/__StaticArrayInitTypeSize=485" newFullName="$E/$F" status="Renamed" />
|
|
||||||
</assembly>
|
|
||||||
</mapping>
|
|
|
@ -1,7 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: b8e3f4340cc69fa4889a61a211cf24c5
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 4d42a5aa28dcabc428e7a06b13421410
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 5be12685e3d38a24ab47ccfde4f424a1
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Binary file not shown.
|
@ -1,7 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: c05b06a0efaf2b1449760b6e43a887d3
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Binary file not shown.
|
@ -1,7 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 8d8f2c4f77ee26b44a448add3a0657fe
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,362 +0,0 @@
|
||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!29 &1
|
|
||||||
OcclusionCullingSettings:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
serializedVersion: 2
|
|
||||||
m_OcclusionBakeSettings:
|
|
||||||
smallestOccluder: 5
|
|
||||||
smallestHole: 0.25
|
|
||||||
backfaceThreshold: 100
|
|
||||||
m_SceneGUID: 00000000000000000000000000000000
|
|
||||||
m_OcclusionCullingData: {fileID: 0}
|
|
||||||
--- !u!104 &2
|
|
||||||
RenderSettings:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
serializedVersion: 9
|
|
||||||
m_Fog: 0
|
|
||||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
|
||||||
m_FogMode: 3
|
|
||||||
m_FogDensity: 0.01
|
|
||||||
m_LinearFogStart: 0
|
|
||||||
m_LinearFogEnd: 300
|
|
||||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
|
||||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
|
||||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
|
||||||
m_AmbientIntensity: 1
|
|
||||||
m_AmbientMode: 0
|
|
||||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
|
||||||
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
|
|
||||||
m_HaloStrength: 0.5
|
|
||||||
m_FlareStrength: 1
|
|
||||||
m_FlareFadeSpeed: 3
|
|
||||||
m_HaloTexture: {fileID: 0}
|
|
||||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
|
||||||
m_DefaultReflectionMode: 0
|
|
||||||
m_DefaultReflectionResolution: 128
|
|
||||||
m_ReflectionBounces: 1
|
|
||||||
m_ReflectionIntensity: 1
|
|
||||||
m_CustomReflection: {fileID: 0}
|
|
||||||
m_Sun: {fileID: 0}
|
|
||||||
m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1}
|
|
||||||
m_UseRadianceAmbientProbe: 0
|
|
||||||
--- !u!157 &3
|
|
||||||
LightmapSettings:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
serializedVersion: 12
|
|
||||||
m_GIWorkflowMode: 1
|
|
||||||
m_GISettings:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_BounceScale: 1
|
|
||||||
m_IndirectOutputScale: 1
|
|
||||||
m_AlbedoBoost: 1
|
|
||||||
m_EnvironmentLightingMode: 0
|
|
||||||
m_EnableBakedLightmaps: 1
|
|
||||||
m_EnableRealtimeLightmaps: 0
|
|
||||||
m_LightmapEditorSettings:
|
|
||||||
serializedVersion: 12
|
|
||||||
m_Resolution: 2
|
|
||||||
m_BakeResolution: 40
|
|
||||||
m_AtlasSize: 1024
|
|
||||||
m_AO: 0
|
|
||||||
m_AOMaxDistance: 1
|
|
||||||
m_CompAOExponent: 1
|
|
||||||
m_CompAOExponentDirect: 0
|
|
||||||
m_ExtractAmbientOcclusion: 0
|
|
||||||
m_Padding: 2
|
|
||||||
m_LightmapParameters: {fileID: 0}
|
|
||||||
m_LightmapsBakeMode: 1
|
|
||||||
m_TextureCompression: 1
|
|
||||||
m_FinalGather: 0
|
|
||||||
m_FinalGatherFiltering: 1
|
|
||||||
m_FinalGatherRayCount: 256
|
|
||||||
m_ReflectionCompression: 2
|
|
||||||
m_MixedBakeMode: 2
|
|
||||||
m_BakeBackend: 1
|
|
||||||
m_PVRSampling: 1
|
|
||||||
m_PVRDirectSampleCount: 32
|
|
||||||
m_PVRSampleCount: 512
|
|
||||||
m_PVRBounces: 2
|
|
||||||
m_PVREnvironmentSampleCount: 256
|
|
||||||
m_PVREnvironmentReferencePointCount: 2048
|
|
||||||
m_PVRFilteringMode: 1
|
|
||||||
m_PVRDenoiserTypeDirect: 1
|
|
||||||
m_PVRDenoiserTypeIndirect: 1
|
|
||||||
m_PVRDenoiserTypeAO: 1
|
|
||||||
m_PVRFilterTypeDirect: 0
|
|
||||||
m_PVRFilterTypeIndirect: 0
|
|
||||||
m_PVRFilterTypeAO: 0
|
|
||||||
m_PVREnvironmentMIS: 1
|
|
||||||
m_PVRCulling: 1
|
|
||||||
m_PVRFilteringGaussRadiusDirect: 1
|
|
||||||
m_PVRFilteringGaussRadiusIndirect: 5
|
|
||||||
m_PVRFilteringGaussRadiusAO: 2
|
|
||||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
|
||||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
|
||||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
|
||||||
m_ExportTrainingData: 0
|
|
||||||
m_TrainingDataDestination: TrainingData
|
|
||||||
m_LightProbeSampleCountMultiplier: 4
|
|
||||||
m_LightingDataAsset: {fileID: 0}
|
|
||||||
m_LightingSettings: {fileID: 0}
|
|
||||||
--- !u!196 &4
|
|
||||||
NavMeshSettings:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_BuildSettings:
|
|
||||||
serializedVersion: 3
|
|
||||||
agentTypeID: 0
|
|
||||||
agentRadius: 0.5
|
|
||||||
agentHeight: 2
|
|
||||||
agentSlope: 45
|
|
||||||
agentClimb: 0.4
|
|
||||||
ledgeDropHeight: 0
|
|
||||||
maxJumpAcrossDistance: 0
|
|
||||||
minRegionArea: 2
|
|
||||||
manualCellSize: 0
|
|
||||||
cellSize: 0.16666667
|
|
||||||
manualTileSize: 0
|
|
||||||
tileSize: 256
|
|
||||||
buildHeightMesh: 0
|
|
||||||
maxJobWorkers: 0
|
|
||||||
preserveTilesOutsideBounds: 0
|
|
||||||
debug:
|
|
||||||
m_Flags: 0
|
|
||||||
m_NavMeshData: {fileID: 0}
|
|
||||||
--- !u!1 &1475525420
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1475525423}
|
|
||||||
- component: {fileID: 1475525422}
|
|
||||||
- component: {fileID: 1475525421}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: Main Camera
|
|
||||||
m_TagString: MainCamera
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!81 &1475525421
|
|
||||||
AudioListener:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1475525420}
|
|
||||||
m_Enabled: 1
|
|
||||||
--- !u!20 &1475525422
|
|
||||||
Camera:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1475525420}
|
|
||||||
m_Enabled: 1
|
|
||||||
serializedVersion: 2
|
|
||||||
m_ClearFlags: 1
|
|
||||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
|
||||||
m_projectionMatrixMode: 1
|
|
||||||
m_GateFitMode: 2
|
|
||||||
m_FOVAxisMode: 0
|
|
||||||
m_Iso: 200
|
|
||||||
m_ShutterSpeed: 0.005
|
|
||||||
m_Aperture: 16
|
|
||||||
m_FocusDistance: 10
|
|
||||||
m_FocalLength: 50
|
|
||||||
m_BladeCount: 5
|
|
||||||
m_Curvature: {x: 2, y: 11}
|
|
||||||
m_BarrelClipping: 0.25
|
|
||||||
m_Anamorphism: 0
|
|
||||||
m_SensorSize: {x: 36, y: 24}
|
|
||||||
m_LensShift: {x: 0, y: 0}
|
|
||||||
m_NormalizedViewPortRect:
|
|
||||||
serializedVersion: 2
|
|
||||||
x: 0
|
|
||||||
y: 0
|
|
||||||
width: 1
|
|
||||||
height: 1
|
|
||||||
near clip plane: 0.3
|
|
||||||
far clip plane: 1000
|
|
||||||
field of view: 60
|
|
||||||
orthographic: 0
|
|
||||||
orthographic size: 5
|
|
||||||
m_Depth: -1
|
|
||||||
m_CullingMask:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_RenderingPath: -1
|
|
||||||
m_TargetTexture: {fileID: 0}
|
|
||||||
m_TargetDisplay: 0
|
|
||||||
m_TargetEye: 3
|
|
||||||
m_HDR: 1
|
|
||||||
m_AllowMSAA: 1
|
|
||||||
m_AllowDynamicResolution: 0
|
|
||||||
m_ForceIntoRT: 0
|
|
||||||
m_OcclusionCulling: 1
|
|
||||||
m_StereoConvergence: 10
|
|
||||||
m_StereoSeparation: 0.022
|
|
||||||
--- !u!4 &1475525423
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1475525420}
|
|
||||||
serializedVersion: 2
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 1, z: -10}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!1 &1674109924
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1674109926}
|
|
||||||
- component: {fileID: 1674109925}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: Bootstrap
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!114 &1674109925
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1674109924}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 639006a739675484884778c298eebdc4, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
--- !u!4 &1674109926
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1674109924}
|
|
||||||
serializedVersion: 2
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!1 &2040361796
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 2040361798}
|
|
||||||
- component: {fileID: 2040361797}
|
|
||||||
m_Layer: 0
|
|
||||||
m_Name: Directional Light
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!108 &2040361797
|
|
||||||
Light:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 2040361796}
|
|
||||||
m_Enabled: 1
|
|
||||||
serializedVersion: 10
|
|
||||||
m_Type: 1
|
|
||||||
m_Shape: 0
|
|
||||||
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
|
|
||||||
m_Intensity: 1
|
|
||||||
m_Range: 10
|
|
||||||
m_SpotAngle: 30
|
|
||||||
m_InnerSpotAngle: 21.80208
|
|
||||||
m_CookieSize: 10
|
|
||||||
m_Shadows:
|
|
||||||
m_Type: 2
|
|
||||||
m_Resolution: -1
|
|
||||||
m_CustomResolution: -1
|
|
||||||
m_Strength: 1
|
|
||||||
m_Bias: 0.05
|
|
||||||
m_NormalBias: 0.4
|
|
||||||
m_NearPlane: 0.2
|
|
||||||
m_CullingMatrixOverride:
|
|
||||||
e00: 1
|
|
||||||
e01: 0
|
|
||||||
e02: 0
|
|
||||||
e03: 0
|
|
||||||
e10: 0
|
|
||||||
e11: 1
|
|
||||||
e12: 0
|
|
||||||
e13: 0
|
|
||||||
e20: 0
|
|
||||||
e21: 0
|
|
||||||
e22: 1
|
|
||||||
e23: 0
|
|
||||||
e30: 0
|
|
||||||
e31: 0
|
|
||||||
e32: 0
|
|
||||||
e33: 1
|
|
||||||
m_UseCullingMatrixOverride: 0
|
|
||||||
m_Cookie: {fileID: 0}
|
|
||||||
m_DrawHalo: 0
|
|
||||||
m_Flare: {fileID: 0}
|
|
||||||
m_RenderMode: 0
|
|
||||||
m_CullingMask:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_RenderingLayerMask: 1
|
|
||||||
m_Lightmapping: 4
|
|
||||||
m_LightShadowCasterMode: 0
|
|
||||||
m_AreaSize: {x: 1, y: 1}
|
|
||||||
m_BounceIntensity: 1
|
|
||||||
m_ColorTemperature: 6570
|
|
||||||
m_UseColorTemperature: 0
|
|
||||||
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
m_UseBoundingSphereOverride: 0
|
|
||||||
m_UseViewFrustumForShadowCasterCull: 1
|
|
||||||
m_ShadowRadius: 0
|
|
||||||
m_ShadowAngle: 0
|
|
||||||
--- !u!4 &2040361798
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 2040361796}
|
|
||||||
serializedVersion: 2
|
|
||||||
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
|
|
||||||
m_LocalPosition: {x: 0, y: 3, z: 0}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
|
|
||||||
--- !u!1660057539 &9223372036854775807
|
|
||||||
SceneRoots:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_Roots:
|
|
||||||
- {fileID: 1475525423}
|
|
||||||
- {fileID: 2040361798}
|
|
||||||
- {fileID: 1674109926}
|
|
|
@ -1,7 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 528018d8add4a724bb1e36008449a904
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2326b426d539e084dbddf7f7c23ed1bd
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 241df8eaf3a34dc47a0873c37ddb2695
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,267 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
|
||||||
using UnityEditor.VersionControl;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.Conf
|
|
||||||
{
|
|
||||||
public interface IRule<T>
|
|
||||||
{
|
|
||||||
void InheritParent(T parentRule);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public interface IMethodRule<R> where R: IRule<R>
|
|
||||||
{
|
|
||||||
string Name { get; set; }
|
|
||||||
NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
R Rule { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class MethodRuleBase<R> : IMethodRule<R> where R : IRule<R>
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
public R Rule { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ITypeRule<T, R> where T: IMethodRule<R> where R : IRule<R>
|
|
||||||
{
|
|
||||||
string Name { get; set; }
|
|
||||||
|
|
||||||
NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
R Rule { get; set; }
|
|
||||||
|
|
||||||
List<T> Methods { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class TypeRuleBase<T, R> : ITypeRule<T, R> where T : IMethodRule<R> where R : IRule<R>
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
public R Rule { get; set; }
|
|
||||||
|
|
||||||
public List<T> Methods { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IAssemblyRule<TType, TMethod, TRule> where TType : ITypeRule<TMethod, TRule> where TMethod : IMethodRule<TRule> where TRule : IRule<TRule>
|
|
||||||
{
|
|
||||||
string Name { get; set; }
|
|
||||||
|
|
||||||
TRule Rule { get; set; }
|
|
||||||
|
|
||||||
List<TType> Types { get; set; }
|
|
||||||
}
|
|
||||||
public abstract class AssemblyRuleBase<TType, TMethod, TRule> : IAssemblyRule<TType, TMethod, TRule> where TType : ITypeRule<TMethod, TRule> where TMethod : IMethodRule<TRule> where TRule : IRule<TRule>
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public TRule Rule { get; set; }
|
|
||||||
|
|
||||||
public List<TType> Types { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class XmlAssemblyTypeMethodRuleParser<TAssembly, TType, TMethod, TRule>
|
|
||||||
where TMethod : IMethodRule<TRule>, new()
|
|
||||||
where TType : ITypeRule<TMethod, TRule>, new()
|
|
||||||
where TAssembly : IAssemblyRule<TType, TMethod, TRule>, new()
|
|
||||||
where TRule : IRule<TRule>, new()
|
|
||||||
{
|
|
||||||
private readonly HashSet<string> _toObfuscatedAssemblyNames;
|
|
||||||
private readonly Func<string, XmlElement, TRule> _ruleParser;
|
|
||||||
private readonly Action<string, XmlElement> _unknownNodeTypeHandler;
|
|
||||||
private readonly Dictionary<string, TAssembly> _assemblySpecs = new Dictionary<string, TAssembly>();
|
|
||||||
|
|
||||||
public XmlAssemblyTypeMethodRuleParser(IEnumerable<string> toObfuscatedAssemblyNames, Func<string, XmlElement, TRule> ruleParser, Action<string, XmlElement> unknownNodeTypeHandler)
|
|
||||||
{
|
|
||||||
_toObfuscatedAssemblyNames = new HashSet<string>(toObfuscatedAssemblyNames);
|
|
||||||
_ruleParser = ruleParser;
|
|
||||||
_unknownNodeTypeHandler = unknownNodeTypeHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<string, TAssembly> AssemblySpecs => _assemblySpecs;
|
|
||||||
|
|
||||||
public void LoadConfigs(IEnumerable<string> configFiles)
|
|
||||||
{
|
|
||||||
foreach (var configFile in configFiles)
|
|
||||||
{
|
|
||||||
LoadConfig(configFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadConfig(string configFile)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(configFile))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, file name is empty");
|
|
||||||
}
|
|
||||||
Debug.Log($"ConfigurableObfuscationPolicy::LoadConfig {configFile}");
|
|
||||||
var doc = new XmlDocument();
|
|
||||||
doc.Load(configFile);
|
|
||||||
var root = doc.DocumentElement;
|
|
||||||
if (root.Name != "obfuz")
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, root name should be 'obfuz'");
|
|
||||||
}
|
|
||||||
foreach (XmlNode node in root.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "assembly":
|
|
||||||
{
|
|
||||||
TAssembly assSpec = ParseAssembly(configFile, ele);
|
|
||||||
_assemblySpecs.Add(assSpec.Name, assSpec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if (_unknownNodeTypeHandler == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
_unknownNodeTypeHandler(configFile, ele);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private TAssembly ParseAssembly(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
var assemblySpec = new TAssembly();
|
|
||||||
string name = ele.GetAttribute("name");
|
|
||||||
if (!_toObfuscatedAssemblyNames.Contains(name))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, assembly name {name} isn't in toObfuscatedAssemblyNames");
|
|
||||||
}
|
|
||||||
if (_assemblySpecs.ContainsKey(name))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, assembly name {name} is duplicated");
|
|
||||||
}
|
|
||||||
assemblySpec.Name = name;
|
|
||||||
assemblySpec.Rule = _ruleParser(configFile, ele);
|
|
||||||
|
|
||||||
var types = new List<TType>();
|
|
||||||
assemblySpec.Types = types;
|
|
||||||
foreach (XmlNode node in ele.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement childEle))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (childEle.Name)
|
|
||||||
{
|
|
||||||
case "type":
|
|
||||||
{
|
|
||||||
types.Add(ParseType(configFile, childEle));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {childEle.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assemblySpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TType ParseType(string configFile, XmlElement element)
|
|
||||||
{
|
|
||||||
var typeSpec = new TType();
|
|
||||||
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
typeSpec.Name = name;
|
|
||||||
typeSpec.NameMatcher = new NameMatcher(name);
|
|
||||||
typeSpec.Rule = _ruleParser(configFile, element);
|
|
||||||
|
|
||||||
var methods = new List<TMethod>();
|
|
||||||
typeSpec.Methods = methods;
|
|
||||||
foreach (XmlNode node in element.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "method":
|
|
||||||
{
|
|
||||||
methods.Add(ParseMethod(configFile, ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return typeSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TMethod ParseMethod(string configFile, XmlElement element)
|
|
||||||
{
|
|
||||||
var methodSpec = new TMethod();
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
methodSpec.Name = name;
|
|
||||||
methodSpec.NameMatcher = new NameMatcher(name);
|
|
||||||
methodSpec.Rule = _ruleParser(configFile, element);
|
|
||||||
return methodSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TRule GetMethodRule(MethodDef method, TRule defaultRule)
|
|
||||||
{
|
|
||||||
var assemblyName = method.DeclaringType.Module.Assembly.Name;
|
|
||||||
if (!_assemblySpecs.TryGetValue(assemblyName, out var assSpec))
|
|
||||||
{
|
|
||||||
return defaultRule;
|
|
||||||
}
|
|
||||||
string declaringTypeName = method.DeclaringType.FullName;
|
|
||||||
foreach (var typeSpec in assSpec.Types)
|
|
||||||
{
|
|
||||||
if (typeSpec.NameMatcher.IsMatch(declaringTypeName))
|
|
||||||
{
|
|
||||||
foreach (var methodSpec in typeSpec.Methods)
|
|
||||||
{
|
|
||||||
if (methodSpec.NameMatcher.IsMatch(method.Name))
|
|
||||||
{
|
|
||||||
return methodSpec.Rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return typeSpec.Rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assSpec.Rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InheritParentRules(TRule defaultRule)
|
|
||||||
{
|
|
||||||
foreach (TAssembly assSpec in _assemblySpecs.Values)
|
|
||||||
{
|
|
||||||
assSpec.Rule.InheritParent(defaultRule);
|
|
||||||
foreach (TType typeSpec in assSpec.Types)
|
|
||||||
{
|
|
||||||
typeSpec.Rule.InheritParent(assSpec.Rule);
|
|
||||||
foreach (TMethod methodSpec in typeSpec.Methods)
|
|
||||||
{
|
|
||||||
methodSpec.Rule.InheritParent(typeSpec.Rule);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 36a3e142db81f6d4bb54938525e31973
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,208 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
|
||||||
using UnityEditor.VersionControl;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.Conf
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class XmlFieldRuleParser<R> where R : class, new()
|
|
||||||
{
|
|
||||||
private readonly HashSet<string> _toObfuscatedAssemblyNames;
|
|
||||||
private readonly Func<string, XmlElement, R> _ruleParser;
|
|
||||||
private readonly Action<string, XmlElement> _unknownNodeTypeHandler;
|
|
||||||
private readonly Dictionary<string, AssemblySpec> _assemblySpecs = new Dictionary<string, AssemblySpec>();
|
|
||||||
|
|
||||||
|
|
||||||
private class FieldSpec
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
public NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
public R Rule { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TypeSpec
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public NameMatcher NameMatcher { get; set; }
|
|
||||||
|
|
||||||
public List<FieldSpec> Fields { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AssemblySpec
|
|
||||||
{
|
|
||||||
public string Name { get; set; }
|
|
||||||
|
|
||||||
public List<TypeSpec> Types { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public XmlFieldRuleParser(IEnumerable<string> toObfuscatedAssemblyNames, Func<string, XmlElement, R> ruleParser, Action<string, XmlElement> unknownNodeTypeHandler)
|
|
||||||
{
|
|
||||||
_toObfuscatedAssemblyNames = new HashSet<string>(toObfuscatedAssemblyNames);
|
|
||||||
_ruleParser = ruleParser;
|
|
||||||
_unknownNodeTypeHandler = unknownNodeTypeHandler;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadConfigs(IEnumerable<string> configFiles)
|
|
||||||
{
|
|
||||||
foreach (var configFile in configFiles)
|
|
||||||
{
|
|
||||||
LoadConfig(configFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadConfig(string configFile)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(configFile))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, file name is empty");
|
|
||||||
}
|
|
||||||
var doc = new XmlDocument();
|
|
||||||
doc.Load(configFile);
|
|
||||||
var root = doc.DocumentElement;
|
|
||||||
if (root.Name != "obfuz")
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, root name should be 'obfuz'");
|
|
||||||
}
|
|
||||||
foreach (XmlNode node in root.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "assembly":
|
|
||||||
{
|
|
||||||
AssemblySpec assSpec = ParseAssembly(configFile, ele);
|
|
||||||
_assemblySpecs.Add(assSpec.Name, assSpec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
if (_unknownNodeTypeHandler == null)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
_unknownNodeTypeHandler(configFile, ele);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private AssemblySpec ParseAssembly(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
var assemblySpec = new AssemblySpec();
|
|
||||||
string name = ele.GetAttribute("name");
|
|
||||||
if (!_toObfuscatedAssemblyNames.Contains(name))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, assembly name {name} isn't in toObfuscatedAssemblyNames");
|
|
||||||
}
|
|
||||||
if (_assemblySpecs.ContainsKey(name))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, assembly name {name} is duplicated");
|
|
||||||
}
|
|
||||||
assemblySpec.Name = name;
|
|
||||||
|
|
||||||
var types = new List<TypeSpec>();
|
|
||||||
assemblySpec.Types = types;
|
|
||||||
foreach (XmlNode node in ele.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement childEle))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (childEle.Name)
|
|
||||||
{
|
|
||||||
case "type":
|
|
||||||
{
|
|
||||||
types.Add(ParseType(configFile, childEle));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {childEle.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assemblySpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeSpec ParseType(string configFile, XmlElement element)
|
|
||||||
{
|
|
||||||
var typeSpec = new TypeSpec();
|
|
||||||
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
typeSpec.Name = name;
|
|
||||||
typeSpec.NameMatcher = new NameMatcher(name);
|
|
||||||
|
|
||||||
var fields = new List<FieldSpec>();
|
|
||||||
typeSpec.Fields = fields;
|
|
||||||
foreach (XmlNode node in element.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "field":
|
|
||||||
{
|
|
||||||
fields.Add(ParseField(configFile, ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return typeSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FieldSpec ParseField(string configFile, XmlElement element)
|
|
||||||
{
|
|
||||||
var fieldSpec = new FieldSpec();
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
fieldSpec.Name = name;
|
|
||||||
fieldSpec.NameMatcher = new NameMatcher(name);
|
|
||||||
fieldSpec.Rule = _ruleParser(configFile, element);
|
|
||||||
return fieldSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
public R GetFieldRule(FieldDef field)
|
|
||||||
{
|
|
||||||
var assemblyName = field.DeclaringType.Module.Assembly.Name;
|
|
||||||
if (!_assemblySpecs.TryGetValue(assemblyName, out var assSpec))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
string declaringTypeName = field.DeclaringType.FullName;
|
|
||||||
foreach (var typeSpec in assSpec.Types)
|
|
||||||
{
|
|
||||||
if (typeSpec.NameMatcher.IsMatch(declaringTypeName))
|
|
||||||
{
|
|
||||||
foreach (var fieldSpec in typeSpec.Fields)
|
|
||||||
{
|
|
||||||
if (fieldSpec.NameMatcher.IsMatch(field.Name))
|
|
||||||
{
|
|
||||||
return fieldSpec.Rule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 1578270b9b81e1e4dba84d562c91090f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,547 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using Obfuz.ObfusPasses;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz
|
|
||||||
{
|
|
||||||
public class ConfigurablePassPolicy
|
|
||||||
{
|
|
||||||
class PassRule
|
|
||||||
{
|
|
||||||
public ObfuscationPassType? enablePasses;
|
|
||||||
public ObfuscationPassType? disablePasses;
|
|
||||||
public ObfuscationPassType? addPasses;
|
|
||||||
public ObfuscationPassType? removePasses;
|
|
||||||
public ObfuscationPassType finalPasses;
|
|
||||||
|
|
||||||
public void InheritParent(PassRule parentRule, ObfuscationPassType globalEnabledPasses)
|
|
||||||
{
|
|
||||||
finalPasses = parentRule.finalPasses;
|
|
||||||
if (enablePasses != null)
|
|
||||||
{
|
|
||||||
finalPasses = enablePasses.Value;
|
|
||||||
}
|
|
||||||
if (disablePasses != null)
|
|
||||||
{
|
|
||||||
finalPasses = ~disablePasses.Value;
|
|
||||||
}
|
|
||||||
if (addPasses != null)
|
|
||||||
{
|
|
||||||
finalPasses |= addPasses.Value;
|
|
||||||
}
|
|
||||||
if (removePasses != null)
|
|
||||||
{
|
|
||||||
finalPasses &= ~removePasses.Value;
|
|
||||||
}
|
|
||||||
finalPasses &= globalEnabledPasses;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SpecBase
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public NameMatcher nameMatcher;
|
|
||||||
public PassRule rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodSpec : SpecBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class FieldSpec : SpecBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class PropertySpec : SpecBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class EventSpec : SpecBase
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class TypeSpec : SpecBase
|
|
||||||
{
|
|
||||||
public List<FieldSpec> fields = new List<FieldSpec>();
|
|
||||||
public List<MethodSpec> methods = new List<MethodSpec>();
|
|
||||||
public List<PropertySpec> properties = new List<PropertySpec>();
|
|
||||||
public List<EventSpec> events = new List<EventSpec>();
|
|
||||||
}
|
|
||||||
|
|
||||||
class AssemblySpec
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public NameMatcher nameMatcher;
|
|
||||||
public PassRule rule;
|
|
||||||
public List<TypeSpec> types = new List<TypeSpec>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly ObfuscationPassType _enabledPasses;
|
|
||||||
private readonly HashSet<string> _toObfuscatedAssemblyNames;
|
|
||||||
private readonly List<AssemblySpec> _assemblySpecs = new List<AssemblySpec>();
|
|
||||||
private readonly PassRule _defaultPassRule;
|
|
||||||
|
|
||||||
private string _curLoadingConfig;
|
|
||||||
|
|
||||||
public ConfigurablePassPolicy(IEnumerable<string> toObfuscatedAssemblyNames, ObfuscationPassType enabledPasses, List<string> configFiles)
|
|
||||||
{
|
|
||||||
_toObfuscatedAssemblyNames = new HashSet<string>(toObfuscatedAssemblyNames);
|
|
||||||
_enabledPasses = enabledPasses;
|
|
||||||
_defaultPassRule = new PassRule { finalPasses = enabledPasses };
|
|
||||||
LoadConfigs(configFiles);
|
|
||||||
InheritParentRules(enabledPasses);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadConfigs(IEnumerable<string> configFiles)
|
|
||||||
{
|
|
||||||
foreach (var configFile in configFiles)
|
|
||||||
{
|
|
||||||
LoadConfig(configFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InheritParentRules(ObfuscationPassType enablePasses)
|
|
||||||
{
|
|
||||||
var defaultRule = new PassRule
|
|
||||||
{
|
|
||||||
enablePasses = enablePasses,
|
|
||||||
finalPasses = enablePasses,
|
|
||||||
};
|
|
||||||
foreach (AssemblySpec assSpec in _assemblySpecs)
|
|
||||||
{
|
|
||||||
assSpec.rule.InheritParent(defaultRule, enablePasses);
|
|
||||||
foreach (TypeSpec typeSpec in assSpec.types)
|
|
||||||
{
|
|
||||||
typeSpec.rule.InheritParent(assSpec.rule, enablePasses);
|
|
||||||
foreach (FieldSpec fieldSpec in typeSpec.fields)
|
|
||||||
{
|
|
||||||
fieldSpec.rule.InheritParent(typeSpec.rule, enablePasses);
|
|
||||||
}
|
|
||||||
foreach (MethodSpec methodSpec in typeSpec.methods)
|
|
||||||
{
|
|
||||||
methodSpec.rule.InheritParent(typeSpec.rule, enablePasses);
|
|
||||||
}
|
|
||||||
foreach (PropertySpec propertySpec in typeSpec.properties)
|
|
||||||
{
|
|
||||||
propertySpec.rule.InheritParent(typeSpec.rule, enablePasses);
|
|
||||||
}
|
|
||||||
foreach (EventSpec eventSpec in typeSpec.events)
|
|
||||||
{
|
|
||||||
eventSpec.rule.InheritParent(typeSpec.rule, enablePasses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadConfig(string configFile)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(configFile))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, file name is empty");
|
|
||||||
}
|
|
||||||
_curLoadingConfig = configFile;
|
|
||||||
|
|
||||||
Debug.Log($"ConfigurablePassPolicy::LoadConfig {configFile}");
|
|
||||||
var doc = new XmlDocument();
|
|
||||||
doc.Load(configFile);
|
|
||||||
var root = doc.DocumentElement;
|
|
||||||
if (root.Name != "obfuz")
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, root name should be 'obfuz'");
|
|
||||||
}
|
|
||||||
foreach (XmlNode node in root.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "assembly":
|
|
||||||
{
|
|
||||||
AssemblySpec assSpec = ParseAssembly(ele);
|
|
||||||
_assemblySpecs.Add(assSpec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {configFile}, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(bool, ObfuscationPassType) ParseObfuscationType(string obfuscationPassTypesStr)
|
|
||||||
{
|
|
||||||
bool delta = false;
|
|
||||||
if (obfuscationPassTypesStr[0] == '+' || obfuscationPassTypesStr[0] == '-')
|
|
||||||
{
|
|
||||||
delta = true;
|
|
||||||
obfuscationPassTypesStr = obfuscationPassTypesStr.Substring(1);
|
|
||||||
}
|
|
||||||
ObfuscationPassType passType = ObfuscationPassType.None;
|
|
||||||
foreach (var passName in obfuscationPassTypesStr.Split('|'))
|
|
||||||
{
|
|
||||||
if (Enum.TryParse< ObfuscationPassType>(passName, out var pass))
|
|
||||||
{
|
|
||||||
passType |= pass;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, unknown pass type {passName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (delta, passType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PassRule ParseRule(XmlElement ele)
|
|
||||||
{
|
|
||||||
var r = new PassRule();
|
|
||||||
if (ele.HasAttribute("enable"))
|
|
||||||
{
|
|
||||||
string enablePassStr = ele.GetAttribute("enable");
|
|
||||||
if (string.IsNullOrEmpty(enablePassStr))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, enable attribute is empty");
|
|
||||||
}
|
|
||||||
var (delta, passType) = ParseObfuscationType(enablePassStr);
|
|
||||||
if (delta)
|
|
||||||
{
|
|
||||||
r.addPasses = passType;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r.enablePasses = passType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("disable"))
|
|
||||||
{
|
|
||||||
string disablePassStr = ele.GetAttribute("disable");
|
|
||||||
if (string.IsNullOrEmpty(disablePassStr))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, disable attribute is empty");
|
|
||||||
}
|
|
||||||
var (delta, passType) = ParseObfuscationType(disablePassStr);
|
|
||||||
if (delta)
|
|
||||||
{
|
|
||||||
r.removePasses = passType;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r.disablePasses = passType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (r.enablePasses != null && (r.disablePasses != null || r.addPasses != null || r.removePasses != null))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, enable and disable can't be used together");
|
|
||||||
}
|
|
||||||
if (r.disablePasses != null && (r.enablePasses != null || r.addPasses != null || r.removePasses != null))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, disable and enable can't be used together");
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
private AssemblySpec ParseAssembly(XmlElement ele)
|
|
||||||
{
|
|
||||||
var assemblySpec = new AssemblySpec();
|
|
||||||
string name = ele.GetAttribute("name");
|
|
||||||
if (!_toObfuscatedAssemblyNames.Contains(name))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file {_curLoadingConfig}, assembly name {name} isn't in toObfuscatedAssemblyNames");
|
|
||||||
}
|
|
||||||
assemblySpec.name = name;
|
|
||||||
assemblySpec.nameMatcher = new NameMatcher(name);
|
|
||||||
assemblySpec.rule = ParseRule(ele);
|
|
||||||
|
|
||||||
|
|
||||||
var types = assemblySpec.types;
|
|
||||||
foreach (XmlNode node in ele.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement childEle))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (childEle.Name)
|
|
||||||
{
|
|
||||||
case "type":
|
|
||||||
{
|
|
||||||
types.Add(ParseType(childEle));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {childEle.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assemblySpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeSpec ParseType(XmlElement element)
|
|
||||||
{
|
|
||||||
var typeSpec = new TypeSpec();
|
|
||||||
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
typeSpec.name = name;
|
|
||||||
typeSpec.nameMatcher = new NameMatcher(name);
|
|
||||||
typeSpec.rule = ParseRule(element);
|
|
||||||
|
|
||||||
List<FieldSpec> fields = typeSpec.fields;
|
|
||||||
List<MethodSpec> methods = typeSpec.methods;
|
|
||||||
List<PropertySpec> properties = typeSpec.properties;
|
|
||||||
List<EventSpec> events = typeSpec.events;
|
|
||||||
foreach (XmlNode node in element.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "field":
|
|
||||||
{
|
|
||||||
fields.Add(ParseField(ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "method":
|
|
||||||
{
|
|
||||||
methods.Add(ParseMethod(ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "property":
|
|
||||||
{
|
|
||||||
properties.Add(ParseProperty(ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "event":
|
|
||||||
{
|
|
||||||
events.Add(ParseEvent(ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return typeSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseSpecObject(XmlElement element, SpecBase obj)
|
|
||||||
{
|
|
||||||
string name = element.GetAttribute("name");
|
|
||||||
obj.name = name;
|
|
||||||
obj.nameMatcher = new NameMatcher(name);
|
|
||||||
obj.rule = ParseRule(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
private FieldSpec ParseField(XmlElement element)
|
|
||||||
{
|
|
||||||
var fieldSpec = new FieldSpec();
|
|
||||||
ParseSpecObject(element, fieldSpec);
|
|
||||||
return fieldSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MethodSpec ParseMethod(XmlElement element)
|
|
||||||
{
|
|
||||||
var methodSpec = new MethodSpec();
|
|
||||||
ParseSpecObject(element, methodSpec);
|
|
||||||
return methodSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PropertySpec ParseProperty(XmlElement element)
|
|
||||||
{
|
|
||||||
var propertySpec = new PropertySpec();
|
|
||||||
ParseSpecObject(element, propertySpec);
|
|
||||||
return propertySpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private EventSpec ParseEvent(XmlElement element)
|
|
||||||
{
|
|
||||||
var eventSpec = new EventSpec();
|
|
||||||
ParseSpecObject(element, eventSpec);
|
|
||||||
return eventSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<ModuleDef, (AssemblySpec, PassRule)> _modulePassRuleCaches = new Dictionary<ModuleDef, (AssemblySpec, PassRule)>();
|
|
||||||
private readonly Dictionary<TypeDef, (TypeSpec, PassRule)> _typePassRuleCaches = new Dictionary<TypeDef, (TypeSpec, PassRule)>();
|
|
||||||
private readonly Dictionary<MethodDef, (MethodSpec, PassRule)> _methodPassRuleCaches = new Dictionary<MethodDef, (MethodSpec, PassRule)>();
|
|
||||||
private readonly Dictionary<FieldDef, (FieldSpec, PassRule)> _fieldPassRuleCaches = new Dictionary<FieldDef, (FieldSpec, PassRule)>();
|
|
||||||
private readonly Dictionary<PropertyDef, (PropertySpec, PassRule)> _propertyPassRuleCaches = new Dictionary<PropertyDef, (PropertySpec, PassRule)>();
|
|
||||||
private readonly Dictionary<EventDef, (EventSpec, PassRule)> _eventPassRuleCaches = new Dictionary<EventDef, (EventSpec, PassRule)>();
|
|
||||||
|
|
||||||
|
|
||||||
private (AssemblySpec, PassRule) GetAssemblySpec(ModuleDef module)
|
|
||||||
{
|
|
||||||
if (!_modulePassRuleCaches.TryGetValue(module, out var result))
|
|
||||||
{
|
|
||||||
result = (null, _defaultPassRule);
|
|
||||||
string assName = module.Assembly.Name;
|
|
||||||
foreach (var ass in _assemblySpecs)
|
|
||||||
{
|
|
||||||
if (ass.nameMatcher.IsMatch(assName))
|
|
||||||
{
|
|
||||||
result = (ass, _defaultPassRule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_modulePassRuleCaches.Add(module, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private (TypeSpec, PassRule) GetTypeSpec(TypeDef type)
|
|
||||||
{
|
|
||||||
if (!_typePassRuleCaches.TryGetValue(type, out var result))
|
|
||||||
{
|
|
||||||
var assResult = GetAssemblySpec(type.Module);
|
|
||||||
result = (null, assResult.Item2);
|
|
||||||
if (assResult.Item1 != null)
|
|
||||||
{
|
|
||||||
string typeName = type.FullName;
|
|
||||||
foreach (var typeSpec in assResult.Item1.types)
|
|
||||||
{
|
|
||||||
if (typeSpec.nameMatcher.IsMatch(typeName))
|
|
||||||
{
|
|
||||||
result = (typeSpec, typeSpec.rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_typePassRuleCaches.Add(type, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private (MethodSpec, PassRule) GetMethodSpec(MethodDef method)
|
|
||||||
{
|
|
||||||
if (!_methodPassRuleCaches.TryGetValue(method, out var result))
|
|
||||||
{
|
|
||||||
var typeResult = GetTypeSpec(method.DeclaringType);
|
|
||||||
result = (null, typeResult.Item2);
|
|
||||||
if (typeResult.Item1 != null)
|
|
||||||
{
|
|
||||||
string methodName = method.Name;
|
|
||||||
foreach (var methodSpec in typeResult.Item1.methods)
|
|
||||||
{
|
|
||||||
if (methodSpec.nameMatcher.IsMatch(methodName))
|
|
||||||
{
|
|
||||||
result = (methodSpec, methodSpec.rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_methodPassRuleCaches.Add(method, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private (FieldSpec, PassRule) GetFieldSpec(FieldDef field)
|
|
||||||
{
|
|
||||||
if (!_fieldPassRuleCaches.TryGetValue(field, out var result))
|
|
||||||
{
|
|
||||||
var typeResult = GetTypeSpec(field.DeclaringType);
|
|
||||||
result = (null, typeResult.Item2);
|
|
||||||
if (typeResult.Item1 != null)
|
|
||||||
{
|
|
||||||
string fieldName = field.Name;
|
|
||||||
foreach (var fieldSpec in typeResult.Item1.fields)
|
|
||||||
{
|
|
||||||
if (fieldSpec.nameMatcher.IsMatch(fieldName))
|
|
||||||
{
|
|
||||||
result = (fieldSpec, fieldSpec.rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_fieldPassRuleCaches.Add(field, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private (PropertySpec, PassRule) GetPropertySpec(PropertyDef property)
|
|
||||||
{
|
|
||||||
if (!_propertyPassRuleCaches.TryGetValue(property, out var result))
|
|
||||||
{
|
|
||||||
var typeResult = GetTypeSpec(property.DeclaringType);
|
|
||||||
result = (null, typeResult.Item2);
|
|
||||||
if (typeResult.Item1 != null)
|
|
||||||
{
|
|
||||||
string propertyName = property.Name;
|
|
||||||
foreach (var propertySpec in typeResult.Item1.properties)
|
|
||||||
{
|
|
||||||
if (propertySpec.nameMatcher.IsMatch(propertyName))
|
|
||||||
{
|
|
||||||
result = (propertySpec, propertySpec.rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_propertyPassRuleCaches.Add(property, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private (EventSpec, PassRule) GetEventSpec(EventDef eventDef)
|
|
||||||
{
|
|
||||||
if (!_eventPassRuleCaches.TryGetValue(eventDef, out var result))
|
|
||||||
{
|
|
||||||
var typeResult = GetTypeSpec(eventDef.DeclaringType);
|
|
||||||
result = (null, typeResult.Item2);
|
|
||||||
if (typeResult.Item1 != null)
|
|
||||||
{
|
|
||||||
string eventName = eventDef.Name;
|
|
||||||
foreach (var eventSpec in typeResult.Item1.events)
|
|
||||||
{
|
|
||||||
if (eventSpec.nameMatcher.IsMatch(eventName))
|
|
||||||
{
|
|
||||||
result = (eventSpec, eventSpec.rule);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_eventPassRuleCaches.Add(eventDef, result);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ObfuscationPassType GetAssemblyObfuscationPasses(ModuleDef module)
|
|
||||||
{
|
|
||||||
return GetAssemblySpec(module).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType GetTypeObfuscationPasses(TypeDef type)
|
|
||||||
{
|
|
||||||
return GetTypeSpec(type).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType GetMethodObfuscationPasses(MethodDef method)
|
|
||||||
{
|
|
||||||
return GetMethodSpec(method).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType GetFieldObfuscationPasses(FieldDef field)
|
|
||||||
{
|
|
||||||
return GetFieldSpec(field).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType GetPropertyObfuscationPasses(PropertyDef property)
|
|
||||||
{
|
|
||||||
return GetPropertySpec(property).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObfuscationPassType GetEventObfuscationPasses(EventDef eventDef)
|
|
||||||
{
|
|
||||||
return GetEventSpec(eventDef).Item2.finalPasses;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 41044699810a34f4780e14de084bf7d7
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,13 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.Editor
|
|
||||||
{
|
|
||||||
public static class ConstValues
|
|
||||||
{
|
|
||||||
public const string ObfuzInternalSymbolNamePrefix = "$Obfuz$";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: aee7817ed523a5e4ea42104013e8a775
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 3319ebe75a42f3d4d996846ca09ed099
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,344 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using Obfuz.Editor;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.NetworkInformation;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
|
|
||||||
namespace Obfuz.Data
|
|
||||||
{
|
|
||||||
public class ModuleConstFieldAllocator : IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
private ModuleDef _module;
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
private EncryptionScopeInfo _encryptionScope;
|
|
||||||
private RandomCreator _randomCreator;
|
|
||||||
private IEncryptor _encryptor;
|
|
||||||
|
|
||||||
private TypeDef _holderTypeDef;
|
|
||||||
|
|
||||||
class ConstFieldInfo
|
|
||||||
{
|
|
||||||
public FieldDef field;
|
|
||||||
public object value;
|
|
||||||
}
|
|
||||||
|
|
||||||
class AnyComparer : IEqualityComparer<object>
|
|
||||||
{
|
|
||||||
public new bool Equals(object x, object y)
|
|
||||||
{
|
|
||||||
if (x is byte[] xBytes && y is byte[] yBytes)
|
|
||||||
{
|
|
||||||
return StructuralComparisons.StructuralEqualityComparer.Equals(xBytes, yBytes);
|
|
||||||
}
|
|
||||||
return x.Equals(y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int ComputeHashCode(object obj)
|
|
||||||
{
|
|
||||||
return HashUtil.ComputePrimitiveOrStringOrBytesHashCode(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHashCode(object obj)
|
|
||||||
{
|
|
||||||
return ComputeHashCode(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<object, ConstFieldInfo> _allocatedFields = new Dictionary<object, ConstFieldInfo>(new AnyComparer());
|
|
||||||
private readonly Dictionary<FieldDef, ConstFieldInfo> _field2Fields = new Dictionary<FieldDef, ConstFieldInfo>();
|
|
||||||
|
|
||||||
private readonly List<TypeDef> _holderTypeDefs = new List<TypeDef>();
|
|
||||||
private bool _done;
|
|
||||||
|
|
||||||
|
|
||||||
public ModuleConstFieldAllocator(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, GroupByModuleEntityManager moduleEntityManager)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_rvaDataAllocator = rvaDataAllocator;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(ModuleDef mod)
|
|
||||||
{
|
|
||||||
_module = mod;
|
|
||||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
|
||||||
_randomCreator = _encryptionScope.localRandomCreator;
|
|
||||||
_encryptor = _encryptionScope.encryptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int maxFieldCount = 1000;
|
|
||||||
|
|
||||||
|
|
||||||
private TypeSig GetTypeSigOfValue(object value)
|
|
||||||
{
|
|
||||||
if (value is int)
|
|
||||||
return _module.CorLibTypes.Int32;
|
|
||||||
if (value is long)
|
|
||||||
return _module.CorLibTypes.Int64;
|
|
||||||
if (value is float)
|
|
||||||
return _module.CorLibTypes.Single;
|
|
||||||
if (value is double)
|
|
||||||
return _module.CorLibTypes.Double;
|
|
||||||
if (value is string)
|
|
||||||
return _module.CorLibTypes.String;
|
|
||||||
if (value is byte[])
|
|
||||||
return new SZArraySig(_module.CorLibTypes.Byte);
|
|
||||||
throw new NotSupportedException($"Unsupported type: {value.GetType()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConstFieldInfo CreateConstFieldInfo(object value)
|
|
||||||
{
|
|
||||||
if (_holderTypeDef == null || _holderTypeDef.Fields.Count >= maxFieldCount)
|
|
||||||
{
|
|
||||||
_module.EnableTypeDefFindCache = false;
|
|
||||||
ITypeDefOrRef objectTypeRef = _module.Import(typeof(object));
|
|
||||||
_holderTypeDef = new TypeDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ConstFieldHolder${_holderTypeDefs.Count}", objectTypeRef);
|
|
||||||
_module.Types.Add(_holderTypeDef);
|
|
||||||
_holderTypeDefs.Add(_holderTypeDef);
|
|
||||||
_module.EnableTypeDefFindCache = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var field = new FieldDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}RVA_Value{_holderTypeDef.Fields.Count}", new FieldSig(GetTypeSigOfValue(value)), FieldAttributes.Static | FieldAttributes.Public | FieldAttributes.InitOnly);
|
|
||||||
field.DeclaringType = _holderTypeDef;
|
|
||||||
return new ConstFieldInfo
|
|
||||||
{
|
|
||||||
field = field,
|
|
||||||
value = value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private FieldDef AllocateAny(object value)
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("can't Allocate after done");
|
|
||||||
}
|
|
||||||
if (!_allocatedFields.TryGetValue(value, out var field))
|
|
||||||
{
|
|
||||||
field = CreateConstFieldInfo(value);
|
|
||||||
_allocatedFields.Add(value, field);
|
|
||||||
_field2Fields.Add(field.field, field);
|
|
||||||
}
|
|
||||||
return field.field;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(int value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(long value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(float value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(double value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(string value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(byte[] value)
|
|
||||||
{
|
|
||||||
return AllocateAny(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DefaultMetadataImporter GetModuleMetadataImporter()
|
|
||||||
{
|
|
||||||
return _moduleEntityManager.GetDefaultModuleMetadataImporter(_module, _encryptionScopeProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateCCtorOfRvaTypeDef(TypeDef type)
|
|
||||||
{
|
|
||||||
var cctor = new MethodDefUser(".cctor",
|
|
||||||
MethodSig.CreateStatic(_module.CorLibTypes.Void),
|
|
||||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
|
||||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
|
||||||
cctor.DeclaringType = type;
|
|
||||||
//_rvaTypeDef.Methods.Add(cctor);
|
|
||||||
var body = new CilBody();
|
|
||||||
cctor.Body = body;
|
|
||||||
var ins = body.Instructions;
|
|
||||||
|
|
||||||
//IMethod method = _module.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
|
||||||
//Assert.IsNotNull(method);
|
|
||||||
|
|
||||||
|
|
||||||
DefaultMetadataImporter importer = GetModuleMetadataImporter();
|
|
||||||
// TODO. obfuscate init codes
|
|
||||||
foreach (var field in type.Fields)
|
|
||||||
{
|
|
||||||
ConstFieldInfo constInfo = _field2Fields[field];
|
|
||||||
IRandom localRandom = _randomCreator(HashUtil.ComputePrimitiveOrStringOrBytesHashCode(constInfo.value));
|
|
||||||
int ops = EncryptionUtil.GenerateEncryptionOpCodes(localRandom, _encryptor, 4);
|
|
||||||
int salt = localRandom.NextInt();
|
|
||||||
switch (constInfo.value)
|
|
||||||
{
|
|
||||||
case int i:
|
|
||||||
{
|
|
||||||
int encryptedValue = _encryptor.Encrypt(i, ops, salt);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaInt));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case long l:
|
|
||||||
{
|
|
||||||
long encryptedValue = _encryptor.Encrypt(l, ops, salt);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaLong));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case float f:
|
|
||||||
{
|
|
||||||
float encryptedValue = _encryptor.Encrypt(f, ops, salt);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaFloat));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case double d:
|
|
||||||
{
|
|
||||||
double encryptedValue = _encryptor.Encrypt(d, ops, salt);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaDouble));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case string s:
|
|
||||||
{
|
|
||||||
byte[] encryptedValue = _encryptor.Encrypt(s, ops, salt);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
Assert.AreEqual(encryptedValue.Length, rvaData.size);
|
|
||||||
ins.Add(Instruction.CreateLdcI4(encryptedValue.Length));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaString));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case byte[] bs:
|
|
||||||
{
|
|
||||||
byte[] encryptedValue = _encryptor.Encrypt(bs, 0, bs.Length, ops, salt);
|
|
||||||
Assert.AreEqual(encryptedValue.Length, bs.Length);
|
|
||||||
RvaData rvaData = _rvaDataAllocator.Allocate(_module, encryptedValue);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(rvaData.offset));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(bs.Length));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(ops));
|
|
||||||
ins.Add(Instruction.CreateLdcI4(salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptFromRvaBytes));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: throw new NotSupportedException($"Unsupported type: {constInfo.value.GetType()}");
|
|
||||||
}
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Stsfld, field));
|
|
||||||
}
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("Already done");
|
|
||||||
}
|
|
||||||
_done = true;
|
|
||||||
foreach (var typeDef in _holderTypeDefs)
|
|
||||||
{
|
|
||||||
CreateCCtorOfRvaTypeDef(typeDef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConstFieldAllocator
|
|
||||||
{
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly RvaDataAllocator _rvaDataAllocator;
|
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
|
|
||||||
public ConstFieldAllocator(EncryptionScopeProvider encryptionScopeProvider, RvaDataAllocator rvaDataAllocator, GroupByModuleEntityManager moduleEntityManager)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_rvaDataAllocator = rvaDataAllocator;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModuleConstFieldAllocator GetModuleAllocator(ModuleDef mod)
|
|
||||||
{
|
|
||||||
return _moduleEntityManager.GetEntity<ModuleConstFieldAllocator>(mod, () => new ModuleConstFieldAllocator(_encryptionScopeProvider, _rvaDataAllocator, _moduleEntityManager));
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, int value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, long value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, float value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, double value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, byte[] value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public FieldDef Allocate(ModuleDef mod, string value)
|
|
||||||
{
|
|
||||||
return GetModuleAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
foreach (var moduleAllocator in _moduleEntityManager.GetEntities<ModuleConstFieldAllocator>())
|
|
||||||
{
|
|
||||||
moduleAllocator.Done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e75f5cdfd47370d4ea6c4dee7e55a881
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,355 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
|
|
||||||
namespace Obfuz.Data
|
|
||||||
{
|
|
||||||
public struct RvaData
|
|
||||||
{
|
|
||||||
public readonly FieldDef field;
|
|
||||||
public readonly int offset;
|
|
||||||
public readonly int size;
|
|
||||||
|
|
||||||
public RvaData(FieldDef field, int offset, int size)
|
|
||||||
{
|
|
||||||
this.field = field;
|
|
||||||
this.offset = offset;
|
|
||||||
this.size = size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ModuleRvaDataAllocator : GroupByModuleEntityBase
|
|
||||||
{
|
|
||||||
// randomized
|
|
||||||
const int maxRvaDataSize = 0x1000;
|
|
||||||
|
|
||||||
private ModuleDef _module;
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
|
|
||||||
private EncryptionScopeInfo _encryptionScope;
|
|
||||||
private IRandom _random;
|
|
||||||
|
|
||||||
class RvaField
|
|
||||||
{
|
|
||||||
public FieldDef holderDataField;
|
|
||||||
public FieldDef runtimeValueField;
|
|
||||||
public int encryptionOps;
|
|
||||||
public uint size;
|
|
||||||
public List<byte> bytes;
|
|
||||||
public int salt;
|
|
||||||
|
|
||||||
public void FillPaddingToSize(int newSize)
|
|
||||||
{
|
|
||||||
for (int i = bytes.Count; i < newSize; i++)
|
|
||||||
{
|
|
||||||
bytes.Add(0xAB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FillPaddingToEnd()
|
|
||||||
{
|
|
||||||
// fill with random value
|
|
||||||
for (int i = bytes.Count; i < size; i++)
|
|
||||||
{
|
|
||||||
bytes.Add(0xAB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly List<RvaField> _rvaFields = new List<RvaField>();
|
|
||||||
private RvaField _currentField;
|
|
||||||
|
|
||||||
|
|
||||||
private TypeDef _rvaTypeDef;
|
|
||||||
|
|
||||||
private readonly Dictionary<int, TypeDef> _dataHolderTypeBySizes = new Dictionary<int, TypeDef>();
|
|
||||||
private bool _done;
|
|
||||||
|
|
||||||
public ModuleRvaDataAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(ModuleDef mod)
|
|
||||||
{
|
|
||||||
_module = mod;
|
|
||||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
|
||||||
_random = _encryptionScope.localRandomCreator(HashUtil.ComputeHash(mod.Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
private (FieldDef, FieldDef) CreateDataHolderRvaField(TypeDef dataHolderType)
|
|
||||||
{
|
|
||||||
if (_rvaTypeDef == null)
|
|
||||||
{
|
|
||||||
_module.EnableTypeDefFindCache = false;
|
|
||||||
//_rvaTypeDef = _module.Find("$ObfuzRVA$", true);
|
|
||||||
//if (_rvaTypeDef != null)
|
|
||||||
//{
|
|
||||||
// throw new Exception($"can't obfuscate a obfuscated assembly");
|
|
||||||
//}
|
|
||||||
ITypeDefOrRef objectTypeRef = _module.Import(typeof(object));
|
|
||||||
_rvaTypeDef = new TypeDefUser("$Obfuz$RVA$", objectTypeRef);
|
|
||||||
_module.Types.Add(_rvaTypeDef);
|
|
||||||
_module.EnableTypeDefFindCache = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var holderField = new FieldDefUser($"$RVA_Data{_rvaFields.Count}", new FieldSig(dataHolderType.ToTypeSig()), FieldAttributes.InitOnly | FieldAttributes.Static | FieldAttributes.HasFieldRVA);
|
|
||||||
holderField.DeclaringType = _rvaTypeDef;
|
|
||||||
|
|
||||||
var runtimeValueField = new FieldDefUser($"$RVA_Value{_rvaFields.Count}", new FieldSig(new SZArraySig(_module.CorLibTypes.Byte)), FieldAttributes.Static | FieldAttributes.Public);
|
|
||||||
runtimeValueField.DeclaringType = _rvaTypeDef;
|
|
||||||
return (holderField, runtimeValueField);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef GetDataHolderType(int size)
|
|
||||||
{
|
|
||||||
size = (size + 15) & ~15; // align to 6 bytes
|
|
||||||
if (_dataHolderTypeBySizes.TryGetValue(size, out var type))
|
|
||||||
return type;
|
|
||||||
var dataHolderType = new TypeDefUser($"$ObfuzRVA$DataHolder{size}", _module.Import(typeof(ValueType)));
|
|
||||||
dataHolderType.Attributes = TypeAttributes.Public | TypeAttributes.Sealed;
|
|
||||||
dataHolderType.Layout = TypeAttributes.ExplicitLayout;
|
|
||||||
dataHolderType.PackingSize = 1;
|
|
||||||
dataHolderType.ClassSize = (uint)size;
|
|
||||||
_dataHolderTypeBySizes.Add(size, dataHolderType);
|
|
||||||
_module.Types.Add(dataHolderType);
|
|
||||||
return dataHolderType;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int AlignTo(int size, int alignment)
|
|
||||||
{
|
|
||||||
return (size + alignment - 1) & ~(alignment - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private RvaField CreateRvaField(int size)
|
|
||||||
{
|
|
||||||
TypeDef dataHolderType = GetDataHolderType(size);
|
|
||||||
var (holderDataField, runtimeValueField) = CreateDataHolderRvaField(dataHolderType);
|
|
||||||
var newRvaField = new RvaField
|
|
||||||
{
|
|
||||||
holderDataField = holderDataField,
|
|
||||||
runtimeValueField = runtimeValueField,
|
|
||||||
size = dataHolderType.ClassSize,
|
|
||||||
bytes = new List<byte>((int)dataHolderType.ClassSize),
|
|
||||||
encryptionOps = _random.NextInt(),
|
|
||||||
salt = _random.NextInt(),
|
|
||||||
};
|
|
||||||
_rvaFields.Add(newRvaField);
|
|
||||||
return newRvaField;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RvaField GetRvaField(int preservedSize, int alignment)
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("can't GetRvaField after done");
|
|
||||||
}
|
|
||||||
Assert.IsTrue(preservedSize % alignment == 0);
|
|
||||||
// for big size, create a new field
|
|
||||||
if (preservedSize >= maxRvaDataSize)
|
|
||||||
{
|
|
||||||
return CreateRvaField(preservedSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_currentField != null)
|
|
||||||
{
|
|
||||||
int offset = AlignTo(_currentField.bytes.Count, alignment);
|
|
||||||
|
|
||||||
int expectedSize = offset + preservedSize;
|
|
||||||
if (expectedSize <= _currentField.size)
|
|
||||||
{
|
|
||||||
_currentField.FillPaddingToSize(offset);
|
|
||||||
return _currentField;
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentField.FillPaddingToEnd();
|
|
||||||
}
|
|
||||||
_currentField = CreateRvaField(maxRvaDataSize);
|
|
||||||
return _currentField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(int value)
|
|
||||||
{
|
|
||||||
RvaField field = GetRvaField(4, 4);
|
|
||||||
int offset = field.bytes.Count;
|
|
||||||
Assert.IsTrue(offset % 4 == 0);
|
|
||||||
field.bytes.AddRange(BitConverter.GetBytes(value));
|
|
||||||
return new RvaData(field.runtimeValueField, offset, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(long value)
|
|
||||||
{
|
|
||||||
RvaField field = GetRvaField(8, 8);
|
|
||||||
int offset = field.bytes.Count;
|
|
||||||
Assert.IsTrue(offset % 8 == 0);
|
|
||||||
field.bytes.AddRange(BitConverter.GetBytes(value));
|
|
||||||
return new RvaData(field.runtimeValueField, offset, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(float value)
|
|
||||||
{
|
|
||||||
RvaField field = GetRvaField(4, 4);
|
|
||||||
int offset = field.bytes.Count;
|
|
||||||
Assert.IsTrue(offset % 4 == 0);
|
|
||||||
field.bytes.AddRange(BitConverter.GetBytes(value));
|
|
||||||
return new RvaData(field.runtimeValueField, offset, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(double value)
|
|
||||||
{
|
|
||||||
RvaField field = GetRvaField(8, 8);
|
|
||||||
int offset = field.bytes.Count;
|
|
||||||
Assert.IsTrue(offset % 8 == 0);
|
|
||||||
field.bytes.AddRange(BitConverter.GetBytes(value));
|
|
||||||
return new RvaData(field.runtimeValueField, offset, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(string value)
|
|
||||||
{
|
|
||||||
byte[] bytes = Encoding.UTF8.GetBytes(value);
|
|
||||||
return Allocate(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(byte[] value)
|
|
||||||
{
|
|
||||||
RvaField field = GetRvaField(value.Length, 1);
|
|
||||||
int offset = field.bytes.Count;
|
|
||||||
field.bytes.AddRange(value);
|
|
||||||
return new RvaData(field.runtimeValueField, offset, value.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateCCtorOfRvaTypeDef()
|
|
||||||
{
|
|
||||||
if (_rvaTypeDef == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ModuleDef mod = _rvaTypeDef.Module;
|
|
||||||
var cctorMethod = new MethodDefUser(".cctor",
|
|
||||||
MethodSig.CreateStatic(_module.CorLibTypes.Void),
|
|
||||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
|
||||||
MethodAttributes.Static | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName | MethodAttributes.Private);
|
|
||||||
cctorMethod.DeclaringType = _rvaTypeDef;
|
|
||||||
//_rvaTypeDef.Methods.Add(cctor);
|
|
||||||
var body = new CilBody();
|
|
||||||
cctorMethod.Body = body;
|
|
||||||
var ins = body.Instructions;
|
|
||||||
|
|
||||||
DefaultMetadataImporter importer = _moduleEntityManager.GetDefaultModuleMetadataImporter(mod, _encryptionScopeProvider);
|
|
||||||
foreach (var field in _rvaFields)
|
|
||||||
{
|
|
||||||
// ldc
|
|
||||||
// newarr
|
|
||||||
// dup
|
|
||||||
// stsfld
|
|
||||||
// ldtoken
|
|
||||||
// RuntimeHelpers.InitializeArray(array, fieldHandle);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, (int)field.size));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Newarr, field.runtimeValueField.FieldType.Next.ToTypeDefOrRef()));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Dup));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Stsfld, field.runtimeValueField));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldtoken, field.holderDataField));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.InitializedArrayMethod));
|
|
||||||
|
|
||||||
// EncryptionService.DecryptBlock(array, field.encryptionOps, field.salt);
|
|
||||||
ins.Add(Instruction.CreateLdcI4(field.encryptionOps));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldc_I4, field.salt));
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Call, importer.DecryptBlock));
|
|
||||||
|
|
||||||
}
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ret));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetFieldsRVA()
|
|
||||||
{
|
|
||||||
foreach (var field in _rvaFields)
|
|
||||||
{
|
|
||||||
Assert.IsTrue(field.bytes.Count <= field.size);
|
|
||||||
if (field.bytes.Count < field.size)
|
|
||||||
{
|
|
||||||
field.FillPaddingToEnd();
|
|
||||||
}
|
|
||||||
byte[] data = field.bytes.ToArray();
|
|
||||||
_encryptionScope.encryptor.EncryptBlock(data, field.encryptionOps, field.salt);
|
|
||||||
field.holderDataField.InitialValue = data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("can't call Done twice");
|
|
||||||
}
|
|
||||||
_done = true;
|
|
||||||
SetFieldsRVA();
|
|
||||||
CreateCCtorOfRvaTypeDef();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class RvaDataAllocator
|
|
||||||
{
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
|
|
||||||
public RvaDataAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModuleRvaDataAllocator GetModuleRvaDataAllocator(ModuleDef mod)
|
|
||||||
{
|
|
||||||
return _moduleEntityManager.GetEntity<ModuleRvaDataAllocator>(mod, () => new ModuleRvaDataAllocator(_encryptionScopeProvider, _moduleEntityManager));
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, int value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, long value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, float value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, double value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, string value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RvaData Allocate(ModuleDef mod, byte[] value)
|
|
||||||
{
|
|
||||||
return GetModuleRvaDataAllocator(mod).Allocate(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
foreach (var allocator in _moduleEntityManager.GetEntities<ModuleRvaDataAllocator>())
|
|
||||||
{
|
|
||||||
allocator.Done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: c00ca514f46605645bf40b0135e7e504
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: a513a192808ba5f47b1ef8a3ecf02533
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,295 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.Remoting.Messaging;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.Emit
|
|
||||||
{
|
|
||||||
public class BasicBlock
|
|
||||||
{
|
|
||||||
public readonly List<Instruction> instructions = new List<Instruction>();
|
|
||||||
|
|
||||||
public readonly List<BasicBlock> inBlocks = new List<BasicBlock>();
|
|
||||||
|
|
||||||
public readonly List<BasicBlock> outBlocks = new List<BasicBlock>();
|
|
||||||
|
|
||||||
public bool inLoop;
|
|
||||||
|
|
||||||
public void AddTargetBasicBlock(BasicBlock target)
|
|
||||||
{
|
|
||||||
if (!outBlocks.Contains(target))
|
|
||||||
{
|
|
||||||
outBlocks.Add(target);
|
|
||||||
}
|
|
||||||
if (!target.inBlocks.Contains(this))
|
|
||||||
{
|
|
||||||
target.inBlocks.Add(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class BasicBlockCollection
|
|
||||||
{
|
|
||||||
private readonly MethodDef _method;
|
|
||||||
|
|
||||||
private readonly List<BasicBlock> _blocks = new List<BasicBlock>();
|
|
||||||
private readonly Dictionary<Instruction, BasicBlock> _inst2BlockMap = new Dictionary<Instruction, BasicBlock>();
|
|
||||||
|
|
||||||
public IList<BasicBlock> Blocks => _blocks;
|
|
||||||
|
|
||||||
public BasicBlockCollection(MethodDef method)
|
|
||||||
{
|
|
||||||
_method = method;
|
|
||||||
HashSet<Instruction> splitPoints = BuildSplitPoint(method);
|
|
||||||
BuildBasicBlocks(method, splitPoints);
|
|
||||||
BuildInOutGraph(method);
|
|
||||||
|
|
||||||
var loopBlocks = FindLoopBlocks(_blocks);
|
|
||||||
foreach (var block in loopBlocks)
|
|
||||||
{
|
|
||||||
block.inLoop = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BasicBlock GetBasicBlockByInstruction(Instruction inst)
|
|
||||||
{
|
|
||||||
return _inst2BlockMap[inst];
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashSet<Instruction> BuildSplitPoint(MethodDef method)
|
|
||||||
{
|
|
||||||
var insts = method.Body.Instructions;
|
|
||||||
var splitPoints = new HashSet<Instruction>();
|
|
||||||
foreach (ExceptionHandler eh in method.Body.ExceptionHandlers)
|
|
||||||
{
|
|
||||||
if (eh.TryStart != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(eh.TryStart);
|
|
||||||
}
|
|
||||||
if (eh.TryEnd != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(eh.TryEnd);
|
|
||||||
}
|
|
||||||
if (eh.HandlerStart != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(eh.HandlerStart);
|
|
||||||
}
|
|
||||||
if (eh.HandlerEnd != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(eh.HandlerEnd);
|
|
||||||
}
|
|
||||||
if (eh.FilterStart != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(eh.FilterStart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0, n = insts.Count; i < n; i++)
|
|
||||||
{
|
|
||||||
Instruction curInst = insts[i];
|
|
||||||
Instruction nextInst = i + 1 < n ? insts[i + 1] : null;
|
|
||||||
switch (curInst.OpCode.FlowControl)
|
|
||||||
{
|
|
||||||
case FlowControl.Branch:
|
|
||||||
{
|
|
||||||
if (nextInst != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(nextInst);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FlowControl.Cond_Branch:
|
|
||||||
{
|
|
||||||
if (nextInst != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(nextInst);
|
|
||||||
}
|
|
||||||
if (curInst.Operand is Instruction targetInst)
|
|
||||||
{
|
|
||||||
splitPoints.Add(targetInst);
|
|
||||||
}
|
|
||||||
else if (curInst.Operand is Instruction[] targetInsts)
|
|
||||||
{
|
|
||||||
foreach (var target in targetInsts)
|
|
||||||
{
|
|
||||||
splitPoints.Add(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FlowControl.Return:
|
|
||||||
{
|
|
||||||
if (nextInst != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(nextInst);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FlowControl.Throw:
|
|
||||||
{
|
|
||||||
if (nextInst != null)
|
|
||||||
{
|
|
||||||
splitPoints.Add(nextInst);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return splitPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void BuildBasicBlocks(MethodDef method, HashSet<Instruction> splitPoints)
|
|
||||||
{
|
|
||||||
var insts = method.Body.Instructions;
|
|
||||||
|
|
||||||
|
|
||||||
BasicBlock curBlock = new BasicBlock();
|
|
||||||
foreach (Instruction inst in insts)
|
|
||||||
{
|
|
||||||
if (splitPoints.Contains(inst) && curBlock.instructions.Count > 0)
|
|
||||||
{
|
|
||||||
_blocks.Add(curBlock);
|
|
||||||
curBlock = new BasicBlock();
|
|
||||||
}
|
|
||||||
curBlock.instructions.Add(inst);
|
|
||||||
_inst2BlockMap.Add(inst, curBlock);
|
|
||||||
}
|
|
||||||
if (curBlock.instructions.Count > 0)
|
|
||||||
{
|
|
||||||
_blocks.Add(curBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void BuildInOutGraph(MethodDef method)
|
|
||||||
{
|
|
||||||
var insts = method.Body.Instructions;
|
|
||||||
for (int i = 0, n = _blocks.Count; i < n; i++)
|
|
||||||
{
|
|
||||||
BasicBlock curBlock = _blocks[i];
|
|
||||||
BasicBlock nextBlock = i + 1 < n ? _blocks[i + 1] : null;
|
|
||||||
Instruction lastInst = curBlock.instructions.Last();
|
|
||||||
switch (lastInst.OpCode.FlowControl)
|
|
||||||
{
|
|
||||||
case FlowControl.Branch:
|
|
||||||
{
|
|
||||||
Instruction targetInst = (Instruction)lastInst.Operand;
|
|
||||||
BasicBlock targetBlock = GetBasicBlockByInstruction(targetInst);
|
|
||||||
curBlock.AddTargetBasicBlock(targetBlock);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FlowControl.Cond_Branch:
|
|
||||||
{
|
|
||||||
if (lastInst.Operand is Instruction targetInst)
|
|
||||||
{
|
|
||||||
BasicBlock targetBlock = GetBasicBlockByInstruction(targetInst);
|
|
||||||
curBlock.AddTargetBasicBlock(targetBlock);
|
|
||||||
}
|
|
||||||
else if (lastInst.Operand is Instruction[] targetInsts)
|
|
||||||
{
|
|
||||||
foreach (var target in targetInsts)
|
|
||||||
{
|
|
||||||
BasicBlock targetBlock = GetBasicBlockByInstruction(target);
|
|
||||||
curBlock.AddTargetBasicBlock(targetBlock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Invalid operand type for conditional branch");
|
|
||||||
}
|
|
||||||
if (nextBlock != null)
|
|
||||||
{
|
|
||||||
curBlock.AddTargetBasicBlock(nextBlock);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case FlowControl.Return:
|
|
||||||
case FlowControl.Throw:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static HashSet<BasicBlock> FindLoopBlocks(List<BasicBlock> allBlocks)
|
|
||||||
{
|
|
||||||
// Tarjan算法找强连通分量
|
|
||||||
var sccList = FindStronglyConnectedComponents(allBlocks);
|
|
||||||
|
|
||||||
// 筛选有效循环
|
|
||||||
var loopBlocks = new HashSet<BasicBlock>();
|
|
||||||
foreach (var scc in sccList)
|
|
||||||
{
|
|
||||||
// 有效循环需满足以下条件之一:
|
|
||||||
// 1. 分量包含多个块
|
|
||||||
// 2. 单个块有自环(跳转自己)
|
|
||||||
if (scc.Count > 1 ||
|
|
||||||
(scc.Count == 1 && scc[0].outBlocks.Contains(scc[0])))
|
|
||||||
{
|
|
||||||
foreach (var block in scc)
|
|
||||||
{
|
|
||||||
loopBlocks.Add(block);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return loopBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<List<BasicBlock>> FindStronglyConnectedComponents(List<BasicBlock> allBlocks)
|
|
||||||
{
|
|
||||||
int index = 0;
|
|
||||||
var stack = new Stack<BasicBlock>();
|
|
||||||
var indexes = new Dictionary<BasicBlock, int>();
|
|
||||||
var lowLinks = new Dictionary<BasicBlock, int>();
|
|
||||||
var onStack = new HashSet<BasicBlock>();
|
|
||||||
var sccList = new List<List<BasicBlock>>();
|
|
||||||
|
|
||||||
foreach (var block in allBlocks.Where(b => !indexes.ContainsKey(b)))
|
|
||||||
{
|
|
||||||
StrongConnect(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sccList;
|
|
||||||
|
|
||||||
void StrongConnect(BasicBlock v)
|
|
||||||
{
|
|
||||||
indexes[v] = index;
|
|
||||||
lowLinks[v] = index;
|
|
||||||
index++;
|
|
||||||
stack.Push(v);
|
|
||||||
onStack.Add(v);
|
|
||||||
|
|
||||||
foreach (var w in v.outBlocks)
|
|
||||||
{
|
|
||||||
if (!indexes.ContainsKey(w))
|
|
||||||
{
|
|
||||||
StrongConnect(w);
|
|
||||||
lowLinks[v] = System.Math.Min(lowLinks[v], lowLinks[w]);
|
|
||||||
}
|
|
||||||
else if (onStack.Contains(w))
|
|
||||||
{
|
|
||||||
lowLinks[v] = System.Math.Min(lowLinks[v], indexes[w]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lowLinks[v] == indexes[v])
|
|
||||||
{
|
|
||||||
var scc = new List<BasicBlock>();
|
|
||||||
BasicBlock w;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
w = stack.Pop();
|
|
||||||
onStack.Remove(w);
|
|
||||||
scc.Add(w);
|
|
||||||
} while (!w.Equals(v));
|
|
||||||
sccList.Add(scc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 77c19c023bb7f77489998d994a3be1bd
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,193 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using System;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
|
|
||||||
namespace Obfuz.Emit
|
|
||||||
{
|
|
||||||
public class EncryptionServiceMetadataImporter
|
|
||||||
{
|
|
||||||
private readonly ModuleDef _module;
|
|
||||||
private readonly Type _encryptionServiceType;
|
|
||||||
|
|
||||||
private IMethod _encryptBlock;
|
|
||||||
private IMethod _decryptBlock;
|
|
||||||
private IMethod _encryptInt;
|
|
||||||
private IMethod _decryptInt;
|
|
||||||
private IMethod _encryptLong;
|
|
||||||
private IMethod _decryptLong;
|
|
||||||
private IMethod _encryptFloat;
|
|
||||||
private IMethod _decryptFloat;
|
|
||||||
private IMethod _encryptDouble;
|
|
||||||
private IMethod _decryptDouble;
|
|
||||||
private IMethod _encryptString;
|
|
||||||
private IMethod _decryptString;
|
|
||||||
private IMethod _encryptBytes;
|
|
||||||
private IMethod _decryptBytes;
|
|
||||||
|
|
||||||
private IMethod _decryptFromRvaInt;
|
|
||||||
private IMethod _decryptFromRvaLong;
|
|
||||||
private IMethod _decryptFromRvaFloat;
|
|
||||||
private IMethod _decryptFromRvaDouble;
|
|
||||||
private IMethod _decryptFromRvaString;
|
|
||||||
private IMethod _decryptFromRvaBytes;
|
|
||||||
|
|
||||||
public IMethod EncryptBlock => _encryptBlock;
|
|
||||||
public IMethod DecryptBlock => _decryptBlock;
|
|
||||||
|
|
||||||
public IMethod EncryptInt => _encryptInt;
|
|
||||||
public IMethod DecryptInt => _decryptInt;
|
|
||||||
public IMethod EncryptLong => _encryptLong;
|
|
||||||
public IMethod DecryptLong => _decryptLong;
|
|
||||||
public IMethod EncryptFloat => _encryptFloat;
|
|
||||||
public IMethod DecryptFloat => _decryptFloat;
|
|
||||||
public IMethod EncryptDouble => _encryptDouble;
|
|
||||||
public IMethod DecryptDouble => _decryptDouble;
|
|
||||||
public IMethod EncryptString => _encryptString;
|
|
||||||
public IMethod DecryptString => _decryptString;
|
|
||||||
public IMethod EncryptBytes => _encryptBytes;
|
|
||||||
public IMethod DecryptBytes => _decryptBytes;
|
|
||||||
|
|
||||||
public IMethod DecryptFromRvaInt => _decryptFromRvaInt;
|
|
||||||
public IMethod DecryptFromRvaLong => _decryptFromRvaLong;
|
|
||||||
public IMethod DecryptFromRvaFloat => _decryptFromRvaFloat;
|
|
||||||
public IMethod DecryptFromRvaDouble => _decryptFromRvaDouble;
|
|
||||||
public IMethod DecryptFromRvaBytes => _decryptFromRvaBytes;
|
|
||||||
public IMethod DecryptFromRvaString => _decryptFromRvaString;
|
|
||||||
|
|
||||||
public EncryptionServiceMetadataImporter(ModuleDef mod, Type encryptionServiceType)
|
|
||||||
{
|
|
||||||
_module = mod;
|
|
||||||
_encryptionServiceType = encryptionServiceType;
|
|
||||||
_encryptBlock = mod.Import(encryptionServiceType.GetMethod("EncryptBlock", new[] { typeof(byte[]), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptBlock);
|
|
||||||
_decryptBlock = mod.Import(encryptionServiceType.GetMethod("DecryptBlock", new[] { typeof(byte[]), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptBlock);
|
|
||||||
_encryptInt = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptInt);
|
|
||||||
_decryptInt = mod.Import(encryptionServiceType.GetMethod("Decrypt", new[] { typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptInt);
|
|
||||||
_encryptLong = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(long), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptLong);
|
|
||||||
_decryptLong = mod.Import(encryptionServiceType.GetMethod("Decrypt", new[] { typeof(long), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptLong);
|
|
||||||
_encryptFloat = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(float), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptFloat);
|
|
||||||
_decryptFloat = mod.Import(encryptionServiceType.GetMethod("Decrypt", new[] { typeof(float), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFloat);
|
|
||||||
_encryptDouble = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(double), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptDouble);
|
|
||||||
_decryptDouble = mod.Import(encryptionServiceType.GetMethod("Decrypt", new[] { typeof(double), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptDouble);
|
|
||||||
_encryptString = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(string), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptString);
|
|
||||||
_decryptString = mod.Import(encryptionServiceType.GetMethod("DecryptString", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptString);
|
|
||||||
_encryptBytes = mod.Import(encryptionServiceType.GetMethod("Encrypt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_encryptBytes);
|
|
||||||
_decryptBytes = mod.Import(encryptionServiceType.GetMethod("Decrypt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptBytes);
|
|
||||||
|
|
||||||
_decryptFromRvaInt = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaInt", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaInt);
|
|
||||||
_decryptFromRvaLong = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaLong", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaLong);
|
|
||||||
_decryptFromRvaFloat = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaFloat", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaFloat);
|
|
||||||
_decryptFromRvaDouble = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaDouble", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaDouble);
|
|
||||||
_decryptFromRvaBytes = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaBytes", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaBytes);
|
|
||||||
_decryptFromRvaString = mod.Import(encryptionServiceType.GetMethod("DecryptFromRvaString", new[] { typeof(byte[]), typeof(int), typeof(int), typeof(int), typeof(int) }));
|
|
||||||
Assert.IsNotNull(_decryptFromRvaString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DefaultMetadataImporter : GroupByModuleEntityBase
|
|
||||||
{
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private EncryptionScopeInfo _encryptionScope;
|
|
||||||
private EncryptionServiceMetadataImporter _defaultEncryptionServiceMetadataImporter;
|
|
||||||
|
|
||||||
|
|
||||||
private EncryptionServiceMetadataImporter _staticDefaultEncryptionServiceMetadataImporter;
|
|
||||||
private EncryptionServiceMetadataImporter _dynamicDefaultEncryptionServiceMetadataImporter;
|
|
||||||
|
|
||||||
public DefaultMetadataImporter(EncryptionScopeProvider encryptionScopeProvider)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init(ModuleDef mod)
|
|
||||||
{
|
|
||||||
_module = mod;
|
|
||||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
|
||||||
var constUtilityType = typeof(ConstUtility);
|
|
||||||
|
|
||||||
_castIntAsFloat = mod.Import(constUtilityType.GetMethod("CastIntAsFloat"));
|
|
||||||
Assert.IsNotNull(_castIntAsFloat, "CastIntAsFloat not found");
|
|
||||||
_castLongAsDouble = mod.Import(constUtilityType.GetMethod("CastLongAsDouble"));
|
|
||||||
Assert.IsNotNull(_castLongAsDouble, "CastLongAsDouble not found");
|
|
||||||
_castFloatAsInt = mod.Import(constUtilityType.GetMethod("CastFloatAsInt"));
|
|
||||||
Assert.IsNotNull(_castFloatAsInt, "CastFloatAsInt not found");
|
|
||||||
_castDoubleAsLong = mod.Import(constUtilityType.GetMethod("CastDoubleAsLong"));
|
|
||||||
Assert.IsNotNull(_castDoubleAsLong, "CastDoubleAsLong not found");
|
|
||||||
|
|
||||||
_initializeArray = mod.Import(typeof(System.Runtime.CompilerServices.RuntimeHelpers).GetMethod("InitializeArray", new[] { typeof(Array), typeof(RuntimeFieldHandle) }));
|
|
||||||
Assert.IsNotNull(_initializeArray);
|
|
||||||
|
|
||||||
_staticDefaultEncryptionServiceMetadataImporter = new EncryptionServiceMetadataImporter(mod, typeof(EncryptionService<DefaultStaticEncryptionScope>));
|
|
||||||
_dynamicDefaultEncryptionServiceMetadataImporter = new EncryptionServiceMetadataImporter(mod, typeof(EncryptionService<DefaultDynamicEncryptionScope>));
|
|
||||||
if (_encryptionScopeProvider.IsDynamicSecretAssembly(mod))
|
|
||||||
{
|
|
||||||
_defaultEncryptionServiceMetadataImporter = _dynamicDefaultEncryptionServiceMetadataImporter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_defaultEncryptionServiceMetadataImporter = _staticDefaultEncryptionServiceMetadataImporter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public EncryptionServiceMetadataImporter GetEncryptionServiceMetadataImporterOfModule(ModuleDef mod)
|
|
||||||
{
|
|
||||||
return _encryptionScopeProvider.IsDynamicSecretAssembly(mod) ? _dynamicDefaultEncryptionServiceMetadataImporter : _staticDefaultEncryptionServiceMetadataImporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModuleDef _module;
|
|
||||||
private IMethod _castIntAsFloat;
|
|
||||||
private IMethod _castLongAsDouble;
|
|
||||||
private IMethod _castFloatAsInt;
|
|
||||||
private IMethod _castDoubleAsLong;
|
|
||||||
private IMethod _initializeArray;
|
|
||||||
|
|
||||||
public IMethod CastIntAsFloat => _castIntAsFloat;
|
|
||||||
public IMethod CastLongAsDouble => _castLongAsDouble;
|
|
||||||
public IMethod CastFloatAsInt => _castFloatAsInt;
|
|
||||||
public IMethod CastDoubleAsLong => _castDoubleAsLong;
|
|
||||||
|
|
||||||
public IMethod InitializedArrayMethod => _initializeArray;
|
|
||||||
|
|
||||||
public IMethod EncryptBlock => _defaultEncryptionServiceMetadataImporter.EncryptBlock;
|
|
||||||
public IMethod DecryptBlock => _defaultEncryptionServiceMetadataImporter.DecryptBlock;
|
|
||||||
|
|
||||||
public IMethod EncryptInt => _defaultEncryptionServiceMetadataImporter.EncryptInt;
|
|
||||||
public IMethod DecryptInt => _defaultEncryptionServiceMetadataImporter.DecryptInt;
|
|
||||||
public IMethod EncryptLong => _defaultEncryptionServiceMetadataImporter.EncryptLong;
|
|
||||||
public IMethod DecryptLong => _defaultEncryptionServiceMetadataImporter.DecryptLong;
|
|
||||||
public IMethod EncryptFloat => _defaultEncryptionServiceMetadataImporter.EncryptFloat;
|
|
||||||
public IMethod DecryptFloat => _defaultEncryptionServiceMetadataImporter.DecryptFloat;
|
|
||||||
public IMethod EncryptDouble => _defaultEncryptionServiceMetadataImporter.EncryptDouble;
|
|
||||||
public IMethod DecryptDouble => _defaultEncryptionServiceMetadataImporter.DecryptDouble;
|
|
||||||
public IMethod EncryptString => _defaultEncryptionServiceMetadataImporter.EncryptString;
|
|
||||||
public IMethod DecryptString => _defaultEncryptionServiceMetadataImporter.DecryptString;
|
|
||||||
public IMethod EncryptBytes => _defaultEncryptionServiceMetadataImporter.EncryptBytes;
|
|
||||||
public IMethod DecryptBytes => _defaultEncryptionServiceMetadataImporter.DecryptBytes;
|
|
||||||
|
|
||||||
public IMethod DecryptFromRvaInt => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaInt;
|
|
||||||
public IMethod DecryptFromRvaLong => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaLong;
|
|
||||||
public IMethod DecryptFromRvaFloat => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaFloat;
|
|
||||||
public IMethod DecryptFromRvaDouble => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaDouble;
|
|
||||||
public IMethod DecryptFromRvaBytes => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaBytes;
|
|
||||||
public IMethod DecryptFromRvaString => _defaultEncryptionServiceMetadataImporter.DecryptFromRvaString;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 76438ce96146edd469872feada7857ba
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,66 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.Emit
|
|
||||||
{
|
|
||||||
public interface IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
void Init(ModuleDef mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class GroupByModuleEntityBase : IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
public abstract void Init(ModuleDef mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GroupByModuleEntityManager
|
|
||||||
{
|
|
||||||
private readonly Dictionary<(ModuleDef, Type), IGroupByModuleEntity> _moduleEntityManagers = new Dictionary<(ModuleDef, Type), IGroupByModuleEntity>();
|
|
||||||
|
|
||||||
public T GetEntity<T>(ModuleDef mod, Func<T> creator = null) where T : IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
var key = (mod, typeof(T));
|
|
||||||
if (_moduleEntityManagers.TryGetValue(key, out var emitManager))
|
|
||||||
{
|
|
||||||
return (T)emitManager;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
T newEmitManager;
|
|
||||||
if (creator != null)
|
|
||||||
{
|
|
||||||
newEmitManager = creator();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newEmitManager = (T)Activator.CreateInstance(typeof(T));
|
|
||||||
}
|
|
||||||
newEmitManager.Init(mod);
|
|
||||||
_moduleEntityManagers[key] = newEmitManager;
|
|
||||||
return newEmitManager;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<T> GetEntities<T>() where T: IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
var managers = new List<T>();
|
|
||||||
foreach (var kv in _moduleEntityManagers)
|
|
||||||
{
|
|
||||||
if (kv.Key.Item2 == typeof(T))
|
|
||||||
{
|
|
||||||
managers.Add((T)kv.Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return managers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DefaultMetadataImporter GetDefaultModuleMetadataImporter(ModuleDef module, EncryptionScopeProvider encryptionScopeProvider)
|
|
||||||
{
|
|
||||||
return GetEntity<DefaultMetadataImporter>(module, () => new DefaultMetadataImporter(encryptionScopeProvider));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 0bfcb2b5a87851f469d201fc8978c109
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: fec4187cc1b96d5439ff908bcecd988f
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,25 +0,0 @@
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public class EncryptionInstructionWithOpCode
|
|
||||||
{
|
|
||||||
public readonly ushort code;
|
|
||||||
|
|
||||||
public readonly IEncryptionInstruction function;
|
|
||||||
|
|
||||||
public EncryptionInstructionWithOpCode(ushort code, IEncryptionInstruction function)
|
|
||||||
{
|
|
||||||
this.code = code;
|
|
||||||
this.function = function;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return function.Encrypt(value, secretKey, salt);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return function.Decrypt(value, secretKey, salt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ca9bd232ed2583f4bb5f330886a329e6
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,24 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public interface IEncryptionInstruction
|
|
||||||
{
|
|
||||||
int Encrypt(int value, int[] secretKey, int salt);
|
|
||||||
|
|
||||||
int Decrypt(int value, int[] secretKey, int salt);
|
|
||||||
|
|
||||||
void GenerateEncryptCode(List<string> lines, string indent);
|
|
||||||
|
|
||||||
void GenerateDecryptCode(List<string> lines, string indent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class EncryptionInstructionBase : IEncryptionInstruction
|
|
||||||
{
|
|
||||||
public abstract int Encrypt(int value, int[] secretKey, int salt);
|
|
||||||
public abstract int Decrypt(int value, int[] secretKey, int salt);
|
|
||||||
|
|
||||||
public abstract void GenerateEncryptCode(List<string> lines, string indent);
|
|
||||||
public abstract void GenerateDecryptCode(List<string> lines, string indent);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: f7b9d087de770a5488a9069ddf697c2f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 981355cf75a9d234883b2a15c446f478
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,35 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class AddInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
private readonly int _addValue;
|
|
||||||
private readonly int _opKeyIndex;
|
|
||||||
|
|
||||||
public AddInstruction(int addValue, int opKeyIndex)
|
|
||||||
{
|
|
||||||
_addValue = addValue;
|
|
||||||
_opKeyIndex = opKeyIndex;
|
|
||||||
}
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return ((value + secretKey[_opKeyIndex]) ^ salt) + _addValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return ((value - _addValue) ^ salt) - secretKey[_opKeyIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = ((value + _secretKey[{_opKeyIndex}]) ^ salt) + {_addValue};");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = ((value - {_addValue}) ^ salt) - _secretKey[{_opKeyIndex}];");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 6bdbdc5fd983f044a87e7b8ab8647aeb
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,66 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class AddRotateXorInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x + p1 + secretKey[index1];
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
|
|
||||||
private readonly int _addValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public AddRotateXorInstruction(int addValue, int index1, int rotateBitNum, int xorValue)
|
|
||||||
{
|
|
||||||
_addValue = addValue;
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value += _addValue + secretKey[_index1];
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value -= _addValue + secretKey[_index1];
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value += {_addValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(value2 | part1);");
|
|
||||||
lines.Add(indent + $"value -= {_addValue} + _secretKey[{_index1}];");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: cda67c0dd0cadd24ea02c2988e34281a
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,66 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class AddXorRotateInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x + p1 + secretKey[index1];
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
|
|
||||||
private readonly int _addValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public AddXorRotateInstruction(int addValue, int index1, int xorValue, int rotateBitNum)
|
|
||||||
{
|
|
||||||
_addValue = addValue;
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value += _addValue + secretKey[_index1];
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
value -= _addValue + secretKey[_index1];
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value += {_addValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"value -= {_addValue} + _secretKey[{_index1}];");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: d806305e627be06469fb2d2c2cf98816
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,46 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class BitRotateInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _opKeyIndex;
|
|
||||||
|
|
||||||
public BitRotateInstruction(int rotateBitNum, int opKeyIndex)
|
|
||||||
{
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_opKeyIndex = opKeyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
return ((int)(part1 | part2) ^ secretKey[_opKeyIndex]) + salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint value2 = (uint)((value - salt) ^ secretKey[_opKeyIndex]);
|
|
||||||
uint part1 = value2 >> _rotateBitNum;
|
|
||||||
uint part2 = value2 << (32 - _rotateBitNum);
|
|
||||||
return (int)(part1 | part2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = ((int)(part1 | part2) ^ _secretKey[{_opKeyIndex}]) + salt;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)((value - salt) ^ _secretKey[{_opKeyIndex}]);");
|
|
||||||
lines.Add(indent + $"uint part1 = value2 >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = value2 << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: bccff31b9f07fcf4f821cee671f82caf
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,47 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
|
|
||||||
public class EncryptFunction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
private readonly IEncryptionInstruction[] _instructions;
|
|
||||||
|
|
||||||
public EncryptFunction(IEncryptionInstruction[] instructions)
|
|
||||||
{
|
|
||||||
_instructions = instructions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
foreach (var instruction in _instructions)
|
|
||||||
{
|
|
||||||
value = instruction.Encrypt(value, secretKey, salt);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
for (int i = _instructions.Length - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
value = _instructions[i].Decrypt(value, secretKey, salt);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: feafdb30f7b6d5143a89c7659bc16171
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,64 +0,0 @@
|
||||||
using NUnit.Framework;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class MultipleInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
private readonly int _multiValue;
|
|
||||||
private readonly int _revertMultiValue;
|
|
||||||
private readonly int _opKeyIndex;
|
|
||||||
|
|
||||||
public MultipleInstruction(int addValue, int opKeyIndex)
|
|
||||||
{
|
|
||||||
_multiValue = addValue;
|
|
||||||
_opKeyIndex = opKeyIndex;
|
|
||||||
_revertMultiValue = (int)ModInverseOdd((uint)addValue);
|
|
||||||
Verify();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Verify()
|
|
||||||
{
|
|
||||||
int a = 1122334;
|
|
||||||
Assert.AreEqual(a, a * _multiValue * _revertMultiValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static uint ModInverseOdd(uint a)
|
|
||||||
{
|
|
||||||
if (a % 2 == 0)
|
|
||||||
throw new ArgumentException("Input must be an odd number.", nameof(a));
|
|
||||||
|
|
||||||
uint x = 1; // 初始解:x₀ = 1 (mod 2)
|
|
||||||
for (int i = 0; i < 5; i++) // 迭代5次(2^1 → 2^32)
|
|
||||||
{
|
|
||||||
int shift = 2 << i; // 当前模数为 2^(2^(i+1))
|
|
||||||
ulong mod = 1UL << shift; // 使用 ulong 避免溢出
|
|
||||||
ulong ax = (ulong)a * x; // 计算 a*x(64位避免截断)
|
|
||||||
ulong term = (2 - ax) % mod;
|
|
||||||
x = (uint)((x * term) % mod); // 更新 x,结果截断为 uint
|
|
||||||
}
|
|
||||||
return x; // 最终解为 x₅ mod 2^32
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return value * _multiValue + secretKey[_opKeyIndex] + salt;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return (value - secretKey[_opKeyIndex] - salt) * _revertMultiValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = value * {_multiValue} + _secretKey[{_opKeyIndex}] + salt;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = (value - _secretKey[{_opKeyIndex}] - salt) * {_revertMultiValue};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: fd5fdfad694e0ae469bf6ca04c913220
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,68 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class MultipleRotateXorInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x * p1 + secretKey[index1];
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
|
|
||||||
private readonly int _multipleValue;
|
|
||||||
private readonly int _revertMultipleValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public MultipleRotateXorInstruction(int multipleValue, int index1, int rotateBitNum, int xorValue)
|
|
||||||
{
|
|
||||||
_multipleValue = multipleValue;
|
|
||||||
_revertMultipleValue = (int)MultipleInstruction.ModInverseOdd((uint)multipleValue);
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value = value * _multipleValue + secretKey[_index1];
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value = (value - secretKey[_index1]) * _revertMultipleValue;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = value * {_multipleValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(value2 | part1);");
|
|
||||||
lines.Add(indent + $"value = (value - _secretKey[{_index1}]) * {_revertMultipleValue};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e3c8b55b35ff1554489fa657a714f485
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,68 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class MultipleXorRotateInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x * p1 + secretKey[index1];
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
|
|
||||||
private readonly int _multipleValue;
|
|
||||||
private readonly int _revertMultipleValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public MultipleXorRotateInstruction(int multipleValue, int index1, int xorValue, int rotateBitNum)
|
|
||||||
{
|
|
||||||
_multipleValue = multipleValue;
|
|
||||||
_revertMultipleValue = (int)MultipleInstruction.ModInverseOdd((uint)multipleValue);
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value = value * _multipleValue + secretKey[_index1];
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
value = (value - secretKey[_index1]) * _revertMultipleValue;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = value * {_multipleValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(value2 | part1);");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"value = (value - _secretKey[{_index1}]) * {_revertMultipleValue};");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: adc3dcde66795744fa4bdc753a2c599f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,66 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class XorAddRotateInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
// x = x + p1 + secretKey[index1];
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
|
|
||||||
private readonly int _addValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public XorAddRotateInstruction(int xorValue, int addValue, int index1, int rotateBitNum)
|
|
||||||
{
|
|
||||||
_addValue = addValue;
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
value += _addValue + secretKey[_index1];
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value -= _addValue + secretKey[_index1];
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"value += {_addValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(value2 | part1);");
|
|
||||||
lines.Add(indent + $"value -= {_addValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ad8f4dd724d7ff845b0dd65861054d37
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,36 +0,0 @@
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class XorInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
private readonly int _xorValue;
|
|
||||||
private readonly int _opKeyIndex;
|
|
||||||
|
|
||||||
public XorInstruction(int xorValue, int opKeyIndex)
|
|
||||||
{
|
|
||||||
_xorValue = xorValue;
|
|
||||||
_opKeyIndex = opKeyIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return ((value ^ secretKey[_opKeyIndex]) + salt) ^ _xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
return ((value ^ _xorValue) - salt) ^ secretKey[_opKeyIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = ((value ^ _secretKey[{_opKeyIndex}]) + salt) ^ {_xorValue};");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value = ((value ^ {_xorValue}) - salt) ^ _secretKey[{_opKeyIndex}];");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2f16dd868e4473b45bfa9daaf7fabaf8
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,68 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM.Instructions
|
|
||||||
{
|
|
||||||
public class XorMultipleRotateInstruction : EncryptionInstructionBase
|
|
||||||
{
|
|
||||||
// x = x ^ p3 ^ salt;
|
|
||||||
// x = x * p1 + secretKey[index1];
|
|
||||||
// x = Rotate(x, p2)
|
|
||||||
|
|
||||||
private readonly int _multipleValue;
|
|
||||||
private readonly int _revertMultipleValue;
|
|
||||||
private readonly int _index1;
|
|
||||||
private readonly int _rotateBitNum;
|
|
||||||
private readonly int _xorValue;
|
|
||||||
|
|
||||||
public XorMultipleRotateInstruction(int xorValue, int multipleValue, int index1, int rotateBitNum)
|
|
||||||
{
|
|
||||||
_multipleValue = multipleValue;
|
|
||||||
_revertMultipleValue = (int)MultipleInstruction.ModInverseOdd((uint)multipleValue);
|
|
||||||
_index1 = index1;
|
|
||||||
_rotateBitNum = rotateBitNum;
|
|
||||||
_xorValue = xorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
value = value * _multipleValue + secretKey[_index1];
|
|
||||||
uint part1 = (uint)value << _rotateBitNum;
|
|
||||||
uint part2 = (uint)value >> (32 - _rotateBitNum);
|
|
||||||
value = (int)(part1 | part2);
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int[] secretKey, int salt)
|
|
||||||
{
|
|
||||||
uint value2 = (uint)value >> _rotateBitNum;
|
|
||||||
uint part1 = (uint)value << (32 - _rotateBitNum);
|
|
||||||
value = (int)(value2 | part1);
|
|
||||||
value = (value - secretKey[_index1]) * _revertMultipleValue;
|
|
||||||
value ^= _xorValue ^ salt;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateEncryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
lines.Add(indent + $"value = value * {_multipleValue} + _secretKey[{_index1}];");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part2 = (uint)value >> (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(part1 | part2);");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void GenerateDecryptCode(List<string> lines, string indent)
|
|
||||||
{
|
|
||||||
lines.Add(indent + $"uint value2 = (uint)value >> {_rotateBitNum};");
|
|
||||||
lines.Add(indent + $"uint part1 = (uint)value << (32 - {_rotateBitNum});");
|
|
||||||
lines.Add(indent + $"value = (int)(value2 | part1);");
|
|
||||||
lines.Add(indent + $"value = (value - _secretKey[{_index1}]) * {_revertMultipleValue};");
|
|
||||||
lines.Add(indent + $"value ^= {_xorValue} ^ salt;");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 3eb7e6d475cfc14459d3850c5964ba52
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,17 +0,0 @@
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public class VirtualMachine
|
|
||||||
{
|
|
||||||
public const int SecretKeyLength = 1024;
|
|
||||||
|
|
||||||
public readonly int version;
|
|
||||||
public readonly string codeGenerationSecretKey;
|
|
||||||
public readonly EncryptionInstructionWithOpCode[] opCodes;
|
|
||||||
|
|
||||||
public VirtualMachine(int version, string codeGenerationSecretKey, EncryptionInstructionWithOpCode[] opCodes)
|
|
||||||
{
|
|
||||||
this.codeGenerationSecretKey = codeGenerationSecretKey;
|
|
||||||
this.opCodes = opCodes;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: c6970e037654dcb49912783a40f3e1ba
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,207 +0,0 @@
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public class VirtualMachineCodeGenerator
|
|
||||||
{
|
|
||||||
private readonly int _opCodeCount;
|
|
||||||
private readonly int _opCodeBits;
|
|
||||||
private readonly VirtualMachine _vm;
|
|
||||||
|
|
||||||
public VirtualMachineCodeGenerator(string vmCodeGenerateSecretKey, int opCodeCount)
|
|
||||||
{
|
|
||||||
_opCodeCount = opCodeCount;
|
|
||||||
_opCodeBits = EncryptionUtil.GetBitCount(opCodeCount - 1);
|
|
||||||
_vm = new VirtualMachineCreator(vmCodeGenerateSecretKey).CreateVirtualMachine(opCodeCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualMachineCodeGenerator(VirtualMachine vm)
|
|
||||||
{
|
|
||||||
_opCodeCount = vm.opCodes.Length;
|
|
||||||
_opCodeBits = EncryptionUtil.GetBitCount(_opCodeCount - 1);
|
|
||||||
_vm = vm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public bool ValidateMatch(string outputFile)
|
|
||||||
{
|
|
||||||
if (!File.Exists(outputFile))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
string oldCode = NormalizeText(File.ReadAllText(outputFile, Encoding.UTF8));
|
|
||||||
string newCode = NormalizeText(GenerateCode());
|
|
||||||
return oldCode == newCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string NormalizeText(string input)
|
|
||||||
{
|
|
||||||
return Regex.Replace(input, @"\s+", string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Generate(string outputFile)
|
|
||||||
{
|
|
||||||
FileUtil.CreateParentDir(outputFile);
|
|
||||||
|
|
||||||
string code = GenerateCode();
|
|
||||||
|
|
||||||
File.WriteAllText(outputFile, code, Encoding.UTF8);
|
|
||||||
Debug.Log($"Generate EncryptionVM code to {outputFile}");
|
|
||||||
UnityEditor.AssetDatabase.Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GenerateCode()
|
|
||||||
{
|
|
||||||
var lines = new List<string>();
|
|
||||||
AppendHeader(lines);
|
|
||||||
AppendEncryptCodes(lines);
|
|
||||||
AppendDecryptCodes(lines);
|
|
||||||
AppendTailer(lines);
|
|
||||||
return string.Join("\n", lines);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendEncryptCodes(List<string> lines)
|
|
||||||
{
|
|
||||||
lines.Add(@"
|
|
||||||
private int ExecuteEncrypt(int value, int opCode, int salt)
|
|
||||||
{
|
|
||||||
switch (opCode)
|
|
||||||
{");
|
|
||||||
foreach (var opCode in _vm.opCodes)
|
|
||||||
{
|
|
||||||
lines.Add($@" case {opCode.code}:
|
|
||||||
{{
|
|
||||||
// {opCode.function.GetType().Name}");
|
|
||||||
AppendEncryptCode(lines, opCode.function);
|
|
||||||
lines.Add(@" return value;
|
|
||||||
}");
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.Add(@"
|
|
||||||
default:
|
|
||||||
throw new System.Exception($""Invalid opCode:{opCode}"");
|
|
||||||
}
|
|
||||||
}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendDecryptCodes(List<string> lines)
|
|
||||||
{
|
|
||||||
lines.Add(@"
|
|
||||||
private int ExecuteDecrypt(int value, int opCode, int salt)
|
|
||||||
{
|
|
||||||
switch (opCode)
|
|
||||||
{");
|
|
||||||
foreach (var opCode in _vm.opCodes)
|
|
||||||
{
|
|
||||||
lines.Add($@" case {opCode.code}:
|
|
||||||
{{
|
|
||||||
// {opCode.function.GetType().Name}");
|
|
||||||
AppendDecryptCode(lines, opCode.function);
|
|
||||||
lines.Add(@" return value;
|
|
||||||
}");
|
|
||||||
}
|
|
||||||
|
|
||||||
lines.Add(@"
|
|
||||||
default:
|
|
||||||
throw new System.Exception($""Invalid opCode:{opCode}"");
|
|
||||||
}
|
|
||||||
}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendHeader(List<string> lines)
|
|
||||||
{
|
|
||||||
|
|
||||||
lines.Add($"/// This file is auto-generated by Obfuz. Do not modify it.");
|
|
||||||
lines.Add($"///");
|
|
||||||
//lines.Add($"/// Created Time: {DateTime.Now}");
|
|
||||||
|
|
||||||
lines.Add($"/// Version: {_vm.version}");
|
|
||||||
lines.Add($"/// SecretKey: {_vm.codeGenerationSecretKey}");
|
|
||||||
lines.Add($"/// OpCodeCount: {_vm.opCodes.Length}");
|
|
||||||
|
|
||||||
lines.Add(@"
|
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public class GeneratedEncryptionVirtualMachine : Obfuz.EncryptorBase
|
|
||||||
{");
|
|
||||||
lines.Add($@"
|
|
||||||
private const int kOpCodeBits = {_opCodeBits};
|
|
||||||
|
|
||||||
private const int kOpCodeCount = {_opCodeCount};
|
|
||||||
|
|
||||||
private const int kOpCodeMask = {_opCodeCount - 1};
|
|
||||||
");
|
|
||||||
lines.Add(@"
|
|
||||||
|
|
||||||
private readonly int[] _secretKey;
|
|
||||||
|
|
||||||
public GeneratedEncryptionVirtualMachine(byte[] secretKey)
|
|
||||||
{
|
|
||||||
this._secretKey = ConvertToIntKey(secretKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int OpCodeCount => kOpCodeCount;
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int opts, int salt)
|
|
||||||
{
|
|
||||||
uint uopts = (uint)opts;
|
|
||||||
uint revertOps = 0;
|
|
||||||
while (uopts != 0)
|
|
||||||
{
|
|
||||||
uint opCode = uopts & kOpCodeMask;
|
|
||||||
revertOps <<= kOpCodeBits;
|
|
||||||
revertOps |= opCode;
|
|
||||||
uopts >>= kOpCodeBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (revertOps != 0)
|
|
||||||
{
|
|
||||||
uint opCode = revertOps & kOpCodeMask;
|
|
||||||
value = ExecuteEncrypt(value, (int)opCode, salt);
|
|
||||||
revertOps >>= kOpCodeBits;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int opts, int salt)
|
|
||||||
{
|
|
||||||
uint uopts = (uint)opts;
|
|
||||||
while (uopts != 0)
|
|
||||||
{
|
|
||||||
uint opCode = uopts & kOpCodeMask;
|
|
||||||
value = ExecuteDecrypt(value, (int)opCode, salt);
|
|
||||||
uopts >>= kOpCodeBits;
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendTailer(List<string> lines)
|
|
||||||
{
|
|
||||||
lines.Add(@"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendEncryptCode(List<string> lines, IEncryptionInstruction instruction)
|
|
||||||
{
|
|
||||||
instruction.GenerateEncryptCode(lines, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendDecryptCode(List<string> lines, IEncryptionInstruction instruction)
|
|
||||||
{
|
|
||||||
instruction.GenerateDecryptCode(lines, " ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2246e9d3369eb3c45bc19ae0748d76ba
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,71 +0,0 @@
|
||||||
using NUnit.Framework;
|
|
||||||
using Obfuz.EncryptionVM.Instructions;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
public class VirtualMachineCreator
|
|
||||||
{
|
|
||||||
private readonly string _vmGenerationSecretKey;
|
|
||||||
private readonly IRandom _random;
|
|
||||||
|
|
||||||
public const int CodeGenerationSecretKeyLength = 1024;
|
|
||||||
|
|
||||||
public const int VirtualMachineVersion = 1;
|
|
||||||
|
|
||||||
public VirtualMachineCreator(string vmGenerationSecretKey)
|
|
||||||
{
|
|
||||||
_vmGenerationSecretKey = vmGenerationSecretKey;
|
|
||||||
byte[] byteGenerationSecretKey = KeyGenerator.GenerateKey(vmGenerationSecretKey, CodeGenerationSecretKeyLength);
|
|
||||||
int[] intGenerationSecretKey = KeyGenerator.ConvertToIntKey(byteGenerationSecretKey);
|
|
||||||
_random = new RandomWithKey(intGenerationSecretKey, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly List<Func<IRandom, int, EncryptionInstructionBase>> _instructionCreators = new List<Func<IRandom, int, EncryptionInstructionBase>>
|
|
||||||
{
|
|
||||||
(r, len) => new AddInstruction(r.NextInt(), r.NextInt(len)),
|
|
||||||
(r, len) => new XorInstruction(r.NextInt(), r.NextInt(len)),
|
|
||||||
(r, len) => new BitRotateInstruction(r.NextInt(32), r.NextInt(len)),
|
|
||||||
(r, len) => new MultipleInstruction(r.NextInt() | 0x1, r.NextInt(len)),
|
|
||||||
(r, len) => new AddRotateXorInstruction(r.NextInt(), r.NextInt(len), r.NextInt(32), r.NextInt()),
|
|
||||||
(r, len) => new AddXorRotateInstruction(r.NextInt(), r.NextInt(len), r.NextInt(), r.NextInt(32)),
|
|
||||||
(r, len) => new XorAddRotateInstruction(r.NextInt(), r.NextInt(), r.NextInt(len), r.NextInt(32)),
|
|
||||||
(r, len) => new MultipleRotateXorInstruction(r.NextInt() | 0x1, r.NextInt(len), r.NextInt(32), r.NextInt()),
|
|
||||||
(r, len) => new MultipleXorRotateInstruction(r.NextInt() | 0x1, r.NextInt(len), r.NextInt(), r.NextInt(32)),
|
|
||||||
(r, len) => new XorMultipleRotateInstruction(r.NextInt(), r.NextInt() | 0x1, r.NextInt(len), r.NextInt(32)),
|
|
||||||
};
|
|
||||||
|
|
||||||
private IEncryptionInstruction CreateRandomInstruction(int intSecretKeyLength)
|
|
||||||
{
|
|
||||||
return _instructionCreators[_random.NextInt(_instructionCreators.Count)](_random, intSecretKeyLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
private EncryptionInstructionWithOpCode CreateEncryptOpCode(ushort code)
|
|
||||||
{
|
|
||||||
IEncryptionInstruction inst = CreateRandomInstruction(VirtualMachine.SecretKeyLength / sizeof(int));
|
|
||||||
return new EncryptionInstructionWithOpCode(code, inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualMachine CreateVirtualMachine(int opCodeCount)
|
|
||||||
{
|
|
||||||
if (opCodeCount < 64)
|
|
||||||
{
|
|
||||||
throw new System.Exception("OpCode count should be >= 64");
|
|
||||||
}
|
|
||||||
if ((opCodeCount & (opCodeCount - 1)) != 0)
|
|
||||||
{
|
|
||||||
throw new System.Exception("OpCode count should be power of 2");
|
|
||||||
}
|
|
||||||
var opCodes = new EncryptionInstructionWithOpCode[opCodeCount];
|
|
||||||
for (int i = 0; i < opCodes.Length; i++)
|
|
||||||
{
|
|
||||||
opCodes[i] = CreateEncryptOpCode((ushort)i);
|
|
||||||
}
|
|
||||||
return new VirtualMachine(VirtualMachineVersion, _vmGenerationSecretKey, opCodes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 77d95ff5cf0b3aa4e96a055e37c381ba
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,96 +0,0 @@
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq.Expressions;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
namespace Obfuz.EncryptionVM
|
|
||||||
{
|
|
||||||
|
|
||||||
public class VirtualMachineSimulator : EncryptorBase
|
|
||||||
{
|
|
||||||
private readonly EncryptionInstructionWithOpCode[] _opCodes;
|
|
||||||
private readonly int[] _secretKey;
|
|
||||||
|
|
||||||
public override int OpCodeCount => _opCodes.Length;
|
|
||||||
|
|
||||||
public VirtualMachineSimulator(VirtualMachine vm, byte[] byteSecretKey)
|
|
||||||
{
|
|
||||||
_opCodes = vm.opCodes;
|
|
||||||
_secretKey = KeyGenerator.ConvertToIntKey(byteSecretKey);
|
|
||||||
|
|
||||||
VerifyInstructions();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VerifyInstructions()
|
|
||||||
{
|
|
||||||
int value = 0x11223344;
|
|
||||||
for (int i = 0; i < _opCodes.Length; i++)
|
|
||||||
{
|
|
||||||
int encryptedValue = _opCodes[i].Encrypt(value, _secretKey, i);
|
|
||||||
int decryptedValue = _opCodes[i].Decrypt(encryptedValue, _secretKey, i);
|
|
||||||
//Debug.Log($"instruction type:{_opCodes[i].function.GetType()}");
|
|
||||||
Assert.AreEqual(value, decryptedValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ops = 11223344;
|
|
||||||
int salt = 789;
|
|
||||||
Assert.AreEqual(1, Decrypt(Encrypt(1, ops, salt), ops, salt));
|
|
||||||
Assert.AreEqual(1L, Decrypt(Encrypt(1L, ops, salt), ops, salt));
|
|
||||||
Assert.AreEqual(1.0f, Decrypt(Encrypt(1.0f, ops, salt), ops, salt));
|
|
||||||
Assert.AreEqual(1.0, Decrypt(Encrypt(1.0, ops, salt), ops, salt));
|
|
||||||
|
|
||||||
byte[] strBytes = Encrypt("abcdef", ops, salt);
|
|
||||||
Assert.AreEqual("abcdef", DecryptString(strBytes, 0, strBytes.Length, ops, salt));
|
|
||||||
var arr = new byte[100];
|
|
||||||
for (int i = 0; i < arr.Length ; i++)
|
|
||||||
{
|
|
||||||
arr[i] = (byte)i;
|
|
||||||
}
|
|
||||||
EncryptBlock(arr, ops, salt);
|
|
||||||
DecryptBlock(arr, ops, salt);
|
|
||||||
for (int i = 0; i < arr.Length; i++)
|
|
||||||
{
|
|
||||||
Assert.AreEqual(i, arr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<uint> DecodeOps(uint ops)
|
|
||||||
{
|
|
||||||
var codes = new List<uint>();
|
|
||||||
while (ops != 0)
|
|
||||||
{
|
|
||||||
uint code = ops % (uint)_opCodes.Length;
|
|
||||||
codes.Add(code);
|
|
||||||
ops /= (uint)_opCodes.Length;
|
|
||||||
}
|
|
||||||
return codes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Encrypt(int value, int ops, int salt)
|
|
||||||
{
|
|
||||||
var codes = DecodeOps((uint)ops);
|
|
||||||
for (int i = codes.Count - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
var opCode = _opCodes[codes[i]];
|
|
||||||
value = opCode.Encrypt(value, _secretKey, salt);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Decrypt(int value, int ops, int salt)
|
|
||||||
{
|
|
||||||
var codes = DecodeOps((uint)ops);
|
|
||||||
foreach (var code in codes)
|
|
||||||
{
|
|
||||||
var opCode = _opCodes[code];
|
|
||||||
value = opCode.Decrypt(value, _secretKey, salt);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 4f86f4d6faf49764a915d5c675091375
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,20 +0,0 @@
|
||||||
using Obfuz.ObfusPasses;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz
|
|
||||||
{
|
|
||||||
public interface IObfuscationPass
|
|
||||||
{
|
|
||||||
ObfuscationPassType Type { get; }
|
|
||||||
|
|
||||||
void Start();
|
|
||||||
|
|
||||||
void Stop();
|
|
||||||
|
|
||||||
void Process();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: b7003f9503025794b8aa775d9ade335c
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 120b2dcffd582e84dbb92003240824d1
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,87 +0,0 @@
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using dnlib.DotNet;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses
|
|
||||||
{
|
|
||||||
public abstract class BasicBlockObfuscationPassBase : ObfuscationPassBase
|
|
||||||
{
|
|
||||||
protected abstract bool NeedObfuscateMethod(MethodDef method);
|
|
||||||
|
|
||||||
public override void Process()
|
|
||||||
{
|
|
||||||
var ctx = ObfuscationPassContext.Current;
|
|
||||||
ObfuscationMethodWhitelist whiteList = ctx.whiteList;
|
|
||||||
ConfigurablePassPolicy passPolicy = ctx.passPolicy;
|
|
||||||
foreach (ModuleDef mod in ctx.modulesToObfuscate)
|
|
||||||
{
|
|
||||||
if (whiteList.IsInWhiteList(mod) || !Support(passPolicy.GetAssemblyObfuscationPasses(mod)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// ToArray to avoid modify list exception
|
|
||||||
foreach (TypeDef type in mod.GetTypes().ToArray())
|
|
||||||
{
|
|
||||||
if (whiteList.IsInWhiteList(type) || !Support(passPolicy.GetTypeObfuscationPasses(type)))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// ToArray to avoid modify list exception
|
|
||||||
foreach (MethodDef method in type.Methods.ToArray())
|
|
||||||
{
|
|
||||||
if (!method.HasBody || ctx.whiteList.IsInWhiteList(method) || !Support(passPolicy.GetMethodObfuscationPasses(method)) || !NeedObfuscateMethod(method))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// TODO if isGeneratedBy Obfuscator, continue
|
|
||||||
ObfuscateData(method);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract bool TryObfuscateInstruction(MethodDef callingMethod, Instruction inst, BasicBlock block, int instructionIndex,
|
|
||||||
IList<Instruction> globalInstructions, List<Instruction> outputInstructions, List<Instruction> totalFinalInstructions);
|
|
||||||
|
|
||||||
private void ObfuscateData(MethodDef method)
|
|
||||||
{
|
|
||||||
BasicBlockCollection bbc = new BasicBlockCollection(method);
|
|
||||||
|
|
||||||
IList<Instruction> instructions = method.Body.Instructions;
|
|
||||||
|
|
||||||
var outputInstructions = new List<Instruction>();
|
|
||||||
var totalFinalInstructions = new List<Instruction>();
|
|
||||||
for (int i = 0; i < instructions.Count; i++)
|
|
||||||
{
|
|
||||||
Instruction inst = instructions[i];
|
|
||||||
BasicBlock block = bbc.GetBasicBlockByInstruction(inst);
|
|
||||||
outputInstructions.Clear();
|
|
||||||
if (TryObfuscateInstruction(method, inst, block, i, instructions, outputInstructions, totalFinalInstructions))
|
|
||||||
{
|
|
||||||
// current instruction may be the target of control flow instruction, so we can't remove it directly.
|
|
||||||
// we replace it with nop now, then remove it in CleanUpInstructionPass
|
|
||||||
inst.OpCode = outputInstructions[0].OpCode;
|
|
||||||
inst.Operand = outputInstructions[0].Operand;
|
|
||||||
totalFinalInstructions.Add(inst);
|
|
||||||
for (int k = 1; k < outputInstructions.Count; k++)
|
|
||||||
{
|
|
||||||
totalFinalInstructions.Add(outputInstructions[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
totalFinalInstructions.Add(inst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
instructions.Clear();
|
|
||||||
foreach (var obInst in totalFinalInstructions)
|
|
||||||
{
|
|
||||||
instructions.Add(obInst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: ae83aaf003665614092aabceabff3cf8
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: cf68e45551825c547b137f6e5189937e
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,92 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine.Assertions;
|
|
||||||
using Obfuz.Settings;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
public class CallObfusPass : BasicBlockObfuscationPassBase
|
|
||||||
{
|
|
||||||
private readonly List<string> _configFiles;
|
|
||||||
private readonly int _obfuscationLevel;
|
|
||||||
private IObfuscator _dynamicProxyObfuscator;
|
|
||||||
private IObfuscationPolicy _dynamicProxyPolicy;
|
|
||||||
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.CallObfus;
|
|
||||||
|
|
||||||
public CallObfusPass(CallObfuscationSettings settings)
|
|
||||||
{
|
|
||||||
_configFiles = settings.ruleFiles.ToList();
|
|
||||||
_obfuscationLevel = settings.obfuscationLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Stop()
|
|
||||||
{
|
|
||||||
_dynamicProxyObfuscator.Done();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Start()
|
|
||||||
{
|
|
||||||
var ctx = ObfuscationPassContext.Current;
|
|
||||||
_dynamicProxyObfuscator = new DefaultCallProxyObfuscator(ctx.encryptionScopeProvider, ctx.constFieldAllocator, ctx.moduleEntityManager, _obfuscationLevel);
|
|
||||||
_dynamicProxyPolicy = new ConfigurableObfuscationPolicy(ctx.assembliesToObfuscate, _configFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool NeedObfuscateMethod(MethodDef method)
|
|
||||||
{
|
|
||||||
return _dynamicProxyPolicy.NeedObfuscateCallInMethod(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override bool TryObfuscateInstruction(MethodDef callerMethod, Instruction inst, BasicBlock block,
|
|
||||||
int instructionIndex, IList<Instruction> globalInstructions, List<Instruction> outputInstructions, List<Instruction> totalFinalInstructions)
|
|
||||||
{
|
|
||||||
IMethod calledMethod = inst.Operand as IMethod;
|
|
||||||
if (calledMethod == null || !calledMethod.IsMethod)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (MetaUtil.ContainsContainsGenericParameter(calledMethod))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool callVir;
|
|
||||||
switch (inst.OpCode.Code)
|
|
||||||
{
|
|
||||||
case Code.Call:
|
|
||||||
{
|
|
||||||
callVir = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Code.Callvirt:
|
|
||||||
{
|
|
||||||
if (instructionIndex > 0 && globalInstructions[instructionIndex - 1].OpCode.Code == Code.Constrained)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
callVir = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_dynamicProxyPolicy.NeedObfuscateCalledMethod(callerMethod, calledMethod, callVir, block.inLoop))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ObfuscationCachePolicy cachePolicy = _dynamicProxyPolicy.GetMethodObfuscationCachePolicy(callerMethod);
|
|
||||||
bool cachedCallIndex = block.inLoop ? cachePolicy.cacheInLoop : cachePolicy.cacheNotInLoop;
|
|
||||||
_dynamicProxyObfuscator.Obfuscate(callerMethod, calledMethod, callVir, cachedCallIndex, outputInstructions);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 112178b770868274fb8119a4997a3420
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,293 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using Obfuz.Editor;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MethodImplAttributes = dnlib.DotNet.MethodImplAttributes;
|
|
||||||
using TypeAttributes = dnlib.DotNet.TypeAttributes;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
public struct ProxyCallMethodData
|
|
||||||
{
|
|
||||||
public readonly MethodDef proxyMethod;
|
|
||||||
public readonly int encryptOps;
|
|
||||||
public readonly int salt;
|
|
||||||
public readonly int encryptedIndex;
|
|
||||||
public readonly int index;
|
|
||||||
|
|
||||||
public ProxyCallMethodData(MethodDef proxyMethod, int encryptOps, int salt, int encryptedIndex, int index)
|
|
||||||
{
|
|
||||||
this.proxyMethod = proxyMethod;
|
|
||||||
this.encryptOps = encryptOps;
|
|
||||||
this.salt = salt;
|
|
||||||
this.encryptedIndex = encryptedIndex;
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ModuleCallProxyAllocator : IGroupByModuleEntity
|
|
||||||
{
|
|
||||||
private ModuleDef _module;
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly int _encryptionLevel;
|
|
||||||
|
|
||||||
private EncryptionScopeInfo _encryptionScope;
|
|
||||||
private bool _done;
|
|
||||||
|
|
||||||
class MethodKey : IEquatable<MethodKey>
|
|
||||||
{
|
|
||||||
public readonly IMethod _method;
|
|
||||||
public readonly bool _callVir;
|
|
||||||
private readonly int _hashCode;
|
|
||||||
|
|
||||||
public MethodKey(IMethod method, bool callVir)
|
|
||||||
{
|
|
||||||
_method = method;
|
|
||||||
_callVir = callVir;
|
|
||||||
_hashCode = HashUtil.CombineHash(MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method), callVir ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return _hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Equals(MethodKey other)
|
|
||||||
{
|
|
||||||
return MethodEqualityComparer.CompareDeclaringTypes.Equals(_method, other._method) && _callVir == other._callVir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodProxyInfo
|
|
||||||
{
|
|
||||||
public MethodDef proxyMethod;
|
|
||||||
|
|
||||||
public int index;
|
|
||||||
public int encryptedOps;
|
|
||||||
public int salt;
|
|
||||||
public int encryptedIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<MethodKey, MethodProxyInfo> _methodProxys = new Dictionary<MethodKey, MethodProxyInfo>();
|
|
||||||
|
|
||||||
|
|
||||||
const int maxProxyMethodPerDispatchMethod = 1000;
|
|
||||||
|
|
||||||
class CallInfo
|
|
||||||
{
|
|
||||||
public IMethod method;
|
|
||||||
public bool callVir;
|
|
||||||
}
|
|
||||||
|
|
||||||
class DispatchMethodInfo
|
|
||||||
{
|
|
||||||
public MethodDef methodDef;
|
|
||||||
public List<CallInfo> methods = new List<CallInfo>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<MethodSig, List<DispatchMethodInfo>> _dispatchMethods = new Dictionary<MethodSig, List<DispatchMethodInfo>>(SignatureEqualityComparer.Instance);
|
|
||||||
|
|
||||||
|
|
||||||
private TypeDef _proxyTypeDef;
|
|
||||||
|
|
||||||
public ModuleCallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, int encryptionLevel)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_encryptionLevel = encryptionLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(ModuleDef mod)
|
|
||||||
{
|
|
||||||
_module = mod;
|
|
||||||
_encryptionScope = _encryptionScopeProvider.GetScope(mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
private TypeDef CreateProxyTypeDef()
|
|
||||||
{
|
|
||||||
var typeDef = new TypeDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ProxyCall", _module.CorLibTypes.Object.ToTypeDefOrRef());
|
|
||||||
typeDef.Attributes = TypeAttributes.NotPublic | TypeAttributes.Sealed;
|
|
||||||
_module.EnableTypeDefFindCache = false;
|
|
||||||
_module.Types.Add(typeDef);
|
|
||||||
_module.EnableTypeDefFindCache = true;
|
|
||||||
return typeDef;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MethodDef CreateDispatchMethodInfo(MethodSig methodSig)
|
|
||||||
{
|
|
||||||
if (_proxyTypeDef == null)
|
|
||||||
{
|
|
||||||
_proxyTypeDef = CreateProxyTypeDef();
|
|
||||||
}
|
|
||||||
MethodDef methodDef = new MethodDefUser($"{ConstValues.ObfuzInternalSymbolNamePrefix}ProxyCall$Dispatch${_proxyTypeDef.Methods.Count}", methodSig,
|
|
||||||
MethodImplAttributes.IL | MethodImplAttributes.Managed,
|
|
||||||
MethodAttributes.Static | MethodAttributes.Public);
|
|
||||||
methodDef.DeclaringType = _proxyTypeDef;
|
|
||||||
return methodDef;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MethodSig CreateDispatchMethodSig(IMethod method)
|
|
||||||
{
|
|
||||||
MethodSig methodSig = MetaUtil.ToSharedMethodSig(_module.CorLibTypes, MetaUtil.GetInflatedMethodSig(method));
|
|
||||||
//MethodSig methodSig = MetaUtil.GetInflatedMethodSig(method).Clone();
|
|
||||||
//methodSig.Params
|
|
||||||
switch (MetaUtil.GetThisArgType(method))
|
|
||||||
{
|
|
||||||
case ThisArgType.Class:
|
|
||||||
{
|
|
||||||
methodSig.Params.Insert(0, _module.CorLibTypes.Object);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ThisArgType.ValueType:
|
|
||||||
{
|
|
||||||
methodSig.Params.Insert(0, _module.CorLibTypes.IntPtr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// extra param for index
|
|
||||||
methodSig.Params.Add(_module.CorLibTypes.Int32);
|
|
||||||
return MethodSig.CreateStatic(methodSig.RetType, methodSig.Params.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GenerateSalt(IRandom random)
|
|
||||||
{
|
|
||||||
return random.NextInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GenerateEncryptOps(IRandom random)
|
|
||||||
{
|
|
||||||
return EncryptionUtil.GenerateEncryptionOpCodes(random, _encryptionScope.encryptor, _encryptionLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private DispatchMethodInfo GetDispatchMethod(IMethod method)
|
|
||||||
{
|
|
||||||
MethodSig methodSig = CreateDispatchMethodSig(method);
|
|
||||||
if (!_dispatchMethods.TryGetValue(methodSig, out var dispatchMethods))
|
|
||||||
{
|
|
||||||
dispatchMethods = new List<DispatchMethodInfo>();
|
|
||||||
_dispatchMethods.Add(methodSig, dispatchMethods);
|
|
||||||
}
|
|
||||||
if (dispatchMethods.Count == 0 || dispatchMethods.Last().methods.Count >= maxProxyMethodPerDispatchMethod)
|
|
||||||
{
|
|
||||||
var newDispatchMethodInfo = new DispatchMethodInfo
|
|
||||||
{
|
|
||||||
methodDef = CreateDispatchMethodInfo(methodSig),
|
|
||||||
};
|
|
||||||
dispatchMethods.Add(newDispatchMethodInfo);
|
|
||||||
}
|
|
||||||
return dispatchMethods.Last();
|
|
||||||
}
|
|
||||||
|
|
||||||
private IRandom CreateRandomForMethod(IMethod method, bool callVir)
|
|
||||||
{
|
|
||||||
int seed = MethodEqualityComparer.CompareDeclaringTypes.GetHashCode(method);
|
|
||||||
return _encryptionScope.localRandomCreator(seed);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyCallMethodData Allocate(IMethod method, bool callVir)
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("can't Allocate after done");
|
|
||||||
}
|
|
||||||
var key = new MethodKey(method, callVir);
|
|
||||||
if (!_methodProxys.TryGetValue(key, out var proxyInfo))
|
|
||||||
{
|
|
||||||
var methodDispatcher = GetDispatchMethod(method);
|
|
||||||
|
|
||||||
int index = methodDispatcher.methods.Count;
|
|
||||||
IRandom localRandom = CreateRandomForMethod(method, callVir);
|
|
||||||
int encryptOps = GenerateEncryptOps(localRandom);
|
|
||||||
int salt = GenerateSalt(localRandom);
|
|
||||||
int encryptedIndex = _encryptionScope.encryptor.Encrypt(index, encryptOps, salt);
|
|
||||||
proxyInfo = new MethodProxyInfo()
|
|
||||||
{
|
|
||||||
proxyMethod = methodDispatcher.methodDef,
|
|
||||||
index = index,
|
|
||||||
encryptedOps = encryptOps,
|
|
||||||
salt = salt,
|
|
||||||
encryptedIndex = encryptedIndex,
|
|
||||||
};
|
|
||||||
methodDispatcher.methods.Add(new CallInfo { method = method, callVir = callVir});
|
|
||||||
_methodProxys.Add(key, proxyInfo);
|
|
||||||
}
|
|
||||||
return new ProxyCallMethodData(proxyInfo.proxyMethod, proxyInfo.encryptedOps, proxyInfo.salt, proxyInfo.encryptedIndex, proxyInfo.index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
if (_done)
|
|
||||||
{
|
|
||||||
throw new Exception("Already done");
|
|
||||||
}
|
|
||||||
_done = true;
|
|
||||||
|
|
||||||
foreach (DispatchMethodInfo dispatchMethod in _dispatchMethods.Values.SelectMany(ms => ms))
|
|
||||||
{
|
|
||||||
var methodDef = dispatchMethod.methodDef;
|
|
||||||
var methodSig = methodDef.MethodSig;
|
|
||||||
|
|
||||||
|
|
||||||
var body = new CilBody();
|
|
||||||
methodDef.Body = body;
|
|
||||||
var ins = body.Instructions;
|
|
||||||
|
|
||||||
foreach (Parameter param in methodDef.Parameters)
|
|
||||||
{
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Ldarg, param));
|
|
||||||
}
|
|
||||||
|
|
||||||
var switchCases = new List<Instruction>();
|
|
||||||
var switchInst = Instruction.Create(OpCodes.Switch, switchCases);
|
|
||||||
ins.Add(switchInst);
|
|
||||||
var ret = Instruction.Create(OpCodes.Ret);
|
|
||||||
foreach (CallInfo ci in dispatchMethod.methods)
|
|
||||||
{
|
|
||||||
var callTargetMethod = Instruction.Create(ci.callVir ? OpCodes.Callvirt : OpCodes.Call, ci.method);
|
|
||||||
switchCases.Add(callTargetMethod);
|
|
||||||
ins.Add(callTargetMethod);
|
|
||||||
ins.Add(Instruction.Create(OpCodes.Br, ret));
|
|
||||||
}
|
|
||||||
ins.Add(ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CallProxyAllocator
|
|
||||||
{
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
private readonly int _encryptionLevel;
|
|
||||||
|
|
||||||
public CallProxyAllocator(EncryptionScopeProvider encryptionScopeProvider, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
_encryptionLevel = encryptionLevel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModuleCallProxyAllocator GetModuleAllocator(ModuleDef mod)
|
|
||||||
{
|
|
||||||
return _moduleEntityManager.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_encryptionScopeProvider, _encryptionLevel));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProxyCallMethodData Allocate(ModuleDef mod, IMethod method, bool callVir)
|
|
||||||
{
|
|
||||||
ModuleCallProxyAllocator allocator = GetModuleAllocator(mod);
|
|
||||||
return allocator.Allocate(method, callVir);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Done()
|
|
||||||
{
|
|
||||||
foreach (var allocator in _moduleEntityManager.GetEntities<ModuleCallProxyAllocator>())
|
|
||||||
{
|
|
||||||
allocator.Done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 16b960455f093854d927c2dbd47a4826
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,411 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using Obfuz.Conf;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
public class ConfigurableObfuscationPolicy : ObfuscationPolicyBase
|
|
||||||
{
|
|
||||||
class WhiteListAssembly
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public NameMatcher nameMatcher;
|
|
||||||
public bool? obfuscate;
|
|
||||||
public List<WhiteListType> types = new List<WhiteListType>();
|
|
||||||
}
|
|
||||||
|
|
||||||
class WhiteListType
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public NameMatcher nameMatcher;
|
|
||||||
public bool? obfuscate;
|
|
||||||
public List<WhiteListMethod> methods = new List<WhiteListMethod>();
|
|
||||||
}
|
|
||||||
|
|
||||||
class WhiteListMethod
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public NameMatcher nameMatcher;
|
|
||||||
public bool? obfuscate;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ObfuscationRule : IRule<ObfuscationRule>
|
|
||||||
{
|
|
||||||
public bool? disableObfuscation;
|
|
||||||
public bool? obfuscateCallInLoop;
|
|
||||||
public bool? cacheCallIndexInLoop;
|
|
||||||
public bool? cacheCallIndexNotLoop;
|
|
||||||
|
|
||||||
public void InheritParent(ObfuscationRule parentRule)
|
|
||||||
{
|
|
||||||
if (disableObfuscation == null)
|
|
||||||
{
|
|
||||||
disableObfuscation = parentRule.disableObfuscation;
|
|
||||||
}
|
|
||||||
if (obfuscateCallInLoop == null)
|
|
||||||
{
|
|
||||||
obfuscateCallInLoop = parentRule.obfuscateCallInLoop;
|
|
||||||
}
|
|
||||||
if (cacheCallIndexInLoop == null)
|
|
||||||
{
|
|
||||||
cacheCallIndexInLoop = parentRule.cacheCallIndexInLoop;
|
|
||||||
}
|
|
||||||
if (cacheCallIndexNotLoop == null)
|
|
||||||
{
|
|
||||||
cacheCallIndexNotLoop = parentRule.cacheCallIndexNotLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AssemblySpec : AssemblyRuleBase<TypeSpec, MethodSpec, ObfuscationRule>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class TypeSpec : TypeRuleBase<MethodSpec, ObfuscationRule>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodSpec : MethodRuleBase<ObfuscationRule>
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly ObfuscationRule s_default = new ObfuscationRule()
|
|
||||||
{
|
|
||||||
disableObfuscation = false,
|
|
||||||
obfuscateCallInLoop = true,
|
|
||||||
cacheCallIndexInLoop = true,
|
|
||||||
cacheCallIndexNotLoop = false,
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly XmlAssemblyTypeMethodRuleParser<AssemblySpec, TypeSpec, MethodSpec, ObfuscationRule> _configParser;
|
|
||||||
|
|
||||||
private ObfuscationRule _global;
|
|
||||||
private readonly List<WhiteListAssembly> _whiteListAssemblies = new List<WhiteListAssembly>();
|
|
||||||
|
|
||||||
private readonly Dictionary<IMethod, bool> _whiteListMethodCache = new Dictionary<IMethod, bool>(MethodEqualityComparer.CompareDeclaringTypes);
|
|
||||||
private readonly Dictionary<MethodDef, ObfuscationRule> _methodRuleCache = new Dictionary<MethodDef, ObfuscationRule>();
|
|
||||||
|
|
||||||
public ConfigurableObfuscationPolicy(List<string> toObfuscatedAssemblyNames, List<string> xmlConfigFiles)
|
|
||||||
{
|
|
||||||
_configParser = new XmlAssemblyTypeMethodRuleParser<AssemblySpec, TypeSpec, MethodSpec, ObfuscationRule>(toObfuscatedAssemblyNames,
|
|
||||||
ParseObfuscationRule, ParseGlobalElement);
|
|
||||||
LoadConfigs(xmlConfigFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadConfigs(List<string> configFiles)
|
|
||||||
{
|
|
||||||
_configParser.LoadConfigs(configFiles);
|
|
||||||
|
|
||||||
if (_global == null)
|
|
||||||
{
|
|
||||||
_global = s_default;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_global.InheritParent(s_default);
|
|
||||||
}
|
|
||||||
_configParser.InheritParentRules(_global);
|
|
||||||
InheritWhitelistRules();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InheritWhitelistRules()
|
|
||||||
{
|
|
||||||
foreach (var ass in _whiteListAssemblies)
|
|
||||||
{
|
|
||||||
foreach (var type in ass.types)
|
|
||||||
{
|
|
||||||
if (type.obfuscate == null)
|
|
||||||
{
|
|
||||||
type.obfuscate = ass.obfuscate;
|
|
||||||
}
|
|
||||||
foreach (var method in type.methods)
|
|
||||||
{
|
|
||||||
if (method.obfuscate == null)
|
|
||||||
{
|
|
||||||
method.obfuscate = type.obfuscate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseGlobalElement(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "global": _global = ParseObfuscationRule(configFile, ele); break;
|
|
||||||
case "whitelist": ParseWhitelist(ele); break;
|
|
||||||
default: throw new Exception($"Invalid xml file {configFile}, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
var rule = new ObfuscationRule();
|
|
||||||
if (ele.HasAttribute("disableObfuscation"))
|
|
||||||
{
|
|
||||||
rule.disableObfuscation = ConfigUtil.ParseBool(ele.GetAttribute("disableObfuscation"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("obfuscateCallInLoop"))
|
|
||||||
{
|
|
||||||
rule.obfuscateCallInLoop = ConfigUtil.ParseBool(ele.GetAttribute("obfuscateCallInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheCallIndexInLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheCallIndexInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheCallIndexInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheCallIndexNotLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheCallIndexNotLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheCallIndexNotLoop"));
|
|
||||||
}
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseWhitelist(XmlElement ruleEle)
|
|
||||||
{
|
|
||||||
foreach (XmlNode xmlNode in ruleEle.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(xmlNode is XmlElement childEle))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (childEle.Name)
|
|
||||||
{
|
|
||||||
case "assembly":
|
|
||||||
{
|
|
||||||
var ass = ParseWhiteListAssembly(childEle);
|
|
||||||
_whiteListAssemblies.Add(ass);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: throw new Exception($"Invalid xml file, unknown node {childEle.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private WhiteListAssembly ParseWhiteListAssembly(XmlElement element)
|
|
||||||
{
|
|
||||||
var ass = new WhiteListAssembly();
|
|
||||||
ass.name = element.GetAttribute("name");
|
|
||||||
ass.nameMatcher = new NameMatcher(ass.name);
|
|
||||||
|
|
||||||
ass.obfuscate = ConfigUtil.ParseNullableBool(element.GetAttribute("obfuscate")) ?? false;
|
|
||||||
|
|
||||||
foreach (XmlNode node in element.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "type":
|
|
||||||
ass.types.Add(ParseWhiteListType(ele));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Exception($"Invalid xml file, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ass;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WhiteListType ParseWhiteListType(XmlElement element)
|
|
||||||
{
|
|
||||||
var type = new WhiteListType();
|
|
||||||
type.name = element.GetAttribute("name");
|
|
||||||
type.nameMatcher = new NameMatcher(type.name);
|
|
||||||
type.obfuscate = ConfigUtil.ParseNullableBool(element.GetAttribute("obfuscate"));
|
|
||||||
|
|
||||||
foreach (XmlNode node in element.ChildNodes)
|
|
||||||
{
|
|
||||||
if (!(node is XmlElement ele))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "method":
|
|
||||||
{
|
|
||||||
type.methods.Add(ParseWhiteListMethod(ele));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: throw new Exception($"Invalid xml file, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WhiteListMethod ParseWhiteListMethod(XmlElement element)
|
|
||||||
{
|
|
||||||
var method = new WhiteListMethod();
|
|
||||||
method.name = element.GetAttribute("name");
|
|
||||||
method.nameMatcher = new NameMatcher(method.name);
|
|
||||||
method.obfuscate = ConfigUtil.ParseNullableBool(element.GetAttribute("obfuscate"));
|
|
||||||
return method;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObfuscationRule GetMethodObfuscationRule(MethodDef method)
|
|
||||||
{
|
|
||||||
if (!_methodRuleCache.TryGetValue(method, out var rule))
|
|
||||||
{
|
|
||||||
rule = _configParser.GetMethodRule(method, s_default);
|
|
||||||
_methodRuleCache[method] = rule;
|
|
||||||
}
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateCallInMethod(MethodDef method)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
return rule.disableObfuscation != true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
return new ObfuscationCachePolicy()
|
|
||||||
{
|
|
||||||
cacheInLoop = rule.cacheCallIndexInLoop.Value,
|
|
||||||
cacheNotInLoop = rule.cacheCallIndexNotLoop.Value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private bool IsSpecialNotObfuscatedMethod(TypeDef typeDef, IMethod method)
|
|
||||||
{
|
|
||||||
if (typeDef.IsDelegate || typeDef.IsEnum)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
string methodName = method.Name;
|
|
||||||
|
|
||||||
// doesn't proxy call if the method is a constructor
|
|
||||||
if (methodName == ".ctor")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeDef.Name == "EncryptionService`1")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// special handle
|
|
||||||
// don't proxy call for List<T>.Enumerator GetEnumerator()
|
|
||||||
if (methodName == "GetEnumerator")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ComputeIsInWhiteList(IMethod calledMethod)
|
|
||||||
{
|
|
||||||
ITypeDefOrRef declaringType = calledMethod.DeclaringType;
|
|
||||||
TypeSig declaringTypeSig = calledMethod.DeclaringType.ToTypeSig();
|
|
||||||
declaringTypeSig = declaringTypeSig.RemovePinnedAndModifiers();
|
|
||||||
switch (declaringTypeSig.ElementType)
|
|
||||||
{
|
|
||||||
case ElementType.ValueType:
|
|
||||||
case ElementType.Class:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ElementType.GenericInst:
|
|
||||||
{
|
|
||||||
if (MetaUtil.ContainsContainsGenericParameter(calledMethod))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TypeDef typeDef = declaringType.ResolveTypeDef();
|
|
||||||
|
|
||||||
if (IsSpecialNotObfuscatedMethod(typeDef, calledMethod))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
string assName = typeDef.Module.Assembly.Name;
|
|
||||||
string typeFullName = typeDef.FullName;
|
|
||||||
string methodName = calledMethod.Name;
|
|
||||||
foreach (var ass in _whiteListAssemblies)
|
|
||||||
{
|
|
||||||
if (!ass.nameMatcher.IsMatch(assName))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foreach (var type in ass.types)
|
|
||||||
{
|
|
||||||
if (!type.nameMatcher.IsMatch(typeFullName))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
foreach (var method in type.methods)
|
|
||||||
{
|
|
||||||
if (method.nameMatcher.IsMatch(methodName))
|
|
||||||
{
|
|
||||||
return !method.obfuscate.Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !type.obfuscate.Value;
|
|
||||||
}
|
|
||||||
return !ass.obfuscate.Value;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsInWhiteList(IMethod method)
|
|
||||||
{
|
|
||||||
if (!_whiteListMethodCache.TryGetValue(method, out var isWhiteList))
|
|
||||||
{
|
|
||||||
isWhiteList = ComputeIsInWhiteList(method);
|
|
||||||
_whiteListMethodCache.Add(method, isWhiteList);
|
|
||||||
}
|
|
||||||
return isWhiteList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsTypeSelfAndParentPublic(TypeDef type)
|
|
||||||
{
|
|
||||||
if (type.DeclaringType != null && !IsTypeSelfAndParentPublic(type.DeclaringType))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return type.IsPublic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop)
|
|
||||||
{
|
|
||||||
if (IsInWhiteList(calledMethod))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// mono has more strict access control, calls non-public method will raise exception.
|
|
||||||
if (PlatformUtil.IsMonoBackend())
|
|
||||||
{
|
|
||||||
MethodDef calledMethodDef = calledMethod.ResolveMethodDef();
|
|
||||||
if (calledMethodDef != null && (!calledMethodDef.IsPublic || !IsTypeSelfAndParentPublic(calledMethodDef.DeclaringType)))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(callerMethod);
|
|
||||||
if (currentInLoop && rule.obfuscateCallInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: d9ea12b16c4b296459db8a60fb1615d6
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,53 +0,0 @@
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using dnlib.DotNet;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using Obfuz.Emit;
|
|
||||||
using Obfuz.Data;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
public class DefaultCallProxyObfuscator : ObfuscatorBase
|
|
||||||
{
|
|
||||||
private readonly EncryptionScopeProvider _encryptionScopeProvider;
|
|
||||||
private readonly ConstFieldAllocator _constFieldAllocator;
|
|
||||||
private readonly CallProxyAllocator _proxyCallAllocator;
|
|
||||||
private readonly GroupByModuleEntityManager _moduleEntityManager;
|
|
||||||
|
|
||||||
public DefaultCallProxyObfuscator(EncryptionScopeProvider encryptionScopeProvider, ConstFieldAllocator constFieldAllocator, GroupByModuleEntityManager moduleEntityManager, int encryptionLevel)
|
|
||||||
{
|
|
||||||
_encryptionScopeProvider = encryptionScopeProvider;
|
|
||||||
_constFieldAllocator = constFieldAllocator;
|
|
||||||
_moduleEntityManager = moduleEntityManager;
|
|
||||||
_proxyCallAllocator = new CallProxyAllocator(encryptionScopeProvider, moduleEntityManager, encryptionLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Done()
|
|
||||||
{
|
|
||||||
_proxyCallAllocator.Done();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Obfuscate(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions)
|
|
||||||
{
|
|
||||||
|
|
||||||
MethodSig sharedMethodSig = MetaUtil.ToSharedMethodSig(calledMethod.Module.CorLibTypes, MetaUtil.GetInflatedMethodSig(calledMethod));
|
|
||||||
ProxyCallMethodData proxyCallMethodData = _proxyCallAllocator.Allocate(callerMethod.Module, calledMethod, callVir);
|
|
||||||
DefaultMetadataImporter importer = _moduleEntityManager.GetDefaultModuleMetadataImporter(callerMethod.Module, _encryptionScopeProvider);
|
|
||||||
|
|
||||||
if (needCacheCall)
|
|
||||||
{
|
|
||||||
FieldDef cacheField = _constFieldAllocator.Allocate(callerMethod.Module, proxyCallMethodData.index);
|
|
||||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, cacheField));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptedIndex));
|
|
||||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.encryptOps));
|
|
||||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(proxyCallMethodData.salt));
|
|
||||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, importer.DecryptInt));
|
|
||||||
}
|
|
||||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Call, proxyCallMethodData.proxyMethod));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e13ba01b03439e049af0e09367825cde
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,34 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
|
|
||||||
public struct ObfuscationCachePolicy
|
|
||||||
{
|
|
||||||
public bool cacheInLoop;
|
|
||||||
public bool cacheNotInLoop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface IObfuscationPolicy
|
|
||||||
{
|
|
||||||
bool NeedObfuscateCallInMethod(MethodDef method);
|
|
||||||
|
|
||||||
ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method);
|
|
||||||
|
|
||||||
bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class ObfuscationPolicyBase : IObfuscationPolicy
|
|
||||||
{
|
|
||||||
public abstract bool NeedObfuscateCallInMethod(MethodDef method);
|
|
||||||
|
|
||||||
public abstract ObfuscationCachePolicy GetMethodObfuscationCachePolicy(MethodDef method);
|
|
||||||
|
|
||||||
public abstract bool NeedObfuscateCalledMethod(MethodDef callerMethod, IMethod calledMethod, bool callVir, bool currentInLoop);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 6af3cd881fdefd14d9a55b77088dd5a4
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,23 +0,0 @@
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using dnlib.DotNet;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CallObfus
|
|
||||||
{
|
|
||||||
public interface IObfuscator
|
|
||||||
{
|
|
||||||
void Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions);
|
|
||||||
|
|
||||||
void Done();
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class ObfuscatorBase : IObfuscator
|
|
||||||
{
|
|
||||||
public abstract void Obfuscate(MethodDef callingMethod, IMethod calledMethod, bool callVir, bool needCacheCall, List<Instruction> obfuscatedInstructions);
|
|
||||||
public abstract void Done();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 4156317478f8b1d438ef6d5a280d409f
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 2764442d8fc2b914dbc39dcfa2699698
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,46 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CleanUp
|
|
||||||
{
|
|
||||||
public class CleanUpInstructionPass : ObfuscationPassBase
|
|
||||||
{
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.None;
|
|
||||||
|
|
||||||
public override void Start()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Stop()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Process()
|
|
||||||
{
|
|
||||||
var ctx = ObfuscationPassContext.Current;
|
|
||||||
foreach (ModuleDef mod in ctx.modulesToObfuscate)
|
|
||||||
{
|
|
||||||
foreach (TypeDef type in mod.GetTypes())
|
|
||||||
{
|
|
||||||
foreach (MethodDef method in type.Methods)
|
|
||||||
{
|
|
||||||
if (method.HasBody)
|
|
||||||
{
|
|
||||||
CilBody body = method.Body;
|
|
||||||
body.SimplifyBranches();
|
|
||||||
body.OptimizeMacros();
|
|
||||||
body.OptimizeBranches();
|
|
||||||
// TODO remove dup
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 78cc056cd929d70409a0f0737b571a6d
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,71 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using dnlib.DotNet.Emit;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.CleanUp
|
|
||||||
{
|
|
||||||
public class RemoveObfuzAttributesPass : ObfuscationPassBase
|
|
||||||
{
|
|
||||||
public override ObfuscationPassType Type => ObfuscationPassType.None;
|
|
||||||
|
|
||||||
public override void Start()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Stop()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void RemoveObfuzAttributes(IHasCustomAttribute provider)
|
|
||||||
{
|
|
||||||
CustomAttributeCollection customAttributes = provider.CustomAttributes;
|
|
||||||
if (customAttributes.Count == 0)
|
|
||||||
return;
|
|
||||||
var toRemove = new List<CustomAttribute>();
|
|
||||||
customAttributes.RemoveAll("Obfuz.ObfuzIgnoreAttribute");
|
|
||||||
customAttributes.RemoveAll("Obfuz.EncryptFieldAttribute");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Process()
|
|
||||||
{
|
|
||||||
var ctx = ObfuscationPassContext.Current;
|
|
||||||
foreach (ModuleDef mod in ctx.modulesToObfuscate)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(mod);
|
|
||||||
foreach (TypeDef type in mod.GetTypes())
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(type);
|
|
||||||
foreach (FieldDef field in type.Fields)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(field);
|
|
||||||
}
|
|
||||||
foreach (MethodDef method in type.Methods)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(method);
|
|
||||||
foreach (Parameter param in method.Parameters)
|
|
||||||
{
|
|
||||||
if (param.ParamDef != null)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(param.ParamDef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (PropertyDef property in type.Properties)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(property);
|
|
||||||
}
|
|
||||||
foreach (EventDef eventDef in type.Events)
|
|
||||||
{
|
|
||||||
RemoveObfuzAttributes(eventDef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 6b475010a7656a0439ca8664a3d2dbc0
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 18104d0c3c665ea489e566eec67f2aea
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,489 +0,0 @@
|
||||||
using dnlib.DotNet;
|
|
||||||
using Obfuz.Conf;
|
|
||||||
using Obfuz.Utils;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Xml;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
|
||||||
{
|
|
||||||
|
|
||||||
public class ConfigurableEncryptPolicy : EncryptPolicyBase
|
|
||||||
{
|
|
||||||
class ObfuscationRule : IRule<ObfuscationRule>
|
|
||||||
{
|
|
||||||
public bool? disableEncrypt;
|
|
||||||
public bool? encryptInt;
|
|
||||||
public bool? encryptLong;
|
|
||||||
public bool? encryptFloat;
|
|
||||||
public bool? encryptDouble;
|
|
||||||
public bool? encryptArray;
|
|
||||||
public bool? encryptString;
|
|
||||||
|
|
||||||
public bool? encryptConstInLoop;
|
|
||||||
public bool? encryptStringInLoop;
|
|
||||||
|
|
||||||
public bool? cacheConstInLoop;
|
|
||||||
public bool? cacheConstNotInLoop;
|
|
||||||
public bool? cacheStringInLoop;
|
|
||||||
public bool? cacheStringNotInLoop;
|
|
||||||
|
|
||||||
public void InheritParent(ObfuscationRule parentRule)
|
|
||||||
{
|
|
||||||
if (disableEncrypt == null)
|
|
||||||
disableEncrypt = parentRule.disableEncrypt;
|
|
||||||
if (encryptInt == null)
|
|
||||||
encryptInt = parentRule.encryptInt;
|
|
||||||
if (encryptLong == null)
|
|
||||||
encryptLong = parentRule.encryptLong;
|
|
||||||
if (encryptFloat == null)
|
|
||||||
encryptFloat = parentRule.encryptFloat;
|
|
||||||
if (encryptDouble == null)
|
|
||||||
encryptDouble = parentRule.encryptDouble;
|
|
||||||
if (encryptArray == null)
|
|
||||||
encryptArray = parentRule.encryptArray;
|
|
||||||
if (encryptString == null)
|
|
||||||
encryptString = parentRule.encryptString;
|
|
||||||
|
|
||||||
if (encryptConstInLoop == null)
|
|
||||||
encryptConstInLoop = parentRule.encryptConstInLoop;
|
|
||||||
if (encryptStringInLoop == null)
|
|
||||||
encryptStringInLoop = parentRule.encryptStringInLoop;
|
|
||||||
|
|
||||||
if (cacheConstInLoop == null)
|
|
||||||
cacheConstInLoop = parentRule.cacheConstInLoop;
|
|
||||||
if (cacheConstNotInLoop == null)
|
|
||||||
cacheConstNotInLoop = parentRule.cacheConstNotInLoop;
|
|
||||||
if (cacheStringInLoop == null)
|
|
||||||
cacheStringInLoop = parentRule.cacheStringInLoop;
|
|
||||||
if (cacheStringNotInLoop == null)
|
|
||||||
cacheStringNotInLoop = parentRule.cacheStringNotInLoop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MethodSpec : MethodRuleBase<ObfuscationRule>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class TypeSpec : TypeRuleBase<MethodSpec, ObfuscationRule>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
class AssemblySpec : AssemblyRuleBase<TypeSpec, MethodSpec, ObfuscationRule>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static readonly ObfuscationRule s_default = new ObfuscationRule()
|
|
||||||
{
|
|
||||||
disableEncrypt = false,
|
|
||||||
encryptInt = true,
|
|
||||||
encryptLong = true,
|
|
||||||
encryptFloat = true,
|
|
||||||
encryptDouble = true,
|
|
||||||
encryptArray = true,
|
|
||||||
encryptString = true,
|
|
||||||
encryptConstInLoop = true,
|
|
||||||
encryptStringInLoop = true,
|
|
||||||
cacheConstInLoop = true,
|
|
||||||
cacheConstNotInLoop = false,
|
|
||||||
cacheStringInLoop = true,
|
|
||||||
cacheStringNotInLoop = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
private ObfuscationRule _global;
|
|
||||||
|
|
||||||
public HashSet<int> notEncryptInts = new HashSet<int>();
|
|
||||||
public HashSet<long> notEncryptLongs = new HashSet<long>();
|
|
||||||
public HashSet<string> notEncryptStrings = new HashSet<string>();
|
|
||||||
public List<NumberRange<int>> notEncryptIntRanges = new List<NumberRange<int>>();
|
|
||||||
public List<NumberRange<long>> notEncryptLongRanges = new List<NumberRange<long>>();
|
|
||||||
public List<NumberRange<float>> notEncryptFloatRanges = new List<NumberRange<float>>();
|
|
||||||
public List<NumberRange<double>> notEncryptDoubleRanges = new List<NumberRange<double>>();
|
|
||||||
public List<NumberRange<int>> notEncryptArrayLengthRanges = new List<NumberRange<int>>();
|
|
||||||
public List<NumberRange<int>> notEncryptStringLengthRanges = new List<NumberRange<int>>();
|
|
||||||
|
|
||||||
private readonly XmlAssemblyTypeMethodRuleParser<AssemblySpec, TypeSpec, MethodSpec, ObfuscationRule> _xmlParser;
|
|
||||||
|
|
||||||
private readonly Dictionary<string, AssemblySpec> _assemblySpecs = new Dictionary<string, AssemblySpec>();
|
|
||||||
private readonly Dictionary<MethodDef, ObfuscationRule> _methodRuleCache = new Dictionary<MethodDef, ObfuscationRule>();
|
|
||||||
|
|
||||||
public ConfigurableEncryptPolicy(List<string> toObfuscatedAssemblyNames, List<string> xmlConfigFiles)
|
|
||||||
{
|
|
||||||
_xmlParser = new XmlAssemblyTypeMethodRuleParser<AssemblySpec, TypeSpec, MethodSpec, ObfuscationRule>(
|
|
||||||
toObfuscatedAssemblyNames, ParseObfuscationRule, ParseGlobalElement);
|
|
||||||
LoadConfigs(xmlConfigFiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LoadConfigs(List<string> configFiles)
|
|
||||||
{
|
|
||||||
_xmlParser.LoadConfigs(configFiles);
|
|
||||||
if (_global == null)
|
|
||||||
{
|
|
||||||
_global = s_default;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_global.InheritParent(s_default);
|
|
||||||
}
|
|
||||||
_xmlParser.InheritParentRules(_global);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseGlobalElement(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
switch (ele.Name)
|
|
||||||
{
|
|
||||||
case "global": _global = ParseObfuscationRule(configFile, ele); break;
|
|
||||||
case "whitelist": ParseWhitelist(configFile, ele); break;
|
|
||||||
default: throw new Exception($"Invalid xml file {configFile}, unknown node {ele.Name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObfuscationRule ParseObfuscationRule(string configFile, XmlElement ele)
|
|
||||||
{
|
|
||||||
var rule = new ObfuscationRule();
|
|
||||||
if (ele.HasAttribute("disableEncrypt"))
|
|
||||||
{
|
|
||||||
rule.disableEncrypt = ConfigUtil.ParseBool(ele.GetAttribute("disableEncrypt"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptInt"))
|
|
||||||
{
|
|
||||||
rule.encryptInt = ConfigUtil.ParseBool(ele.GetAttribute("encryptInt"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptLong"))
|
|
||||||
{
|
|
||||||
rule.encryptLong = ConfigUtil.ParseBool(ele.GetAttribute("encryptLong"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptFloat"))
|
|
||||||
{
|
|
||||||
rule.encryptFloat = ConfigUtil.ParseBool(ele.GetAttribute("encryptFloat"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptDouble"))
|
|
||||||
{
|
|
||||||
rule.encryptDouble = ConfigUtil.ParseBool(ele.GetAttribute("encryptDouble"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptBytes"))
|
|
||||||
{
|
|
||||||
rule.encryptArray = ConfigUtil.ParseBool(ele.GetAttribute("encryptArray"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptString"))
|
|
||||||
{
|
|
||||||
rule.encryptString = ConfigUtil.ParseBool(ele.GetAttribute("encryptString"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ele.HasAttribute("encryptConstInLoop"))
|
|
||||||
{
|
|
||||||
rule.encryptConstInLoop = ConfigUtil.ParseBool(ele.GetAttribute("encryptConstInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("encryptStringInLoop"))
|
|
||||||
{
|
|
||||||
rule.encryptStringInLoop = ConfigUtil.ParseBool(ele.GetAttribute("encryptStringInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheConstInLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheConstInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheConstInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheConstNotInLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheConstNotInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheConstNotInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheStringInLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheStringInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheStringInLoop"));
|
|
||||||
}
|
|
||||||
if (ele.HasAttribute("cacheStringNotInLoop"))
|
|
||||||
{
|
|
||||||
rule.cacheStringNotInLoop = ConfigUtil.ParseBool(ele.GetAttribute("cacheStringNotInLoop"));
|
|
||||||
}
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ParseWhitelist(string configFile, XmlElement childEle)
|
|
||||||
{
|
|
||||||
string type = childEle.GetAttribute("type");
|
|
||||||
if (string.IsNullOrEmpty(type))
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, whitelist type is empty");
|
|
||||||
}
|
|
||||||
string value = childEle.InnerText;
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case "int":
|
|
||||||
{
|
|
||||||
notEncryptInts.AddRange(value.Split(',').Select(s => int.Parse(s.Trim())));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "long":
|
|
||||||
{
|
|
||||||
notEncryptLongs.AddRange(value.Split(',').Select(s => long.Parse(s.Trim())));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "string":
|
|
||||||
{
|
|
||||||
notEncryptStrings.AddRange(value.Split(',').Select(s => s.Trim()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "int-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, int-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptIntRanges.Add(new NumberRange<int>(ConfigUtil.ParseNullableInt(parts[0]), ConfigUtil.ParseNullableInt(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "long-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, long-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptLongRanges.Add(new NumberRange<long>(ConfigUtil.ParseNullableLong(parts[0]), ConfigUtil.ParseNullableLong(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "float-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, float-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptFloatRanges.Add(new NumberRange<float>(ConfigUtil.ParseNullableFloat(parts[0]), ConfigUtil.ParseNullableFloat(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "double-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, double-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptDoubleRanges.Add(new NumberRange<double>(ConfigUtil.ParseNullableDouble(parts[0]), ConfigUtil.ParseNullableDouble(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "string-length-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, string-length-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptStringLengthRanges.Add(new NumberRange<int>(ConfigUtil.ParseNullableInt(parts[0]), ConfigUtil.ParseNullableInt(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "array-length-range":
|
|
||||||
{
|
|
||||||
var parts = value.Split(',');
|
|
||||||
if (parts.Length != 2)
|
|
||||||
{
|
|
||||||
throw new Exception($"Invalid xml file, array-length-range {value} is invalid");
|
|
||||||
}
|
|
||||||
notEncryptArrayLengthRanges.Add(new NumberRange<int>(ConfigUtil.ParseNullableInt(parts[0]), ConfigUtil.ParseNullableInt(parts[1])));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: throw new Exception($"Invalid xml file, unknown whitelist type {type} in {childEle.Name} node");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ObfuscationRule GetMethodObfuscationRule(MethodDef method)
|
|
||||||
{
|
|
||||||
if (!_methodRuleCache.TryGetValue(method, out var rule))
|
|
||||||
{
|
|
||||||
rule = _xmlParser.GetMethodRule(method, _global);
|
|
||||||
_methodRuleCache[method] = rule;
|
|
||||||
}
|
|
||||||
return rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateMethod(MethodDef method)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
return rule.disableEncrypt != true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ConstCachePolicy GetMethodConstCachePolicy(MethodDef method)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
return new ConstCachePolicy
|
|
||||||
{
|
|
||||||
cacheConstInLoop = rule.cacheConstInLoop.Value,
|
|
||||||
cacheConstNotInLoop = rule.cacheConstNotInLoop.Value,
|
|
||||||
cacheStringInLoop = rule.cacheStringInLoop.Value,
|
|
||||||
cacheStringNotInLoop = rule.cacheStringNotInLoop.Value,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateInt(MethodDef method, bool currentInLoop, int value)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptInt == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (notEncryptInts.Contains(value))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptIntRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && value < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && value > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateLong(MethodDef method, bool currentInLoop, long value)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptLong == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (notEncryptLongs.Contains(value))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptLongRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && value < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && value > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateFloat(MethodDef method, bool currentInLoop, float value)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptFloat == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptFloatRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && value < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && value > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateDouble(MethodDef method, bool currentInLoop, double value)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptDouble == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptDoubleRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && value < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && value > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateString(MethodDef method, bool currentInLoop, string value)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptString == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (notEncryptStrings.Contains(value))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptStringLengthRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && value.Length < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && value.Length > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool NeedObfuscateArray(MethodDef method, bool currentInLoop, byte[] array)
|
|
||||||
{
|
|
||||||
ObfuscationRule rule = GetMethodObfuscationRule(method);
|
|
||||||
if (rule.encryptArray == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (currentInLoop && rule.encryptConstInLoop == false)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
foreach (var range in notEncryptArrayLengthRanges)
|
|
||||||
{
|
|
||||||
if (range.min != null && array.Length < range.min)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (range.max != null && array.Length > range.max)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: da25453bc1fda394097c052af7733260
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue