/// <inheritdoc /> protected internal override MarkerResult MarkProject(ConfuserProject proj, ConfuserContext context) { crossModuleAttrs = new Dictionary<string, Dictionary<Regex, List<ObfuscationAttributeInfo>>>(); 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) { extModules.Add(module.LoadRaw(proj.BaseDirectory)); continue; } ModuleDefMD modDef = module.Resolve(proj.BaseDirectory, context.Resolver.DefaultModuleContext); context.CheckCancellation(); 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); 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); }
public void ParsePackerString(string str, out Packer packer, out Dictionary<string, string> packerParams) { packer = null; packerParams = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); if (str == null) return; this.str = str; index = 0; var state = ParseState.ReadItemName; var buffer = new StringBuilder(); var ret = new ProtectionSettings(); while (state != ParseState.End) { switch (state) { case ParseState.ReadItemName: ReadId(buffer); packer = (Packer)items[buffer.ToString()]; buffer.Length = 0; if (IsEnd() || Peek() == ';') state = ParseState.EndItem; else if (Peek() == '(') { Next(); state = ParseState.ReadParam; } else throw new ArgumentException("Unexpected character in ReadItemName state at " + index + "."); break; case ParseState.ReadParam: string paramName, paramValue; if (!ReadId(buffer)) throw new ArgumentException("Unexpected end of string in ReadParam state."); paramName = buffer.ToString(); buffer.Length = 0; Expect('='); if (!ReadId(buffer)) throw new ArgumentException("Unexpected end of string in ReadParam state."); paramValue = buffer.ToString(); buffer.Length = 0; packerParams.Add(paramName, paramValue); if (Peek() == ',') { Next(); state = ParseState.ReadParam; } else if (Peek() == ')') { Next(); state = ParseState.EndItem; } else throw new ArgumentException("Unexpected character in ReadParam state at " + index + "."); break; case ParseState.EndItem: if (IsEnd()) state = ParseState.End; else { Expect(';'); if (!IsEnd()) throw new ArgumentException("Unexpected character in EndItem state at " + index + "."); state = ParseState.End; } break; } } }
/// <summary> /// Initializes a new instance of the <see cref="MarkerResult" /> class. /// </summary> /// <param name="modules">The modules.</param> /// <param name="packer">The packer.</param> public MarkerResult(IList<ModuleDefMD> modules, Packer packer) { Modules = modules; Packer = packer; }
/// <summary> /// Initializes a new instance of the <see cref="MarkerResult" /> class. /// </summary> /// <param name="modules">The modules.</param> /// <param name="packer">The packer.</param> /// <param name="extModules">The external modules.</param> public MarkerResult(IList<ModuleDefMD> modules, Packer packer, IList<byte[]> extModules) { Modules = modules; Packer = packer; ExternalModules = 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 (ISDnlibDef 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)); }
/// <summary> /// Initializes a new instance of the <see cref="MarkerResult" /> class. /// </summary> /// <param name="modules">The modules.</param> /// <param name="packer">The packer.</param> public MarkerResult(IList <ModuleDefMD> modules, Packer packer) { Modules = modules; Packer = packer; }
/// <summary> /// Initializes a new instance of the <see cref="MarkerResult" /> class. /// </summary> /// <param name="modules">The modules.</param> /// <param name="packer">The packer.</param> /// <param name="extModules">The external modules.</param> public MarkerResult(IList <ModuleDefMD> modules, Packer packer, IList <byte[]> extModules) { Modules = modules; Packer = packer; ExternalModules = extModules; }
public void ParsePackerString(string str, out Packer packer, out Dictionary <string, string> packerParams) { packer = null; packerParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (str == null) { return; } this.str = str; index = 0; var state = ParseState.ReadItemName; var buffer = new StringBuilder(); var ret = new ProtectionSettings(); while (state != ParseState.End) { switch (state) { case ParseState.ReadItemName: ReadId(buffer); var packerId = buffer.ToString(); if (!items.Contains(packerId)) { throw new KeyNotFoundException("Cannot find packer with id '" + packerId + "'."); } packer = (Packer)items[packerId]; buffer.Length = 0; if (IsEnd() || Peek() == ';') { state = ParseState.EndItem; } else if (Peek() == '(') { Next(); state = ParseState.ReadParam; } else { throw new ArgumentException("Unexpected character in ReadItemName state at " + index + "."); } break; case ParseState.ReadParam: string paramName, paramValue; if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } paramName = buffer.ToString(); buffer.Length = 0; Expect('='); if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } paramValue = buffer.ToString(); buffer.Length = 0; packerParams.Add(paramName, paramValue); if (Peek() == ',') { Next(); state = ParseState.ReadParam; } else if (Peek() == ')') { Next(); state = ParseState.EndItem; } else { throw new ArgumentException("Unexpected character in ReadParam state at " + index + "."); } break; case ParseState.EndItem: if (IsEnd()) { state = ParseState.End; } else { Expect(';'); if (!IsEnd()) { throw new ArgumentException("Unexpected character in EndItem state at " + index + "."); } state = ParseState.End; } break; } } }