Ejemplo n.º 1
0
        public virtual void WriteAssemblyAttributes(AssemblyDefinition assembly, ICollection <string> attributesToIgnore = null)
        {
            List <ICustomAttribute> assemblyAttributes = new List <ICustomAttribute>();

            securityAttributeToDeclaration = new Dictionary <SecurityAttribute, SecurityDeclaration>();

            CustomAttribute assemblyVersionAttribute = AttributesUtilities.GetAssemblyVersionAttribute(assembly);

            assemblyAttributes.Add(assemblyVersionAttribute);

            foreach (CustomAttribute attribute in assembly.CustomAttributes)
            {
                attribute.Resolve();
                assemblyAttributes.Add(attribute);
            }

            if (assembly.HasSecurityDeclarations)
            {
                foreach (SecurityDeclaration declaration in assembly.SecurityDeclarations)
                {
                    assemblyAttributes.AddRange(GetSecurityDeclaration(declaration));
                }
            }

            if (assembly.MainModule.HasExportedTypes)
            {
                foreach (ExportedType exportedType in assembly.MainModule.ExportedTypes)
                {
                    if (!(exportedType.Scope is ModuleReference))
                    {
                        assemblyAttributes.Add(AttributesUtilities.GetExportedTypeAttribute(exportedType, assembly.MainModule));
                    }
                }
            }

            assemblyAttributes.Sort((x, y) => CompareAttributes(x, y));

            foreach (ICustomAttribute attr in assemblyAttributes)
            {
                if (attributesToIgnore != null)
                {
                    if (attributesToIgnore.Contains(attr.AttributeType.FullName))
                    {
                        continue;
                    }
                }
                if (attr is CustomAttribute)
                {
                    WriteAssemblyAttribute(attr as CustomAttribute);
                }
                else if (attr is SecurityAttribute)
                {
                    bool b;
                    WriteSecurityAttribute(assembly.MainModule, true, attr as SecurityAttribute, securityAttributeToDeclaration[attr as SecurityAttribute], out b);
                }
            }

            //if (writeUsings)
            //{
            //    genericWriter.WriteUsings();
            //}

            //WriteModuleAttributes(assembly.MainModule, analysisData, attributesToIgnore);
        }
Ejemplo n.º 2
0
 public virtual void WriteAssemblyAttributes(AssemblyDefinition assembly, ICollection <string> attributesToIgnore = null)
 {
     V_0 = new List <ICustomAttribute>();
     this.securityAttributeToDeclaration = new Dictionary <SecurityAttribute, SecurityDeclaration>();
     V_0.Add(AttributesUtilities.GetAssemblyVersionAttribute(assembly));
     V_2 = assembly.get_CustomAttributes().GetEnumerator();
     try
     {
         while (V_2.MoveNext())
         {
             V_3 = V_2.get_Current();
             V_3.Resolve();
             V_0.Add(V_3);
         }
     }
     finally
     {
         V_2.Dispose();
     }
     if (assembly.get_HasSecurityDeclarations())
     {
         V_4 = assembly.get_SecurityDeclarations().GetEnumerator();
         try
         {
             while (V_4.MoveNext())
             {
                 V_5 = V_4.get_Current();
                 V_0.AddRange(this.GetSecurityDeclaration(V_5));
             }
         }
         finally
         {
             V_4.Dispose();
         }
     }
     if (assembly.get_MainModule().get_HasExportedTypes())
     {
         V_6 = assembly.get_MainModule().get_ExportedTypes().GetEnumerator();
         try
         {
             while (V_6.MoveNext())
             {
                 V_7 = V_6.get_Current();
                 if (V_7.get_Scope() as ModuleReference != null)
                 {
                     continue;
                 }
                 V_0.Add(AttributesUtilities.GetExportedTypeAttribute(V_7, assembly.get_MainModule()));
             }
         }
         finally
         {
             V_6.Dispose();
         }
     }
     V_0.Sort(new Comparison <ICustomAttribute>(this.u003cWriteAssemblyAttributesu003eb__18_0));
     V_8 = V_0.GetEnumerator();
     try
     {
         while (V_8.MoveNext())
         {
             V_9 = V_8.get_Current();
             if (attributesToIgnore != null && attributesToIgnore.Contains(V_9.get_AttributeType().get_FullName()))
             {
                 continue;
             }
             if (V_9 as CustomAttribute == null)
             {
                 if (V_9 as SecurityAttribute == null)
                 {
                     continue;
                 }
                 dummyVar0 = this.WriteSecurityAttribute(assembly.get_MainModule(), true, V_9 as SecurityAttribute, this.securityAttributeToDeclaration.get_Item(V_9 as SecurityAttribute), out V_10, false, false);
             }
             else
             {
                 this.WriteAssemblyAttribute(V_9 as CustomAttribute);
             }
         }
     }
     finally
     {
         ((IDisposable)V_8).Dispose();
     }
     return;
 }