2014-07-19 57 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

非常感謝!這樣可行! :) –