示例#1
0
 /// <summary>
 /// Reads custom attribute named arguments
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error
 /// occurred.</returns>
 internal static List <CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs, GenericParamContext gpContext)
 {
     try {
         using (var reader = new CustomAttributeReader(module, stream, false, gpContext))
             return(reader.ReadNamedArguments(numNamedArgs));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
示例#2
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext)
 {
     if (stream == null || ctor == null)
     {
         return(null);
     }
     try {
         using (var reader = new CustomAttributeReader(module, stream, gpContext))
             return(reader.Read(ctor));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
示例#3
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IImageStream stream, ICustomAttributeType ctor)
 {
     if (stream == null || ctor == null)
     {
         return(null);
     }
     try {
         using (var reader = new CustomAttributeReader(module, stream, ctor))
             return(reader.Read());
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
示例#4
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext)
 {
     using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) {
         try {
             if (ctor == null)
             {
                 return(reader.CreateRaw(ctor));
             }
             return(reader.Read(ctor));
         }
         catch (CABlobParserException) {
             return(reader.CreateRaw(ctor));
         }
         catch (IOException) {
             return(reader.CreateRaw(ctor));
         }
     }
 }
示例#5
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset)
 {
     if (ctor == null)
     {
         return(CreateEmpty(ctor));
     }
     using (var reader = new CustomAttributeReader(readerModule, ctor, offset)) {
         try {
             return(reader.Read());
         }
         catch (CABlobParserException) {
             return(new CustomAttribute(ctor, reader.GetRawBlob()));
         }
         catch (IOException) {
             return(new CustomAttribute(ctor, reader.GetRawBlob()));
         }
     }
 }
        /// <summary>
        ///     Reads the new (.NET 2.0+) DeclSecurity blob format
        /// </summary>
        /// <returns></returns>
        private ThreadSafe.IList <SecurityAttribute> ReadBinaryFormat()
        {
            var numAttrs = (int)reader.ReadCompressedUInt32();
            var list     = ThreadSafeListCreator.Create <SecurityAttribute>(numAttrs);

            for (var i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                // Use CA search rules. Some tools don't write the fully qualified name.
                var attrRef      = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(name), new CAAssemblyRefFinder(module), gpContext);
                var blobLength   = (int)reader.ReadCompressedUInt32();
                var numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = CustomAttributeReader.ReadNamedArguments(module, reader, numNamedArgs, gpContext);
                if (namedArgs == null)
                {
                    throw new ApplicationException("Could not read named arguments");
                }
                list.Add(new SecurityAttribute(attrRef, namedArgs));
            }

            return(list);
        }
示例#7
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset)
 {
     if (ctor == null)
         return CreateEmpty(ctor);
     using (var reader = new CustomAttributeReader(readerModule, offset)) {
         try {
             return reader.Read(ctor);
         }
         catch (CABlobParserException) {
             return new CustomAttribute(ctor, reader.GetRawBlob());
         }
         catch (IOException) {
             return new CustomAttribute(ctor, reader.GetRawBlob());
         }
     }
 }
示例#8
0
 /// <summary>
 /// Reads custom attribute named arguments
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param>
 /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error
 /// occurred.</returns>
 internal static List<CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs)
 {
     try {
         using (var reader = new CustomAttributeReader(module, stream, false))
             return reader.ReadNamedArguments(numNamedArgs);
     }
     catch (CABlobParserException) {
         return null;
     }
     catch (IOException) {
         return null;
     }
 }
示例#9
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor)
 {
     if (stream == null || ctor == null)
         return null;
     try {
         using (var reader = new CustomAttributeReader(module, stream))
             return reader.Read(ctor);
     }
     catch (CABlobParserException) {
         return null;
     }
     catch (IOException) {
         return null;
     }
 }
示例#10
0
		/// <summary>
		/// Reads a custom attribute
		/// </summary>
		/// <param name="module">Owner module</param>
		/// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext) {
			using (var reader = new CustomAttributeReader(module, stream, gpContext)) {
				try {
					if (stream == null || ctor == null)
						return reader.CreateRaw(ctor);
					return reader.Read(ctor);
				}
				catch (CABlobParserException) {
					return reader.CreateRaw(ctor);
				}
				catch (IOException) {
					return reader.CreateRaw(ctor);
				}
			}
		}
示例#11
0
		/// <summary>
		/// Reads a custom attribute
		/// </summary>
		/// <param name="readerModule">Reader module</param>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="offset">Offset of custom attribute in the #Blob stream</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext) {
			using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) {
				try {
					if (ctor == null)
						return reader.CreateRaw(ctor);
					return reader.Read(ctor);
				}
				catch (CABlobParserException) {
					return reader.CreateRaw(ctor);
				}
				catch (IOException) {
					return reader.CreateRaw(ctor);
				}
			}
		}