Mono.Cecil删除自定义属性

时间:2014-07-19 11:59:55

标签: c# attributes obfuscation mono.cecil

我想从程序集中删除ObfuscationExclude属性:

enter image description here

我的尝试:

enter image description here

但我不知道我怎么做到这一点,有人可以帮助我吗?

  public static void CleanCustomAttributes(AssemblyDefinition asmdef)
    {
        foreach(ModuleDefinition  ModuleDef in asmdef.Modules )
      {
            foreach(TypeDefinition TypeDef in ModuleDef.Types )
            {
               foreach(CustomAttribute CustomAttrib in TypeDef.CustomAttributes )
               {
                  if (CustomAttrib.AttributeType = // ? )
                  {

                  }
               }
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

只需检查属性的全名并将其删除即可。

public static void CleanCustomAttributes(AssemblyDefinition asmdef)
{
    foreach (ModuleDefinition ModuleDef in asmdef.Modules)
    {
        foreach (TypeDefinition TypeDef in ModuleDef.Types)
        {
            foreach (CustomAttribute CustomAttrib in TypeDef.CustomAttributes)
            {
                if (CustomAttrib.AttributeType.FullName == "System.Reflection.ObfuscationAttribute")
                {
                    TypeDef.CustomAttributes.Remove(CustomAttrib);
                    break;
                }
            }
        }
    }
}