Ejemplo n.º 1
0
 /// <summary>
 /// Clones a collection of SecurityDeclarations
 /// </summary>
 public void CopySecurityDeclarations(Collection <SecurityDeclaration> input, Collection <SecurityDeclaration> output, IGenericParameterProvider context)
 {
     foreach (SecurityDeclaration sec in input)
     {
         SecurityDeclaration newSec = null;
         if (PermissionsetHelper.IsXmlPermissionSet(sec))
         {
             newSec = PermissionsetHelper.Xml2PermissionSet(sec, _repackContext.TargetAssemblyMainModule);
         }
         if (newSec == null)
         {
             newSec = new SecurityDeclaration(sec.Action);
             foreach (SecurityAttribute sa in sec.SecurityAttributes)
             {
                 SecurityAttribute newSa = new SecurityAttribute(Import(sa.AttributeType, context));
                 if (sa.HasFields)
                 {
                     foreach (CustomAttributeNamedArgument cana in sa.Fields)
                     {
                         newSa.Fields.Add(Copy(cana, context));
                     }
                 }
                 if (sa.HasProperties)
                 {
                     foreach (CustomAttributeNamedArgument cana in sa.Properties)
                     {
                         newSa.Properties.Add(Copy(cana, context));
                     }
                 }
                 newSec.SecurityAttributes.Add(newSa);
             }
         }
         output.Add(newSec);
     }
 }
Ejemplo n.º 2
0
 internal void FixReferences(Collection <SecurityDeclaration> securitydeclarations, IGenericParameterProvider context)
 {
     if (securitydeclarations.Count > 0)
     {
         foreach (SecurityDeclaration sd in securitydeclarations)
         {
             foreach (SecurityAttribute sa in sd.SecurityAttributes)
             {
                 sa.AttributeType = Fix(sa.AttributeType, context);
                 FixReferences(sa.Fields, context);
                 if (sa.HasFields)
                 {
                     throw new NotSupportedException();
                 }
                 FixReferences(sa.Properties, context);
                 if (sa.HasProperties)
                 {
                     foreach (var prop in sa.Properties.ToArray())
                     {
                         if (prop.Name == "PublicKeyBlob")
                         {
                             if (repack.TargetAssemblyDefinition.Name.HasPublicKey)
                             {
                                 if (targetAssemblyPublicKeyBlobString == null)
                                 {
                                     foreach (byte b in repack.TargetAssemblyDefinition.Name.PublicKey)
                                     {
                                         targetAssemblyPublicKeyBlobString += b.ToString("X").PadLeft(2, '0');
                                     }
                                 }
                                 if (prop.Argument.Type.FullName != "System.String")
                                 {
                                     throw new NotSupportedException("Invalid type of argument, expected string");
                                 }
                                 CustomAttributeNamedArgument newProp = new CustomAttributeNamedArgument(prop.Name,
                                                                                                         new CustomAttributeArgument(prop.Argument.Type, targetAssemblyPublicKeyBlobString));
                                 sa.Properties.Remove(prop);
                                 sa.Properties.Add(newProp);
                             }
                             else
                             {
                                 repack.WARN("SecurityPermission with PublicKeyBlob found but target has no strong name!");
                             }
                         }
                     }
                 }
             }
         }
         if ((repack.TargetAssemblyMainModule.Runtime == TargetRuntime.Net_1_0) || (repack.TargetAssemblyMainModule.Runtime == TargetRuntime.Net_1_1))
         {
             SecurityDeclaration[] sdArray = securitydeclarations.ToArray();
             securitydeclarations.Clear();
             foreach (SecurityDeclaration sd in sdArray)
             {
                 securitydeclarations.Add(PermissionsetHelper.Permission2XmlSet(sd, repack.TargetAssemblyMainModule));
             }
         }
     }
 }