示例#1
0
        private void ProcessConfig(string cfg, ObfuscationSettings cs)
        {
            MatchCollection matches = Regex.Matches(cfg, @"(\+|\-|)\[([^,\]]*)(?:,([^\]]*))?\]");

            foreach (Match match in matches)
            {
                string id = match.Groups[2].Value.ToLower();
                switch (match.Groups[1].Value)
                {
                case null:
                case "":
                case "+":
                    if (id == "preset")
                    {
                        FillPreset((Preset)Enum.Parse(typeof(Preset), match.Groups[3].Value, true), cs);
                    }
                    else if (id == "new")
                    {
                        cs.Clear();
                    }
                    else
                    {
                        if (!Confusions.ContainsKey(id))
                        {
                            cr.Log("Warning: Cannot find confusion id '" + id + "'.");
                            break;
                        }
                        IConfusion now = (from i in cs.Keys where i.ID == id select i).FirstOrDefault() ?? Confusions[id];
                        if (!cs.ContainsKey(now))
                        {
                            cs[now] = new NameValueCollection();
                        }
                        NameValueCollection nv = cs[now];
                        if (!string.IsNullOrEmpty(match.Groups[3].Value))
                        {
                            foreach (string param in match.Groups[3].Value.Split(','))
                            {
                                string[] p = param.Split('=');
                                if (p.Length == 1)
                                {
                                    nv[p[0].ToLower()] = "true";
                                }
                                else
                                {
                                    nv[p[0].ToLower()] = p[1];
                                }
                            }
                        }
                    }
                    break;

                case "-":
                    cs.Remove((from i in cs.Keys where i.ID == id select i).FirstOrDefault());
                    break;
                }
            }
        }
示例#2
0
 private void FillPreset(Preset preset, ObfuscationSettings cs)
 {
     foreach (IConfusion i in Confusions.Values)
     {
         if (i.Preset <= preset && !cs.ContainsKey(i))
         {
             cs.Add(i, new NameValueCollection());
         }
     }
 }