backup
parent
62845a5c35
commit
3c6cc385a4
|
@ -258,6 +258,28 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
// 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;
|
||||
|
@ -283,25 +305,14 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
TypeDef typeDef = declaringType.ResolveTypeDef();
|
||||
|
||||
if (typeDef.IsDelegate || typeDef.IsEnum)
|
||||
if (IsSpecialNotObfuscatedMethod(typeDef, calledMethod))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string assName = typeDef.Module.Assembly.Name;
|
||||
string typeFullName = typeDef.FullName;
|
||||
string methodName = calledMethod.Name;
|
||||
|
||||
// doesn't proxy call if the method is a constructor
|
||||
if (methodName == ".ctor")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// special handle
|
||||
// don't proxy call for List<T>.Enumerator GetEnumerator()
|
||||
if (methodName == "GetEnumerator")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (var ass in _whiteListAssemblies)
|
||||
{
|
||||
if (!ass.nameMatcher.IsMatch(assName))
|
||||
|
|
|
@ -22,4 +22,13 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,10 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
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,13 +0,0 @@
|
|||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
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,12 +0,0 @@
|
|||
using dnlib.DotNet.Emit;
|
||||
using dnlib.DotNet;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.CallObfus
|
||||
{
|
||||
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,16 +0,0 @@
|
|||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.ConstEncrypt
|
||||
{
|
||||
public abstract class EncryptPolicyBase : IEncryptPolicy
|
||||
{
|
||||
public abstract bool NeedObfuscateMethod(MethodDef method);
|
||||
public abstract ConstCachePolicy GetMethodConstCachePolicy(MethodDef method);
|
||||
public abstract bool NeedObfuscateDouble(MethodDef method, bool currentInLoop, double value);
|
||||
public abstract bool NeedObfuscateFloat(MethodDef method, bool currentInLoop, float value);
|
||||
public abstract bool NeedObfuscateInt(MethodDef method, bool currentInLoop, int value);
|
||||
public abstract bool NeedObfuscateLong(MethodDef method, bool currentInLoop, long value);
|
||||
public abstract bool NeedObfuscateString(MethodDef method, bool currentInLoop, string value);
|
||||
public abstract bool NeedObfuscateArray(MethodDef method, bool currentInLoop, byte[] array);
|
||||
}
|
||||
}
|
|
@ -21,4 +21,15 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
void Done();
|
||||
}
|
||||
|
||||
public abstract class ConstEncryptorBase : IConstEncryptor
|
||||
{
|
||||
public abstract void ObfuscateBytes(MethodDef method, bool needCacheValue, byte[] value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void ObfuscateDouble(MethodDef method, bool needCacheValue, double value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void ObfuscateFloat(MethodDef method, bool needCacheValue, float value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void ObfuscateInt(MethodDef method, bool needCacheValue, int value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void ObfuscateLong(MethodDef method, bool needCacheValue, long value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void ObfuscateString(MethodDef method, bool needCacheValue, string value, List<Instruction> obfuscatedInstructions);
|
||||
public abstract void Done();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,4 +33,16 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
|
||||
bool NeedObfuscateArray(MethodDef method, bool currentInLoop, byte[] array);
|
||||
}
|
||||
|
||||
public abstract class EncryptPolicyBase : IEncryptPolicy
|
||||
{
|
||||
public abstract bool NeedObfuscateMethod(MethodDef method);
|
||||
public abstract ConstCachePolicy GetMethodConstCachePolicy(MethodDef method);
|
||||
public abstract bool NeedObfuscateDouble(MethodDef method, bool currentInLoop, double value);
|
||||
public abstract bool NeedObfuscateFloat(MethodDef method, bool currentInLoop, float value);
|
||||
public abstract bool NeedObfuscateInt(MethodDef method, bool currentInLoop, int value);
|
||||
public abstract bool NeedObfuscateLong(MethodDef method, bool currentInLoop, long value);
|
||||
public abstract bool NeedObfuscateString(MethodDef method, bool currentInLoop, string value);
|
||||
public abstract bool NeedObfuscateArray(MethodDef method, bool currentInLoop, byte[] array);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Obfuz.ObfusPasses.ExprObfus
|
||||
{
|
||||
public class ExprObfuscationPass : InstructionObfuscationPassBase
|
||||
public class ExprObfusPass : InstructionObfuscationPassBase
|
||||
{
|
||||
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
public class ConfigEncryptionPolicy : EncryptionPolicyBase
|
||||
public class ConfigEncryptionPolicy : EncryptPolicyBase
|
||||
{
|
||||
|
||||
private bool IsSupportedFieldType(TypeSig type)
|
||||
|
|
|
@ -8,7 +8,7 @@ using UnityEngine.Assertions;
|
|||
|
||||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
public class DefaultMemoryEncryptor : MemoryEncryptorBase
|
||||
public class DefaultMemoryEncryptor : MemEncryptorBase
|
||||
{
|
||||
|
||||
private class ModuleDefaultMemoryEncryptor
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
using dnlib.DotNet;
|
||||
|
||||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
public abstract class EncryptionPolicyBase : IEncryptionPolicy
|
||||
{
|
||||
public abstract bool NeedEncrypt(FieldDef field);
|
||||
}
|
||||
}
|
|
@ -7,8 +7,13 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
public interface IEncryptionPolicy
|
||||
public interface IEncryptPolicy
|
||||
{
|
||||
bool NeedEncrypt(FieldDef field);
|
||||
}
|
||||
|
||||
public abstract class EncryptPolicyBase : IEncryptPolicy
|
||||
{
|
||||
public abstract bool NeedEncrypt(FieldDef field);
|
||||
}
|
||||
}
|
|
@ -14,10 +14,16 @@ namespace Obfuz.ObfusPasses.MemEncrypt
|
|||
public Instruction currentInstruction;
|
||||
}
|
||||
|
||||
public interface IMemoryEncryptor
|
||||
public interface IMemEncryptor
|
||||
{
|
||||
void Encrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
|
||||
void Decrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
}
|
||||
|
||||
public abstract class MemEncryptorBase : IMemEncryptor
|
||||
{
|
||||
public abstract void Encrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
public abstract void Decrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
}
|
||||
}
|
|
@ -9,10 +9,10 @@ using UnityEngine;
|
|||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
|
||||
public class MemoryEncryptionPass : InstructionObfuscationPassBase
|
||||
public class MemEncryptPass : InstructionObfuscationPassBase
|
||||
{
|
||||
private readonly IEncryptionPolicy _encryptionPolicy = new ConfigEncryptionPolicy();
|
||||
private readonly IMemoryEncryptor _memoryEncryptor = new DefaultMemoryEncryptor();
|
||||
private readonly IEncryptPolicy _encryptionPolicy = new ConfigEncryptionPolicy();
|
||||
private readonly IMemEncryptor _memoryEncryptor = new DefaultMemoryEncryptor();
|
||||
|
||||
public override void Start(ObfuscationPassContext ctx)
|
||||
{
|
|
@ -1,12 +0,0 @@
|
|||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Obfuz.ObfusPasses.MemEncrypt
|
||||
{
|
||||
public abstract class MemoryEncryptorBase : IMemoryEncryptor
|
||||
{
|
||||
public abstract void Encrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
public abstract void Decrypt(FieldDef field, List<Instruction> outputInstructions, MemoryEncryptionContext ctx);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using dnlib.Protection;
|
|||
using Obfuz.Data;
|
||||
using Obfuz.Emit;
|
||||
using Obfuz.ObfusPasses;
|
||||
using Obfuz.ObfusPasses.CleanUp;
|
||||
using Obfuz.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -11,6 +12,7 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using static UnityEditor.ObjectChangeEventStream;
|
||||
|
||||
namespace Obfuz
|
||||
{
|
||||
|
@ -46,6 +48,7 @@ namespace Obfuz
|
|||
{
|
||||
_pipeline.AddPass(pass);
|
||||
}
|
||||
_pipeline.AddPass(new CleanUpInstructionPass());
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
|
|
@ -77,7 +77,7 @@ namespace Obfuz
|
|||
ObfuscationPassType obfuscationPasses = settings.enabledObfuscationPasses;
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.MemoryEncryption))
|
||||
{
|
||||
builder.AddPass(new MemoryEncryptionPass());
|
||||
builder.AddPass(new MemEncryptPass());
|
||||
}
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.CallProxy))
|
||||
{
|
||||
|
@ -89,13 +89,12 @@ namespace Obfuz
|
|||
}
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.ExprObfuscation))
|
||||
{
|
||||
builder.AddPass(new ExprObfuscationPass());
|
||||
builder.AddPass(new ExprObfusPass());
|
||||
}
|
||||
if (obfuscationPasses.HasFlag(ObfuscationPassType.SymbolObfuscation))
|
||||
{
|
||||
builder.AddPass(new SymbolObfusPass(settings.symbolObfusSettings));
|
||||
}
|
||||
builder.AddPass(new CleanUpInstructionPass());
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue