backup
parent
d14d0f913c
commit
dafa1ddb32
|
@ -136,9 +136,9 @@ namespace Obfuz.Data
|
|||
return _random.NextInt();
|
||||
}
|
||||
|
||||
private DefaultModuleMetadataImporter GetModuleMetadataImporter()
|
||||
private DefaultMetadataImporter GetModuleMetadataImporter()
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetDefaultModuleMetadataImporter(_module);
|
||||
return GroupByModuleEntityManager.Ins.GetDefaultModuleMetadataImporter(_module);
|
||||
}
|
||||
|
||||
private void CreateCCtorOfRvaTypeDef(TypeDef type)
|
||||
|
@ -157,7 +157,7 @@ namespace Obfuz.Data
|
|||
//Assert.IsNotNull(method);
|
||||
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter();
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter();
|
||||
// TODO. obfuscate init codes
|
||||
foreach (var field in type.Fields)
|
||||
{
|
||||
|
@ -268,7 +268,7 @@ namespace Obfuz.Data
|
|||
|
||||
private ModuleConstFieldAllocator GetModuleAllocator(ModuleDef mod)
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetEntity<ModuleConstFieldAllocator>(mod, () => new ModuleConstFieldAllocator(_encryptor, _random, _rvaDataAllocator));
|
||||
return GroupByModuleEntityManager.Ins.GetEntity<ModuleConstFieldAllocator>(mod, () => new ModuleConstFieldAllocator(_encryptor, _random, _rvaDataAllocator));
|
||||
}
|
||||
|
||||
public FieldDef Allocate(ModuleDef mod, int value)
|
||||
|
@ -303,7 +303,7 @@ namespace Obfuz.Data
|
|||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var moduleAllocator in GroupByModuleManager.Ins.GetEntities<ModuleConstFieldAllocator>())
|
||||
foreach (var moduleAllocator in GroupByModuleEntityManager.Ins.GetEntities<ModuleConstFieldAllocator>())
|
||||
{
|
||||
moduleAllocator.Done();
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ namespace Obfuz.Data
|
|||
cctorMethod.Body = body;
|
||||
var ins = body.Instructions;
|
||||
|
||||
DefaultModuleMetadataImporter importer = GroupByModuleManager.Ins.GetDefaultModuleMetadataImporter(mod);
|
||||
DefaultMetadataImporter importer = GroupByModuleEntityManager.Ins.GetDefaultModuleMetadataImporter(mod);
|
||||
foreach (var field in _rvaFields)
|
||||
{
|
||||
// ldc
|
||||
|
@ -296,7 +296,7 @@ namespace Obfuz.Data
|
|||
|
||||
private ModuleRvaDataAllocator GetModuleRvaDataAllocator(ModuleDef mod)
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetEntity<ModuleRvaDataAllocator>(mod, () => new ModuleRvaDataAllocator(_random, _encryptor));
|
||||
return GroupByModuleEntityManager.Ins.GetEntity<ModuleRvaDataAllocator>(mod, () => new ModuleRvaDataAllocator(_random, _encryptor));
|
||||
}
|
||||
|
||||
public RvaData Allocate(ModuleDef mod, int value)
|
||||
|
@ -331,7 +331,7 @@ namespace Obfuz.Data
|
|||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var allocator in GroupByModuleManager.Ins.GetEntities<ModuleRvaDataAllocator>())
|
||||
foreach (var allocator in GroupByModuleEntityManager.Ins.GetEntities<ModuleRvaDataAllocator>())
|
||||
{
|
||||
allocator.Done();
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ using UnityEngine.Assertions;
|
|||
|
||||
namespace Obfuz.Emit
|
||||
{
|
||||
public class DefaultModuleMetadataImporter : GroupByModuleEntityBase
|
||||
public class DefaultMetadataImporter : GroupByModuleEntityBase
|
||||
{
|
||||
public DefaultModuleMetadataImporter() { }
|
||||
public DefaultMetadataImporter() { }
|
||||
|
||||
public override void Init(ModuleDef mod)
|
||||
{
|
|
@ -17,16 +17,16 @@ namespace Obfuz.Emit
|
|||
public abstract void Init(ModuleDef mod);
|
||||
}
|
||||
|
||||
public class GroupByModuleManager
|
||||
public class GroupByModuleEntityManager
|
||||
{
|
||||
public static GroupByModuleManager Ins { get; private set; }
|
||||
public static GroupByModuleEntityManager Ins { get; private set; }
|
||||
|
||||
|
||||
private readonly Dictionary<(ModuleDef, Type), IGroupByModuleEntity> _moduleEmitManagers = new Dictionary<(ModuleDef, Type), IGroupByModuleEntity>();
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
Ins = new GroupByModuleManager();
|
||||
Ins = new GroupByModuleEntityManager();
|
||||
}
|
||||
|
||||
public T GetEntity<T>(ModuleDef mod, Func<T> creator = null) where T : IGroupByModuleEntity
|
||||
|
@ -66,9 +66,9 @@ namespace Obfuz.Emit
|
|||
return managers;
|
||||
}
|
||||
|
||||
public DefaultModuleMetadataImporter GetDefaultModuleMetadataImporter(ModuleDef module)
|
||||
public DefaultMetadataImporter GetDefaultModuleMetadataImporter(ModuleDef module)
|
||||
{
|
||||
return GetEntity<DefaultModuleMetadataImporter>(module);
|
||||
return GetEntity<DefaultMetadataImporter>(module);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,73 +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 IModuleMetadataImporter
|
||||
// {
|
||||
// void Init(ModuleDef mod);
|
||||
// }
|
||||
|
||||
// public abstract class ModuleMetadataImporterBase : IModuleMetadataImporter
|
||||
// {
|
||||
// public abstract void Init(ModuleDef mod);
|
||||
// }
|
||||
|
||||
// public class MetadataImporter
|
||||
// {
|
||||
// private readonly Dictionary<(ModuleDef, Type), IModuleMetadataImporter> _customModuleMetadataImporters = new Dictionary<(ModuleDef, Type), IModuleMetadataImporter>();
|
||||
|
||||
// public static MetadataImporter Instance { get; private set; }
|
||||
|
||||
// public static void Reset()
|
||||
// {
|
||||
// Instance = new MetadataImporter();
|
||||
// }
|
||||
|
||||
// public DefaultModuleMetadataImporter GetDefaultModuleMetadataImporter(ModuleDef module)
|
||||
// {
|
||||
// return GetCustomModuleMetadataImporter<DefaultModuleMetadataImporter>(module);
|
||||
// }
|
||||
|
||||
// public List<DefaultModuleMetadataImporter> GetDefaultModuleMetadataImporters()
|
||||
// {
|
||||
// return GetCustomModuleMetadataImporters<DefaultModuleMetadataImporter>();
|
||||
// }
|
||||
|
||||
// public T GetCustomModuleMetadataImporter<T>(ModuleDef module, Func<ModuleDef, T> creator = null) where T : IModuleMetadataImporter
|
||||
// {
|
||||
// var key = (module, typeof(T));
|
||||
// if (!_customModuleMetadataImporters.TryGetValue(key, out var importer))
|
||||
// {
|
||||
// if (creator != null)
|
||||
// {
|
||||
// importer = creator(module);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// importer = (IModuleMetadataImporter)Activator.CreateInstance(typeof(T));
|
||||
// }
|
||||
// importer.Init(module);
|
||||
// _customModuleMetadataImporters[key] = importer;
|
||||
// }
|
||||
// return (T)importer;
|
||||
// }
|
||||
|
||||
// public List<T> GetCustomModuleMetadataImporters<T>()
|
||||
// {
|
||||
// var result = new List<T>();
|
||||
// foreach (var kvp in _customModuleMetadataImporters)
|
||||
// {
|
||||
// if (kvp.Key.Item2 == typeof(T))
|
||||
// {
|
||||
// result.Add((T)kvp.Value);
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
// }
|
||||
//}
|
|
@ -249,7 +249,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
private ModuleCallProxyAllocator GetModuleAllocator(ModuleDef mod)
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_random, _encryptor));
|
||||
return GroupByModuleEntityManager.Ins.GetEntity<ModuleCallProxyAllocator>(mod, () => new ModuleCallProxyAllocator(_random, _encryptor));
|
||||
}
|
||||
|
||||
public ProxyCallMethodData Allocate(ModuleDef mod, IMethod method, bool callVir)
|
||||
|
@ -260,7 +260,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
public void Done()
|
||||
{
|
||||
foreach (var allocator in GroupByModuleManager.Ins.GetEntities<ModuleCallProxyAllocator>())
|
||||
foreach (var allocator in GroupByModuleEntityManager.Ins.GetEntities<ModuleCallProxyAllocator>())
|
||||
{
|
||||
allocator.Done();
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace Obfuz.ObfusPasses.CallObfus
|
|||
|
||||
MethodSig sharedMethodSig = MetaUtil.ToSharedMethodSig(calledMethod.Module.CorLibTypes, MetaUtil.GetInflatedMethodSig(calledMethod));
|
||||
ProxyCallMethodData proxyCallMethodData = _proxyCallAllocator.Allocate(callerMethod.Module, calledMethod, callVir);
|
||||
DefaultModuleMetadataImporter importer = GroupByModuleManager.Ins.GetDefaultModuleMetadataImporter(callerMethod.Module);
|
||||
DefaultMetadataImporter importer = GroupByModuleEntityManager.Ins.GetDefaultModuleMetadataImporter(callerMethod.Module);
|
||||
|
||||
if (needCacheCall)
|
||||
{
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
return _random.NextInt();
|
||||
}
|
||||
|
||||
private DefaultModuleMetadataImporter GetModuleMetadataImporter(MethodDef method)
|
||||
private DefaultMetadataImporter GetModuleMetadataImporter(MethodDef method)
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetDefaultModuleMetadataImporter(method.Module);
|
||||
return GroupByModuleEntityManager.Ins.GetDefaultModuleMetadataImporter(method.Module);
|
||||
}
|
||||
|
||||
public void ObfuscateInt(MethodDef method, bool needCacheValue, int value, List<Instruction> obfuscatedInstructions)
|
||||
|
@ -54,7 +54,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
int encryptedValue = _encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
@ -76,7 +76,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
long encryptedValue = _encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
@ -98,7 +98,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
float encryptedValue = _encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
@ -120,7 +120,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
double encryptedValue = _encryptor.Encrypt(value, ops, salt);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(ops));
|
||||
|
@ -143,7 +143,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
Assert.IsTrue(encryptedValue.Length % 4 == 0);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
// should use value.Length, can't use rvaData.size, because rvaData.size is align to 4, it's not the actual length.
|
||||
|
@ -169,7 +169,7 @@ namespace Obfuz.ObfusPasses.ConstEncrypt
|
|||
Assert.IsTrue(encryptedValue.Length % 4 == 0);
|
||||
RvaData rvaData = _rvaDataAllocator.Allocate(method.Module, encryptedValue);
|
||||
|
||||
DefaultModuleMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetModuleMetadataImporter(method);
|
||||
obfuscatedInstructions.Add(Instruction.Create(OpCodes.Ldsfld, rvaData.field));
|
||||
obfuscatedInstructions.Add(Instruction.CreateLdcI4(rvaData.offset));
|
||||
// should use stringByteLength, can't use rvaData.size, because rvaData.size is align to 4, it's not the actual length.
|
||||
|
|
|
@ -21,9 +21,9 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
_encryptor = encryptor;
|
||||
}
|
||||
|
||||
private DefaultModuleMetadataImporter GetMetadataImporter(MethodDef method)
|
||||
private DefaultMetadataImporter GetMetadataImporter(MethodDef method)
|
||||
{
|
||||
return GroupByModuleManager.Ins.GetDefaultModuleMetadataImporter(method.Module);
|
||||
return GroupByModuleEntityManager.Ins.GetDefaultModuleMetadataImporter(method.Module);
|
||||
}
|
||||
|
||||
class FieldEncryptInfo
|
||||
|
@ -79,7 +79,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
|
||||
public override void Encrypt(MethodDef method, FieldDef field, List<Instruction> outputInstructions, Instruction currentInstruction)
|
||||
{
|
||||
DefaultModuleMetadataImporter importer = GetMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetMetadataImporter(method);
|
||||
FieldEncryptInfo fei = GetFieldEncryptInfo(field);
|
||||
if (fei.fieldType == ElementType.I4 || fei.fieldType == ElementType.U4 || fei.fieldType == ElementType.R4)
|
||||
{
|
||||
|
@ -116,7 +116,7 @@ namespace Obfuz.ObfusPasses.FieldEncrypt
|
|||
public override void Decrypt(MethodDef method, FieldDef field, List<Instruction> outputInstructions, Instruction currentInstruction)
|
||||
{
|
||||
outputInstructions.Add(currentInstruction.Clone());
|
||||
DefaultModuleMetadataImporter importer = GetMetadataImporter(method);
|
||||
DefaultMetadataImporter importer = GetMetadataImporter(method);
|
||||
FieldEncryptInfo fei = GetFieldEncryptInfo(field);
|
||||
if (fei.fieldType == ElementType.I4 || fei.fieldType == ElementType.U4 || fei.fieldType == ElementType.R4)
|
||||
{
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Obfuz
|
|||
_notObfuscatedAssemblyNamesReferencingObfuscated = notObfuscatedAssemblyNamesReferencingObfuscated;
|
||||
_obfuscatedAssemblyOutputDir = obfuscatedAssemblyOutputDir;
|
||||
|
||||
GroupByModuleManager.Reset();
|
||||
GroupByModuleEntityManager.Reset();
|
||||
_assemblyCache = new AssemblyCache(new PathAssemblyResolver(assemblySearchDirs.ToArray()));
|
||||
foreach (var pass in obfuscationPasses)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue