/// <summary> /// Fills the protection settings with the specified preset. /// </summary> /// <param name="preset">The preset.</param> /// <param name="settings">The settings.</param> void FillPreset(ProtectionPreset preset, ProtectionSettings settings) { foreach (Protection prot in protections.Values) { if (prot.Preset <= preset && !settings.ContainsKey(prot)) { settings.Add(prot, new Dictionary <string, string>()); } } }
public void ParseProtectionString(ProtectionSettings settings, string str) { if (str == null) { return; } this.str = str; index = 0; var state = ParseState.Init; var buffer = new StringBuilder(); bool protAct = true; string protId = null; var protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); while (state != ParseState.End) { switch (state) { case ParseState.Init: ReadId(buffer); if (buffer.ToString().Equals("preset", StringComparison.OrdinalIgnoreCase)) { if (IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } Expect('('); buffer.Length = 0; state = ParseState.ReadPreset; } else if (buffer.Length == 0) { if (IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } state = ParseState.ReadItemName; } else { protAct = true; state = ParseState.ProcessItemName; } break; case ParseState.ReadPreset: if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadPreset state."); } Expect(')'); var preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), buffer.ToString(), true); foreach (var item in items.Values.OfType <Protection>().Where(prot => prot.Preset <= preset)) { if (!settings.ContainsKey(item)) { settings.Add(item, new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)); } } buffer.Length = 0; if (IsEnd()) { state = ParseState.End; } else { Expect(';'); if (IsEnd()) { state = ParseState.End; } else { state = ParseState.ReadItemName; } } break; case ParseState.ReadItemName: protAct = true; if (Peek() == '+') { protAct = true; Next(); } else if (Peek() == '-') { protAct = false; Next(); } ReadId(buffer); state = ParseState.ProcessItemName; break; case ParseState.ProcessItemName: protId = buffer.ToString(); buffer.Length = 0; if (IsEnd() || Peek() == ';') { state = ParseState.EndItem; } else if (Peek() == '(') { if (!protAct) { throw new ArgumentException("No parameters is allowed when removing protection."); } Next(); state = ParseState.ReadParam; } else { throw new ArgumentException("Unexpected character in ProcessItemName 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; protParams.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 (protAct) { settings[(Protection)items[protId]] = protParams; protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); } else { settings.Remove((Protection)items[protId]); } if (IsEnd()) { state = ParseState.End; } else { Expect(';'); if (IsEnd()) { state = ParseState.End; } else { state = ParseState.ReadItemName; } } break; } } }
// Token: 0x060001CE RID: 462 RVA: 0x0000EFA0 File Offset: 0x0000D1A0 public void ParseProtectionString(ProtectionSettings settings, string str) { if (str == null) { return; } this.str = str; this.index = 0; ObfAttrParser.ParseState state = ObfAttrParser.ParseState.Init; StringBuilder buffer = new StringBuilder(); bool protAct = true; string protId = null; Dictionary <string, string> protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); while (state != ObfAttrParser.ParseState.End) { switch (state) { case ObfAttrParser.ParseState.Init: this.ReadId(buffer); if (buffer.ToString().Equals("preset", StringComparison.OrdinalIgnoreCase)) { if (this.IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } this.Expect('('); buffer.Length = 0; state = ObfAttrParser.ParseState.ReadPreset; } else if (buffer.Length == 0) { if (this.IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } state = ObfAttrParser.ParseState.ReadItemName; } else { protAct = true; state = ObfAttrParser.ParseState.ProcessItemName; } break; case ObfAttrParser.ParseState.ReadPreset: { if (!this.ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadPreset state."); } this.Expect(')'); ProtectionPreset preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), buffer.ToString(), true); foreach (Protection item in from prot in this.items.Values.OfType <Protection>() where prot.Preset <= preset select prot) { if (settings != null && !settings.ContainsKey(item)) { settings.Add(item, new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)); } } buffer.Length = 0; if (this.IsEnd()) { state = ObfAttrParser.ParseState.End; } else { this.Expect(';'); if (this.IsEnd()) { state = ObfAttrParser.ParseState.End; } else { state = ObfAttrParser.ParseState.ReadItemName; } } break; } case ObfAttrParser.ParseState.ReadItemName: protAct = true; if (this.Peek() == '+') { protAct = true; this.Next(); } else if (this.Peek() == '-') { protAct = false; this.Next(); } this.ReadId(buffer); state = ObfAttrParser.ParseState.ProcessItemName; break; case ObfAttrParser.ParseState.ProcessItemName: protId = buffer.ToString(); buffer.Length = 0; if (this.IsEnd() || this.Peek() == ';') { state = ObfAttrParser.ParseState.EndItem; } else { if (this.Peek() != '(') { throw new ArgumentException("Unexpected character in ProcessItemName state at " + this.index + "."); } if (!protAct) { throw new ArgumentException("No parameters is allowed when removing protection."); } this.Next(); state = ObfAttrParser.ParseState.ReadParam; } break; case ObfAttrParser.ParseState.ReadParam: { if (!this.ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } string paramName = buffer.ToString(); buffer.Length = 0; this.Expect('='); if (!((this.Peek() == '\'') ? this.ReadString(buffer) : this.ReadId(buffer))) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } string paramValue = buffer.ToString(); buffer.Length = 0; protParams.Add(paramName, paramValue); if (this.Peek() == ',') { this.Next(); state = ObfAttrParser.ParseState.ReadParam; } else { if (this.Peek() != ')') { throw new ArgumentException("Unexpected character in ReadParam state at " + this.index + "."); } this.Next(); state = ObfAttrParser.ParseState.EndItem; } break; } case ObfAttrParser.ParseState.EndItem: if (settings != null) { if (!this.items.Contains(protId)) { throw new KeyNotFoundException("Cannot find protection with id '" + protId + "'."); } if (protAct) { settings[(Protection)this.items[protId]] = protParams; } else { settings.Remove((Protection)this.items[protId]); } } protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (this.IsEnd()) { state = ObfAttrParser.ParseState.End; } else { this.Expect(';'); if (this.IsEnd()) { state = ObfAttrParser.ParseState.End; } else { state = ObfAttrParser.ParseState.ReadItemName; } } break; } } }