public sealed class RuntimeService{ModuleDef? _rtModule;public TypeDef GetRuntimeType(string fullName) { _rtModule ?? LoadSelfModule(); // 首次调用懒加载 return _rtModule.Find(fullName, true) ?? throw new InvalidOperationException( $Runtime type {fullName} not found); } static ModuleDef LoadSelfModule() { var asm typeof(RuntimeService).Assembly; return ModuleDefMD.Load(asm.Location, new ModuleCreationOptions { TryToLoadPdbFromDisk false }); }}使用示例var runtime context.Runtime; // 从 ProtectionContext 获取var constantType runtime.GetRuntimeType(“TWSoft.Runtime.Constant”);var clonedConstant InjectHelper.Inject(constantType, context.Module); // 克隆6. 完整注入流程示例以字符串加密为例完整注入流程// Step 1: 获取运行时类型模板var constantType context.Runtime.GetRuntimeType(“TWSoft.Runtime.Constant”);// Step 2: 深度克隆到目标模块var clonedType InjectHelper.Inject(constantType, context.Module);// Step 3: 替换占位符为真实值var initMethod clonedType.FindMethod(“Initialize”);MutationHelper.InjectKey(initMethod, 0, bufferLength); // KeyI0 → 真实长度MutationHelper.InjectKey(initMethod, 1, seed); // KeyI1 → 真实种子MutationHelper.ReplacePlaceholder(initMethod, args // Placeholder → 数组初始化 ILCreateArrayInitInstructions(args));// Step 4: 重命名注入成员为不可见 Unicodeforeach (var method in clonedType.Methods)method.Name GenerateInvisibleName(random);// Step 5: 标记不可被混淆MarkAsNotRenameable(clonedType);// Step 6: 插入 .cctor 初始化调用InsertCctorCall(context.Module, clonedType, “Initialize”);7. 结语InjectHelper MutationHelper RuntimeService 构成了整个保护引擎的基础设施。所有运行时类型Constant、MethodGuard、VirtualMachine、AntiTamper、AntiDebug、AntiDump、ResourceEncryptor都通过这条管道交付给目标程序集——零外部依赖、完全自包含。