예제 #1
0
        private bool ProcessAttribute(ICustomAttributeProvider provider, Marking setting)
        {
            CustomAttribute att = GetAttribute(provider.CustomAttributes, "ConfusingAttribute");

            if (att == null)
            {
                setting.StartLevel();
                return(false);
            }

            CustomAttributeNamedArgument stripArg = att.Properties.FirstOrDefault(arg => arg.Name == "StripAfterObfuscation");
            bool strip = true;

            if (!stripArg.Equals(default(CustomAttributeNamedArgument)))
            {
                strip = (bool)stripArg.Argument.Value;
            }

            if (strip)
            {
                provider.CustomAttributes.Remove(att);
            }

            CustomAttributeNamedArgument excludeArg = att.Properties.FirstOrDefault(arg => arg.Name == "Exclude");
            bool exclude = false;

            if (!excludeArg.Equals(default(CustomAttributeNamedArgument)))
            {
                exclude = (bool)excludeArg.Argument.Value;
            }

            if (exclude)
            {
                setting.CurrentConfusions.Clear();
            }

            CustomAttributeNamedArgument applyToMembersArg = att.Properties.FirstOrDefault(arg => arg.Name == "ApplyToMembers");
            bool applyToMembers = true;

            if (!applyToMembersArg.Equals(default(CustomAttributeNamedArgument)))
            {
                applyToMembers = (bool)applyToMembersArg.Argument.Value;
            }

            if (applyToMembers)
            {
                setting.StartLevel();
            }
            else
            {
                setting.SkipLevel();
            }
            try
            {
                if (!exclude)
                {
                    CustomAttributeNamedArgument featureArg = att.Properties.FirstOrDefault(arg => arg.Name == "Config");
                    string feature = "all";
                    if (!featureArg.Equals(default(CustomAttributeNamedArgument)))
                    {
                        feature = (string)featureArg.Argument.Value;
                    }

                    if (string.Equals(feature, "all", StringComparison.OrdinalIgnoreCase))
                    {
                        FillPreset(Preset.Maximum, setting.CurrentConfusions);
                    }
                    else if (string.Equals(feature, "default", StringComparison.OrdinalIgnoreCase))
                    {
                        FillPreset(Preset.Normal, setting.CurrentConfusions);
                    }
                    else
                    {
                        ProcessConfig(feature, setting.CurrentConfusions);
                    }
                }

                return(exclude && applyToMembers);
            }
            catch
            {
                cr.Log("Warning: Cannot process ConfusingAttribute at '" + provider.ToString() + "'. ConfusingAttribute ignored.");
                return(false);
            }
        }