示例#1
0
        void Analyze(NameService service, DotProtectContext context, ProtectionParameters parameters, MethodDef method)
        {
            if (IsVisibleOutside(context, parameters, method.DeclaringType) &&
                (method.IsFamily || method.IsFamilyOrAssembly || method.IsPublic) &&
                IsVisibleOutside(context, parameters, method))
            {
                service.SetCanRename(method, false);
            }

            else if (method.IsRuntimeSpecialName)
            {
                service.SetCanRename(method, false);
            }

            else if (parameters.GetParameter(context, method, "forceRen", false))
            {
                return;
            }

            else if (method.DeclaringType.IsComImport() && !method.HasAttribute("System.Runtime.InteropServices.DispIdAttribute"))
            {
                service.SetCanRename(method, false);
            }

            else if (method.DeclaringType.IsDelegate())
            {
                service.SetCanRename(method, false);
            }
        }
示例#2
0
        void Analyze(NameService service, DotProtectContext context, ProtectionParameters parameters, FieldDef field)
        {
            if (IsVisibleOutside(context, parameters, field.DeclaringType) &&
                (field.IsFamily || field.IsFamilyOrAssembly || field.IsPublic) &&
                IsVisibleOutside(context, parameters, field))
            {
                service.SetCanRename(field, false);
            }

            else if (field.IsRuntimeSpecialName)
            {
                service.SetCanRename(field, false);
            }

            else if (parameters.GetParameter(context, field, "forceRen", false))
            {
                return;
            }

            /*
             * System.Xml.Serialization.XmlSerializer
             *
             * XmlSerializer by default serializes fields marked with [NonSerialized]
             * This is a work-around that causes all fields in a class marked [Serializable]
             * to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
             *
             * If we have a way to detect which serializer method the code is going to use
             * for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
             * we'll have a more accurate way to achieve this.
             */
            else if (field.DeclaringType.IsSerializable)             // && !field.IsNotSerialized)
            {
                service.SetCanRename(field, false);
            }

            else if (field.DeclaringType.IsSerializable && (field.CustomAttributes.IsDefined("XmlIgnore") ||
                                                            field.CustomAttributes.IsDefined("XmlIgnoreAttribute") ||
                                                            field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore") ||
                                                            field.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute") ||
                                                            field.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute")))                                                        // Can't seem to detect CustomAttribute
            {
                service.SetCanRename(field, true);
            }

            /*
             * End of XmlSerializer work-around
             */

            else if (field.IsLiteral && field.DeclaringType.IsEnum &&
                     !parameters.GetParameter(context, field, "renEnum", false))
            {
                service.SetCanRename(field, false);
            }
        }
示例#3
0
        void Analyze(NameService service, DotProtectContext context, ProtectionParameters parameters, EventDef evt)
        {
            if (IsVisibleOutside(context, parameters, evt.DeclaringType) &&
                IsVisibleOutside(context, parameters, evt))
            {
                service.SetCanRename(evt, false);
            }

            else if (evt.IsRuntimeSpecialName)
            {
                service.SetCanRename(evt, false);
            }
        }
示例#4
0
        void Analyze(NameService service, DotProtectContext context, ProtectionParameters parameters, PropertyDef property)
        {
            if (IsVisibleOutside(context, parameters, property.DeclaringType) &&
                IsVisibleOutside(context, parameters, property))
            {
                service.SetCanRename(property, false);
            }

            else if (property.IsRuntimeSpecialName)
            {
                service.SetCanRename(property, false);
            }

            else if (parameters.GetParameter(context, property, "forceRen", false))
            {
                return;
            }

            /*
             * System.Xml.Serialization.XmlSerializer
             *
             * XmlSerializer by default serializes fields marked with [NonSerialized]
             * This is a work-around that causes all fields in a class marked [Serializable]
             * to _not_ be renamed, unless marked with [XmlIgnoreAttribute]
             *
             * If we have a way to detect which serializer method the code is going to use
             * for the class, or if Microsoft makes XmlSerializer respond to [NonSerialized]
             * we'll have a more accurate way to achieve this.
             */
            else if (property.DeclaringType.IsSerializable) // && !field.IsNotSerialized)
            {
                service.SetCanRename(property, false);
            }

            else if (property.DeclaringType.IsSerializable && (property.CustomAttributes.IsDefined("XmlIgnore") ||
                                                               property.CustomAttributes.IsDefined("XmlIgnoreAttribute") ||
                                                               property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnore") ||
                                                               property.CustomAttributes.IsDefined("System.Xml.Serialization.XmlIgnoreAttribute") ||
                                                               property.CustomAttributes.IsDefined("T:System.Xml.Serialization.XmlIgnoreAttribute"))) // Can't seem to detect CustomAttribute
            {
                service.SetCanRename(property, true);
            }

            /*
             * End of XmlSerializer work-around
             */

            else if (property.DeclaringType.Implements("System.ComponentModel.INotifyPropertyChanged"))
            {
                service.SetCanRename(property, false);
            }

            else if (property.DeclaringType.Name.String.Contains("AnonymousType"))
            {
                service.SetCanRename(property, false);
            }
        }
示例#5
0
        internal void Analyze(NameService service, DotProtectContext context, ProtectionParameters parameters, IDnlibDef def, bool runAnalyzer)
        {
            if (def is TypeDef)
            {
                Analyze(service, context, parameters, (TypeDef)def);
            }
            else if (def is MethodDef)
            {
                Analyze(service, context, parameters, (MethodDef)def);
            }
            else if (def is FieldDef)
            {
                Analyze(service, context, parameters, (FieldDef)def);
            }
            else if (def is PropertyDef)
            {
                Analyze(service, context, parameters, (PropertyDef)def);
            }
            else if (def is EventDef)
            {
                Analyze(service, context, parameters, (EventDef)def);
            }
            else if (def is ModuleDef)
            {
                var pass = parameters.GetParameter <string>(context, def, "password", null);
                if (pass != null)
                {
                    service.reversibleRenamer = new ReversibleRenamer(pass);
                }

                var idOffset = parameters.GetParameter <uint>(context, def, "idOffset", 0);
                if (idOffset != 0)
                {
                    service.SetNameId(idOffset);
                }

                service.SetCanRename(def, false);
            }

            if (!runAnalyzer || parameters.GetParameter(context, def, "forceRen", false))
            {
                return;
            }

            foreach (IRenamer renamer in service.Renamers)
            {
                renamer.Analyze(context, service, parameters, def);
            }
        }
示例#6
0
        void Analyze(NameService service, DotProtectContext 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);
            }

            /*
             * Can't rename Classes/Types that will be serialized
             */
            if (type != null)
            {
                if (type.IsSerializable)
                {
                    service.SetCanRename(type, false);
                }

                if (type.DeclaringType != null)
                {
                    if (type.DeclaringType.IsSerializable)
                    {
                        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);
            }
        }