Exemple #1
0
 private void AddTypeSigReference(TypeSig typeSig, INameReference <IDnlibDef> reference)
 {
     foreach (var type in typeSig.FindTypeRefs())
     {
         var typeDef = type.ResolveTypeDefThrow();
         if (Context.Modules.Contains((ModuleDefMD)typeDef.Module))
         {
             NameService.ReduceRenameMode(typeDef, RenameMode.Letters);
             if (type is TypeRef)
             {
                 NameService.AddReference(typeDef, new TypeRefReference((TypeRef)type, typeDef));
             }
             NameService.AddReference(typeDef, reference);
         }
     }
 }
        void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, TypeDef type)
        {
            if (IsVisibleOutside(context, parameters, type)) {
                service.SetCanRename(type, false);
            }
            else if (type.IsRuntimeSpecialName || type.IsGlobalModuleType) {
                service.SetCanRename(type, false);
            }
            else if (type.FullName == "ConfusedByAttribute") {
                // Courtesy
                service.SetCanRename(type, false);
            }

            if (parameters.GetParameter(context, type, "forceRen", false))
                return;

            if (type.InheritsFromCorlib("System.Attribute")) {
                service.ReduceRenameMode(type, RenameMode.ASCII);
            }

            if (type.InheritsFrom("System.Configuration.SettingsBase")) {
                service.SetCanRename(type, false);
            }
        }
Exemple #3
0
        private void Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, TypeDef type)
        {
            if (type.IsVisibleOutside() && !parameters.GetParameter<bool>(context, type, "renPublic", false)) {
                service.SetCanRename(type, false);
            }
            else if (type.IsRuntimeSpecialName || type.IsSpecialName) {
                service.SetCanRename(type, false);
            }
            else if (type.FullName == "ConfusedByAttribute") {
                // Courtesy
                service.SetCanRename(type, false);
            }

            if (parameters.GetParameter<bool>(context, type, "forceRen", false))
                return;

            if (type.InheritsFromCorlib("System.Attribute")) {
                service.ReduceRenameMode(type, RenameMode.ASCII);
            }
        }
Exemple #4
0
        private void ProcessConverter(PropertyWithConverterRecord rec, TypeDef type)
        {
            var converter = ResolveType(rec.ConverterTypeId);

            if (converter.FullName == "System.ComponentModel.EnumConverter")
            {
                if (type != null && Context.Modules.Contains((ModuleDefMD)type.Module))
                {
                    var enumField = type.FindField(rec.Value);
                    if (enumField != null)
                    {
                        NameService.AddReference(enumField, new BAMLEnumReference(enumField, rec));
                    }
                }
            }
            else if (converter.FullName == "System.Windows.Input.CommandConverter")
            {
                var cmd   = rec.Value.Trim();
                var index = cmd.IndexOf('.');
                if (index != -1)
                {
                    var    typeName = cmd.Substring(0, index);
                    string prefix;
                    var    sig = ResolveType(typeName, out prefix);
                    if (sig != null)
                    {
                        var cmdName = cmd.Substring(index + 1);

                        var typeDef = sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow();
                        if (Context.Modules.Contains((ModuleDefMD)typeDef.Module))
                        {
                            var property = typeDef.FindProperty(cmdName);
                            if (property != null)
                            {
                                var reference = new BAMLConverterMemberReference(xmlnsCtx, sig, property, rec);
                                AddTypeSigReference(sig, reference);
                                NameService.ReduceRenameMode(property, RenameMode.Letters);
                                NameService.AddReference(property, reference);
                            }
                            var field = typeDef.FindField(cmdName);
                            if (field != null)
                            {
                                var reference = new BAMLConverterMemberReference(xmlnsCtx, sig, field, rec);
                                AddTypeSigReference(sig, reference);
                                NameService.ReduceRenameMode(field, RenameMode.Letters);
                                NameService.AddReference(field, reference);
                            }
                            if (property == null && field == null)
                            {
                                Context.Logger.WarnFormat("Could not resolve command '{0}' in '{1}'.", cmd, CurrentBAMLName);
                            }
                        }
                    }
                }
            }
            else if (converter.FullName == "System.Windows.Markup.DependencyPropertyConverter")
            {
                // Umm... Again nothing to do, DP already won't be renamed.
            }
            else if (converter.FullName == "System.Windows.PropertyPathConverter")
            {
                AnalyzePropertyPath(rec.Value);
            }
            else if (converter.FullName == "System.Windows.Markup.RoutedEventConverter")
            {
                ;
            }
            else if (converter.FullName == "System.Windows.Markup.TypeTypeConverter")
            {
                string prefix;
                var    sig = ResolveType(rec.Value.Trim(), out prefix);
                if (sig != null && Context.Modules.Contains((ModuleDefMD)sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module))
                {
                    var reference = new BAMLConverterTypeReference(xmlnsCtx, sig, rec);
                    AddTypeSigReference(sig, reference);
                }
            }

            var    attrInfo = ResolveAttribute(rec.AttributeId);
            string attrName = null;

            if (attrInfo.Item1 != null)
            {
                attrName = attrInfo.Item1.Name;
            }
            else if (attrInfo.Item2 != null)
            {
                attrName = attrInfo.Item2.Name;
            }

            if (attrName == "DisplayMemberPath")
            {
                AnalyzePropertyPath(rec.Value);
            }
            else if (attrName == "Source")
            {
                string declType = null;
                if (attrInfo.Item1 is IMemberDef)
                {
                    declType = ((IMemberDef)attrInfo.Item1).DeclaringType.FullName;
                }
                else if (attrInfo.Item2 != null)
                {
                    declType = ResolveType(attrInfo.Item2.OwnerTypeId).FullName;
                }
                if (declType == "System.Windows.ResourceDictionary")
                {
                    var src = rec.Value.ToUpperInvariant();
                    if (src.EndsWith(".BAML") || src.EndsWith(".XAML"))
                    {
                        var match = WPFAnalyzer.UriPattern.Match(src);
                        if (match.Success)
                        {
                            src = match.Groups[1].Value;
                        }
                        else if (rec.Value.Contains("/"))
                        {
                            Context.Logger.WarnFormat("Fail to extract XAML name from '{0}'.", rec.Value);
                        }

                        if (!src.Contains("//"))
                        {
                            var rel = new Uri(new Uri(packScheme + "application:,,,/" + CurrentBAMLName), src);
                            src = rel.LocalPath;
                        }
                        var reference = new BAMLPropertyReference(rec);
                        src = src.TrimStart('/');
                        var baml     = src.Substring(0, src.Length - 5) + ".BAML";
                        var xaml     = src.Substring(0, src.Length - 5) + ".XAML";
                        var bamlRefs = NameService.FindRenamer <WPFAnalyzer>().bamlRefs;
                        bamlRefs.AddListEntry(baml, reference);
                        bamlRefs.AddListEntry(xaml, reference);
                        bamlRefs.AddListEntry(Uri.EscapeUriString(baml), reference);
                        bamlRefs.AddListEntry(Uri.EscapeUriString(xaml), reference);
                    }
                }
            }
        }