void ReadSecurityBlob(BlobReader reader, IAttribute[] attributes, ITypeResolveContext context, ResolveResult securityActionRR)
        {
            for (int i = 0; i < attributes.Length; i++)
            {
                string         attributeTypeName = reader.ReadSerString();
                ITypeReference attributeTypeRef  = ReflectionHelper.ParseReflectionName(attributeTypeName);
                IType          attributeType     = attributeTypeRef.Resolve(context);

                reader.ReadCompressedUInt32();                 // ??
                // The specification seems to be incorrect here, so I'm using the logic from Cecil instead.
                uint numNamed = reader.ReadCompressedUInt32();

                var namedArgs = new List <KeyValuePair <IMember, ResolveResult> >((int)numNamed);
                for (uint j = 0; j < numNamed; j++)
                {
                    var namedArg = reader.ReadNamedArg(attributeType);
                    if (namedArg.Key != null)
                    {
                        namedArgs.Add(namedArg);
                    }
                }
                attributes[i] = new DefaultAttribute(
                    attributeType,
                    positionalArguments: new ResolveResult[] { securityActionRR },
                    namedArguments: namedArgs);
            }
        }
        public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob)
        {
            BlobReader reader = new BlobReader(blob, null);

            this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction);
            this.blob           = blob;
            if (reader.ReadByte() == '.')
            {
                // binary attribute
                uint attributeCount = reader.ReadCompressedUInt32();
                for (uint i = 0; i < attributeCount; i++)
                {
                    unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i));
                }
            }
            else
            {
                // for backward compatibility with .NET 1.0: XML-encoded attribute
                var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference);
                attr.ConstructorParameterTypes.Add(securityActionTypeReference);
                attr.PositionalArguments.Add(this.securityAction);
                string xml = System.Text.Encoding.Unicode.GetString(blob);
                attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml));
                unresolvedAttributes.Add(attr);
            }
        }
		public IList<IAttribute> Resolve(IAssembly currentAssembly)
		{
			// TODO: make this a per-assembly cache
//				CacheManager cache = currentAssembly.Compilation.CacheManager;
//				IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
//				if (result != null)
//					return result;
			
			ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
			BlobReader reader = new BlobReader(blob, currentAssembly);
			if (reader.ReadByte() != '.') {
				// should not use UnresolvedSecurityDeclaration for XML secdecls
				throw new InvalidOperationException();
			}
			ResolveResult securityActionRR = securityAction.Resolve(context);
			uint attributeCount = reader.ReadCompressedUInt32();
			IAttribute[] attributes = new IAttribute[attributeCount];
			try {
				ReadSecurityBlob(reader, attributes, context, securityActionRR);
			} catch (NotSupportedException) {
				// ignore invalid blobs
				//Debug.WriteLine(ex.ToString());
			}
			for (int i = 0; i < attributes.Length; i++) {
				if (attributes[i] == null)
					attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
			}
			return attributes;
//				return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
		}
		public UnresolvedSecurityDeclarationBlob(int securityAction, byte[] blob)
		{
			BlobReader reader = new BlobReader(blob, null);
			this.securityAction = new SimpleConstantValue(securityActionTypeReference, securityAction);
			this.blob = blob;
			if (reader.ReadByte() == '.') {
				// binary attribute
				uint attributeCount = reader.ReadCompressedUInt32();
				for (uint i = 0; i < attributeCount; i++) {
					unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i));
				}
			} else {
				// for backward compatibility with .NET 1.0: XML-encoded attribute
				var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference);
				attr.ConstructorParameterTypes.Add(securityActionTypeReference);
				attr.PositionalArguments.Add(this.securityAction);
				string xml = System.Text.Encoding.Unicode.GetString(blob);
				attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml));
				unresolvedAttributes.Add(attr);
			}
		}
Exemple #5
0
        public IList <IAttribute> Resolve(IAssembly currentAssembly)
        {
            // TODO: make this a per-assembly cache
            //				CacheManager cache = currentAssembly.Compilation.CacheManager;
            //				IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
            //				if (result != null)
            //					return result;

            ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
            BlobReader          reader  = new BlobReader(blob, currentAssembly);

            if (reader.ReadByte() != '.')
            {
                // should not use UnresolvedSecurityDeclaration for XML secdecls
                throw new InvalidOperationException();
            }
            ResolveResult securityActionRR = securityAction.Resolve(context);
            uint          attributeCount   = reader.ReadCompressedUInt32();

            IAttribute[] attributes = new IAttribute[attributeCount];
            try
            {
                ReadSecurityBlob(reader, attributes, context, securityActionRR);
            }
            catch (NotSupportedException ex)
            {
                // ignore invalid blobs
                Debug.WriteLine(ex.ToString());
            }
            for (int i = 0; i < attributes.Length; i++)
            {
                if (attributes[i] == null)
                {
                    attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
                }
            }
            return(attributes);
            //				return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
        }
Exemple #6
0
            void ReadSecurityBlob(BlobReader reader, IAttribute[] attributes, ITypeResolveContext context, ResolveResult securityActionRR)
            {
                for (int i = 0; i < attributes.Length; i++) {
                    string attributeTypeName = reader.ReadSerString();
                    ITypeReference attributeTypeRef = ReflectionHelper.ParseReflectionName(attributeTypeName);
                    IType attributeType = attributeTypeRef.Resolve(context);

                    reader.ReadCompressedUInt32(); // ??
                    // The specification seems to be incorrect here, so I'm using the logic from Cecil instead.
                    uint numNamed = reader.ReadCompressedUInt32();

                    var namedArgs = new List<KeyValuePair<IMember, ResolveResult>>((int)numNamed);
                    for (uint j = 0; j < numNamed; j++) {
                        var namedArg = reader.ReadNamedArg(attributeType);
                        if (namedArg.Key != null)
                            namedArgs.Add(namedArg);

                    }
                    attributes[i] = new DefaultAttribute(
                        attributeType,
                        positionalArguments: new ResolveResult[] { securityActionRR },
                    namedArguments: namedArgs);
                }
            }