void ApplySettings(IDnlibDef def, Rules rules, IEnumerable <ProtectionSettingsInfo> infos, ProtectionSettings settings = null) { if (settings == null) { settings = new ProtectionSettings(); } else { settings = new ProtectionSettings(settings); } ApplyRules(context, def, rules, settings); settings = ProtectionParameters.GetParameters(context, def); ProtectionSettingsInfo?last = null; var parser = new ObfAttrParser(protections); foreach (var info in infos) { if (info.Exclude) { if (info.ApplyToMember) { settings.Clear(); } continue; } last = info; if (info.ApplyToMember && !string.IsNullOrEmpty(info.Settings)) { parser.ParseProtectionString(settings, info.Settings); } } if (last != null && !last.Value.ApplyToMember && !string.IsNullOrEmpty(last.Value.Settings)) { parser.ParseProtectionString(settings, last.Value.Settings); } }
// Token: 0x060001B4 RID: 436 RVA: 0x0000E008 File Offset: 0x0000C208 private void ApplySettings(IDnlibDef def, Dictionary <Rule, PatternExpression> rules, IEnumerable <ObfAttrMarker.ProtectionSettingsInfo> infos, ProtectionSettings settings = null) { if (settings == null) { settings = new ProtectionSettings(); } else { settings = new ProtectionSettings(settings); } base.ApplyRules(this.context, def, rules, settings); settings = ProtectionParameters.GetParameters(this.context, def); ObfAttrMarker.ProtectionSettingsInfo?last = null; ObfAttrParser parser = new ObfAttrParser(this.protections); foreach (ObfAttrMarker.ProtectionSettingsInfo info in infos) { if (info.Exclude) { if (info.ApplyToMember) { settings.Clear(); } } else { last = new ObfAttrMarker.ProtectionSettingsInfo?(info); if (info.ApplyToMember && !string.IsNullOrEmpty(info.Settings)) { parser.ParseProtectionString(settings, info.Settings); } } } if (last.HasValue && !last.Value.ApplyToMember && !string.IsNullOrEmpty(last.Value.Settings)) { parser.ParseProtectionString(settings, last.Value.Settings); } }
/// <inheritdoc /> protected internal override MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) { this.context = context; project = proj; extModules = new List <byte[]>(); if (proj.Packer != null) { if (!packers.ContainsKey(proj.Packer.Id)) { context.Logger.ErrorFormat("Cannot find packer with ID '{0}'.", proj.Packer.Id); throw new ConfuserException(null); } packer = packers[proj.Packer.Id]; packerParams = new Dictionary <string, string>(proj.Packer, StringComparer.OrdinalIgnoreCase); } var modules = new List <Tuple <ProjectModule, ModuleDefMD> >(); foreach (ProjectModule module in proj) { if (module.IsExternal) { var rawModule = module.LoadRaw(proj.BaseDirectory); extModules.Add(rawModule); context.InternalResolver.AddToCache(ModuleDefMD.Load(rawModule, context.InternalResolver.DefaultModuleContext)); continue; } try { ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.InternalResolver.DefaultModuleContext); context.CheckCancellation(); context.InternalResolver.AddToCache(modDef); modules.Add(Tuple.Create(module, modDef)); } catch (BadImageFormatException ex) { context.Logger.ErrorFormat("Failed to load \"{0}\" - Assembly does not appear to be a .NET assembly: \"{1}\".", module.Path, ex.Message); throw new ConfuserException(ex); } } foreach (var module in modules) { context.Logger.InfoFormat("Loading '{0}'...", module.Item1.Path); Rules rules = ParseRules(proj, module.Item1, context); MarkModule(module.Item1, module.Item2, rules, module == modules[0]); context.Annotations.Set(module.Item2, RulesKey, rules); // Packer parameters are stored in modules if (packer != null) { ProtectionParameters.GetParameters(context, module.Item2)[packer] = packerParams; } } if (proj.Debug && proj.Packer != null) { context.Logger.Warn("Generated Debug symbols might not be usable with packers!"); } return(new MarkerResult(modules.Select(module => module.Item2).ToList(), packer, extModules)); }
/// <summary> /// Loads the assembly and marks the project. /// </summary> /// <param name="proj">The project.</param> /// <param name="context">The working context.</param> /// <returns><see cref="MarkerResult" /> storing the marked modules and packer information.</returns> protected internal virtual MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) { Packer packer = null; Dictionary <string, string> packerParams = null; if (proj.Packer != null) { if (!packers.ContainsKey(proj.Packer.Id)) { context.Logger.ErrorFormat("Cannot find packer with ID '{0}'.", proj.Packer.Id); throw new ConfuserException(null); } if (proj.Debug) { context.Logger.Warn("Generated Debug symbols might not be usable with packers!"); } packer = packers[proj.Packer.Id]; packerParams = new Dictionary <string, string>(proj.Packer, StringComparer.OrdinalIgnoreCase); } var modules = new List <Tuple <ProjectModule, ModuleDefMD> >(); var extModules = new List <byte[]>(); foreach (ProjectModule module in proj) { if (module.IsExternal) { extModules.Add(module.LoadRaw(proj.BaseDirectory)); continue; } ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext); context.CheckCancellation(); if (proj.Debug) { modDef.LoadPdb(); } context.Resolver.AddToCache(modDef); modules.Add(Tuple.Create(module, modDef)); } foreach (var module in modules) { context.Logger.InfoFormat("Loading '{0}'...", module.Item1.Path); Rules rules = ParseRules(proj, module.Item1, context); context.Annotations.Set(module.Item2, SNKey, LoadSNKey(context, module.Item1.SNKeyPath == null ? null : Path.Combine(proj.BaseDirectory, module.Item1.SNKeyPath), module.Item1.SNKeyPassword)); context.Annotations.Set(module.Item2, RulesKey, rules); foreach (IDnlibDef def in module.Item2.FindDefinitions()) { ApplyRules(context, def, rules); context.CheckCancellation(); } // Packer parameters are stored in modules if (packerParams != null) { ProtectionParameters.GetParameters(context, module.Item2)[packer] = packerParams; } } return(new MarkerResult(modules.Select(module => module.Item2).ToList(), packer, extModules)); }
/// <inheritdoc /> protected internal override void MarkMember(IDnlibDef member, ConfuserContext context) { ModuleDef module = ((IMemberRef)member).Module; ProtectionParameters.SetParameters(context, member, ProtectionParameters.GetParameters(context, module)); }
/// <summary> /// Loads the assembly and marks the project. /// </summary> /// <param name="proj">The project.</param> /// <param name="context">The working context.</param> /// <returns><see cref="T:Confuser.Core.MarkerResult" /> storing the marked modules and packer information.</returns> // Token: 0x06000193 RID: 403 RVA: 0x0000CFF0 File Offset: 0x0000B1F0 protected internal virtual MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) { Packer packer = null; Dictionary <string, string> packerParams = null; if (proj.Packer != null) { if (!this.packers.ContainsKey(proj.Packer.Id)) { context.Logger.ErrorFormat("Cannot find packer with ID '{0}'.", new object[] { proj.Packer.Id }); throw new ConfuserException(null); } if (proj.Debug) { context.Logger.Warn("Generated Debug symbols might not be usable with packers!"); } packer = this.packers[proj.Packer.Id]; packerParams = new Dictionary <string, string>(proj.Packer, StringComparer.OrdinalIgnoreCase); } List <Tuple <ProjectModule, ModuleDefMD> > modules = new List <Tuple <ProjectModule, ModuleDefMD> >(); List <byte[]> extModules = new List <byte[]>(); foreach (ProjectModule module3 in proj) { if (module3.IsExternal) { extModules.Add(module3.LoadRaw(proj.BaseDirectory)); } else { ModuleDefMD modDef = module3.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext); context.CheckCancellation(); if (proj.Debug) { modDef.LoadPdb(); } context.Resolver.AddToCache(modDef); modules.Add(Tuple.Create <ProjectModule, ModuleDefMD>(module3, modDef)); } } foreach (Tuple <ProjectModule, ModuleDefMD> module2 in modules) { context.Logger.InfoFormat("Loading '{0}'...", new object[] { module2.Item1.Path }); Dictionary <Rule, PatternExpression> rules = this.ParseRules(proj, module2.Item1, context); context.Annotations.Set <StrongNameKey>(module2.Item2, Marker.SNKey, Marker.LoadSNKey(context, (module2.Item1.SNKeyPath == null) ? null : Path.Combine(proj.BaseDirectory, module2.Item1.SNKeyPath), module2.Item1.SNKeyPassword)); context.Annotations.Set <Dictionary <Rule, PatternExpression> >(module2.Item2, Marker.RulesKey, rules); foreach (IDnlibDef def in module2.Item2.FindDefinitions()) { this.ApplyRules(context, def, rules, null); context.CheckCancellation(); } if (packerParams != null) { ProtectionParameters.GetParameters(context, module2.Item2)[packer] = packerParams; } } return(new MarkerResult((from module in modules select module.Item2).ToList <ModuleDefMD>(), packer, extModules)); }