Esempio n. 1
0
 /// <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>());
         }
     }
 }
Esempio n. 2
0
		/// <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 != ProtectionPreset.None && prot.Preset <= preset && !settings.ContainsKey(prot))
					settings.Add(prot, new Dictionary<string, string>());
		}
Esempio n. 3
0
 /// <summary>
 /// Initialize this rule instance
 /// </summary>
 /// <param name="pattern">The pattern</param>
 /// <param name="preset">The preset</param>
 /// <param name="inherit">Inherits protection</param>
 public Rule(string pattern = "true", ProtectionPreset preset = ProtectionPreset.None, bool inherit = false)
 {
     Pattern = pattern;
     Preset  = preset;
     Inherit = inherit;
 }
Esempio n. 4
0
        // 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;
                }
            }
        }