コード例 #1
0
        // Token: 0x060001B2 RID: 434 RVA: 0x0000DA78 File Offset: 0x0000BC78
        private static IEnumerable <ObfAttrMarker.ObfuscationAttributeInfo> ReadObfuscationAttributes(IHasCustomAttribute item)
        {
            List <ObfAttrMarker.ObfuscationAttributeInfo> ret = new List <ObfAttrMarker.ObfuscationAttributeInfo>();

            for (int i = item.CustomAttributes.Count - 1; i >= 0; i--)
            {
                CustomAttribute ca = item.CustomAttributes[i];
                if (!(ca.TypeFullName != "System.Reflection.ObfuscationAttribute"))
                {
                    ObfAttrMarker.ObfuscationAttributeInfo info = default(ObfAttrMarker.ObfuscationAttributeInfo);
                    bool strip = true;
                    foreach (CANamedArgument prop in ca.Properties)
                    {
                        string a;
                        if ((a = prop.Name) != null)
                        {
                            if (a == "ApplyToMembers")
                            {
                                info.ApplyToMembers = new bool?((bool)prop.Value);
                                continue;
                            }
                            if (a == "Exclude")
                            {
                                info.Exclude = new bool?((bool)prop.Value);
                                continue;
                            }
                            if (a == "StripAfterObfuscation")
                            {
                                strip = (bool)prop.Value;
                                continue;
                            }
                            if (a == "Feature")
                            {
                                string feature  = (UTF8String)prop.Value;
                                int    sepIndex = feature.IndexOf(':');
                                if (sepIndex == -1)
                                {
                                    info.FeatureName  = "";
                                    info.FeatureValue = feature;
                                    continue;
                                }
                                info.FeatureName  = feature.Substring(0, sepIndex);
                                info.FeatureValue = feature.Substring(sepIndex + 1);
                                continue;
                            }
                        }
                        throw new NotSupportedException("Unsupported property: " + prop.Name);
                    }
                    if (strip)
                    {
                        item.CustomAttributes.RemoveAt(i);
                    }
                    ret.Add(info);
                }
            }
            ret.Reverse();
            return(ret);
        }
コード例 #2
0
        // Token: 0x060001B7 RID: 439 RVA: 0x0000E3C4 File Offset: 0x0000C5C4
        private void MarkModule(ProjectModule projModule, ModuleDefMD module, Dictionary <Rule, PatternExpression> rules, bool isMain)
        {
            List <ObfAttrMarker.ObfuscationAttributeInfo> settingAttrs = new List <ObfAttrMarker.ObfuscationAttributeInfo>();
            string snKeyPath = projModule.SNKeyPath;
            string snKeyPass = projModule.SNKeyPassword;
            Dictionary <Regex, List <ObfAttrMarker.ObfuscationAttributeInfo> > namespaceAttrs;

            if (!this.crossModuleAttrs.TryGetValue(module.Name, out namespaceAttrs))
            {
                namespaceAttrs = new Dictionary <Regex, List <ObfAttrMarker.ObfuscationAttributeInfo> >();
            }
            foreach (ObfAttrMarker.ObfuscationAttributeInfo attr in ObfAttrMarker.ReadObfuscationAttributes(module.Assembly))
            {
                if (string.IsNullOrEmpty(attr.FeatureName))
                {
                    settingAttrs.Add(attr);
                }
                else if (attr.FeatureName.Equals("generate debug symbol", StringComparison.OrdinalIgnoreCase))
                {
                    if (!isMain)
                    {
                        throw new ArgumentException("Only main module can set 'generate debug symbol'.");
                    }
                    this.project.Debug = bool.Parse(attr.FeatureValue);
                }
                else if (attr.FeatureName.Equals("random seed", StringComparison.OrdinalIgnoreCase))
                {
                    if (!isMain)
                    {
                        throw new ArgumentException("Only main module can set 'random seed'.");
                    }
                    this.project.Seed = attr.FeatureValue;
                }
                else if (attr.FeatureName.Equals("strong name key", StringComparison.OrdinalIgnoreCase))
                {
                    snKeyPath = Path.Combine(this.project.BaseDirectory, attr.FeatureValue);
                }
                else if (attr.FeatureName.Equals("strong name key password", StringComparison.OrdinalIgnoreCase))
                {
                    snKeyPass = attr.FeatureValue;
                }
                else if (attr.FeatureName.Equals("packer", StringComparison.OrdinalIgnoreCase))
                {
                    if (!isMain)
                    {
                        throw new ArgumentException("Only main module can set 'packer'.");
                    }
                    new ObfAttrParser(this.packers).ParsePackerString(attr.FeatureValue, out this.packer, out this.packerParams);
                }
                else if (attr.FeatureName.Equals("external module", StringComparison.OrdinalIgnoreCase))
                {
                    if (!isMain)
                    {
                        throw new ArgumentException("Only main module can add external modules.");
                    }
                    byte[] rawModule = new ProjectModule
                    {
                        Path = attr.FeatureValue
                    }.LoadRaw(this.project.BaseDirectory);
                    this.extModules.Add(rawModule);
                }
                else
                {
                    Match match = ObfAttrMarker.NSInModulePattern.Match(attr.FeatureName);
                    if (match.Success)
                    {
                        if (!isMain)
                        {
                            throw new ArgumentException("Only main module can set cross module obfuscation.");
                        }
                        Regex  ns           = ObfAttrMarker.TranslateNamespaceRegex(match.Groups[1].Value);
                        string targetModule = match.Groups[2].Value;
                        ObfAttrMarker.ObfuscationAttributeInfo x = attr;
                        x.FeatureName = "";
                        Dictionary <Regex, List <ObfAttrMarker.ObfuscationAttributeInfo> > targetModuleAttrs;
                        if (!this.crossModuleAttrs.TryGetValue(targetModule, out targetModuleAttrs))
                        {
                            targetModuleAttrs = new Dictionary <Regex, List <ObfAttrMarker.ObfuscationAttributeInfo> >();
                            this.crossModuleAttrs[targetModule] = targetModuleAttrs;
                        }
                        targetModuleAttrs.AddListEntry(ns, x);
                    }
                    else
                    {
                        match = ObfAttrMarker.NSPattern.Match(attr.FeatureName);
                        if (match.Success)
                        {
                            Regex ns2 = ObfAttrMarker.TranslateNamespaceRegex(match.Groups[1].Value);
                            ObfAttrMarker.ObfuscationAttributeInfo x2 = attr;
                            x2.FeatureName = "";
                            namespaceAttrs.AddListEntry(ns2, x2);
                        }
                    }
                }
            }
            if (this.project.Debug)
            {
                module.LoadPdb();
            }
            this.ProcessModule(module, rules, snKeyPath, snKeyPass, settingAttrs, namespaceAttrs);
        }