Example #1
0
 public ObfuscationSettings(ObfuscationSettings settings)
 {
     foreach (var i in settings)
     {
         Add(i.Key, new NameValueCollection(i.Value));
     }
 }
Example #2
0
        internal void MarkHelperAssembly(AssemblyDefinition asm, ObfuscationSettings settings, Confuser cr)
        {
            AssemblySetting ret = new AssemblySetting(asm);

            ret.GlobalParameters = new ObfuscationSettings(settings);

            ret.Modules = asm.Modules.Select(_ => new ModuleSetting(_)
            {
                Parameters = new ObfuscationSettings()
            }).ToArray();
            foreach (var mod in asm.Modules)
            {
                if (mod.GetType("<Module>").GetStaticConstructor() == null)
                {
                    MethodDefinition cctor = new MethodDefinition(".cctor", MethodAttributes.Private | MethodAttributes.HideBySig |
                                                                  MethodAttributes.SpecialName | MethodAttributes.RTSpecialName |
                                                                  MethodAttributes.Static, mod.TypeSystem.Void);
                    cctor.Body = new MethodBody(cctor);
                    cctor.Body.GetILProcessor().Emit(OpCodes.Ret);
                    mod.GetType("<Module>").Methods.Add(cctor);
                }
            }

            cr.settings.Add(ret);
        }
Example #3
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;
                }
            }
        }
Example #4
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());
         }
     }
 }
Example #5
0
        protected void AddHelperAssembly(AssemblyDefinition asm)
        {
            ObfuscationSettings setting = new ObfuscationSettings((cr.settings.Cast <AssemblySetting?>().SingleOrDefault(_ => _.Value.IsMain) ?? cr.settings[0]).GlobalParameters);

            setting.Remove(Confusion);
            cr.param.Marker.MarkHelperAssembly(asm, setting, cr);
            foreach (Analyzer analyzer in cr.analyzers)
            {
                analyzer.Analyze(new AssemblyDefinition[] { asm });
            }
        }
Example #6
0
 public void SkipLevel()
 {
     if (inheritStack.Count > 1)
     {
         CurrentConfusions = new ObfuscationSettings(inheritStack.ToArray()[inheritStack.Count - 2]);
     }
     else
     {
         CurrentConfusions = new ObfuscationSettings();
     }
     inheritStack.Push(CurrentConfusions);
 }
Example #7
0
 public void StartLevel()
 {
     if (inheritStack.Count > 0)
     {
         CurrentConfusions = new ObfuscationSettings(inheritStack.Peek());
     }
     else
     {
         CurrentConfusions = new ObfuscationSettings();
     }
     inheritStack.Push(CurrentConfusions);
 }
Example #8
0
 public ObfuscationSettings(ObfuscationSettings settings) : base(settings)
 {
 }
Example #9
0
 public void LeaveLevel()
 {
     inheritStack.Pop();
     CurrentConfusions = inheritStack.Peek();
 }
Example #10
0
 public Marking()
 {
     inheritStack      = new ObfuscationSettings[0x10];
     count             = 0;
     CurrentConfusions = new ObfuscationSettings();
 }