2025-05-03 23:23:16 +08:00
|
|
|
|
using dnlib.DotNet;
|
2025-05-10 11:25:07 +08:00
|
|
|
|
using Obfuz.Data;
|
2025-05-13 08:49:57 +08:00
|
|
|
|
using Obfuz.Emit;
|
2025-05-12 18:03:39 +08:00
|
|
|
|
using Obfuz.ObfusPasses;
|
2025-05-04 19:55:10 +08:00
|
|
|
|
using Obfuz.ObfusPasses.SymbolObfus;
|
2025-05-04 19:24:14 +08:00
|
|
|
|
using Obfuz.Utils;
|
2025-04-05 19:02:50 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2025-05-05 12:38:52 +08:00
|
|
|
|
namespace Obfuz
|
2025-04-05 19:02:50 +08:00
|
|
|
|
{
|
2025-05-13 09:27:44 +08:00
|
|
|
|
public delegate IRandom RandomCreator(int seed);
|
2025-04-05 19:02:50 +08:00
|
|
|
|
|
2025-05-16 11:33:03 +08:00
|
|
|
|
public class EncryptionScopeInfo
|
|
|
|
|
{
|
|
|
|
|
public readonly IEncryptor encryptor;
|
|
|
|
|
public readonly RandomCreator localRandomCreator;
|
|
|
|
|
|
2025-05-17 12:11:36 +08:00
|
|
|
|
public EncryptionScopeInfo(IEncryptor encryptor, RandomCreator localRandomCreator)
|
2025-05-16 11:33:03 +08:00
|
|
|
|
{
|
|
|
|
|
this.encryptor = encryptor;
|
|
|
|
|
this.localRandomCreator = localRandomCreator;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class EncryptionScopeProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly EncryptionScopeInfo _defaultStaticScope;
|
|
|
|
|
private readonly EncryptionScopeInfo _defaultDynamicScope;
|
|
|
|
|
private readonly HashSet<string> _dynamicSecretAssemblyNames;
|
|
|
|
|
|
|
|
|
|
public EncryptionScopeProvider(EncryptionScopeInfo defaultStaticScope, EncryptionScopeInfo defaultDynamicScope, HashSet<string> dynamicSecretAssemblyNames)
|
|
|
|
|
{
|
|
|
|
|
_defaultStaticScope = defaultStaticScope;
|
|
|
|
|
_defaultDynamicScope = defaultDynamicScope;
|
|
|
|
|
_dynamicSecretAssemblyNames = dynamicSecretAssemblyNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public EncryptionScopeInfo GetScope(ModuleDef module)
|
|
|
|
|
{
|
|
|
|
|
if (_dynamicSecretAssemblyNames.Contains(module.Assembly.Name))
|
|
|
|
|
{
|
|
|
|
|
return _defaultDynamicScope;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return _defaultStaticScope;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-16 12:33:37 +08:00
|
|
|
|
|
|
|
|
|
public bool IsDynamicSecretAssembly(ModuleDef module)
|
|
|
|
|
{
|
|
|
|
|
return _dynamicSecretAssemblyNames.Contains(module.Assembly.Name);
|
|
|
|
|
}
|
2025-05-16 11:33:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-05-04 19:24:14 +08:00
|
|
|
|
public class ObfuscationPassContext
|
2025-04-05 19:02:50 +08:00
|
|
|
|
{
|
2025-05-13 08:49:57 +08:00
|
|
|
|
public static ObfuscationPassContext Current { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GroupByModuleEntityManager moduleEntityManager;
|
|
|
|
|
|
2025-04-15 10:46:03 +08:00
|
|
|
|
public AssemblyCache assemblyCache;
|
|
|
|
|
|
2025-05-17 12:11:36 +08:00
|
|
|
|
public List<ModuleDef> modulesToObfuscate;
|
|
|
|
|
public List<ModuleDef> allObfuscationRelativeModules;
|
2025-04-05 21:47:28 +08:00
|
|
|
|
|
2025-05-17 12:11:36 +08:00
|
|
|
|
public List<string> assembliesToObfuscate;
|
|
|
|
|
public List<string> nonObfuscatedButReferencingObfuscatedAssemblies;
|
2025-04-16 23:03:41 +08:00
|
|
|
|
|
2025-05-17 12:11:36 +08:00
|
|
|
|
public string obfuscatedAssemblyOutputPath;
|
2025-05-10 11:25:07 +08:00
|
|
|
|
|
2025-05-16 11:33:03 +08:00
|
|
|
|
public EncryptionScopeProvider encryptionScopeProvider;
|
2025-05-10 11:25:07 +08:00
|
|
|
|
public ConstFieldAllocator constFieldAllocator;
|
|
|
|
|
public RvaDataAllocator rvaDataAllocator;
|
2025-05-17 12:11:36 +08:00
|
|
|
|
public ObfuscationMethodWhitelist whiteList;
|
2025-05-12 22:01:35 +08:00
|
|
|
|
public ConfigurablePassPolicy passPolicy;
|
2025-04-05 19:02:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|