2014-07-19 58 views
0

我想从我的部件上卸下ObfuscationExclude属性:Mono.Cecil能删除自定义属性

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; 
       } 
      } 
     } 
    } 
} 
+0

非常感谢!这样可行! :) –