/// <summary> /// Returns a body block of a method with specified Relative Virtual Address (RVA); /// </summary> /// <exception cref="ArgumentNullException"><paramref name="peReader"/> is null.</exception> /// <exception cref="BadImageFormatException">The body is not found in the metadata or is invalid.</exception> /// <exception cref="InvalidOperationException">Section where the method is stored is not available.</exception> /// <exception cref="IOException">IO error while reading from the underlying stream.</exception> public static MethodBodyBlock GetMethodBody(this PEReader peReader, int relativeVirtualAddress) { if (peReader is null) { Throw.ArgumentNull(nameof(peReader)); } var block = peReader.GetSectionData(relativeVirtualAddress); if (block.Length == 0) { throw new BadImageFormatException(SR.Format(SR.InvalidMethodRva, relativeVirtualAddress)); } // Call to validating public BlobReader constructor is by design -- we need to throw PlatformNotSupported on big-endian architecture. return(MethodBodyBlock.Create(block.GetReader())); }
/// <summary> /// Returns a body block of a method with specified Relative Virtual Address (RVA); /// </summary> /// <exception cref="ArgumentNullException"><paramref name="peReader"/> is null.</exception> /// <exception cref="BadImageFormatException">The body is not found in the metadata or is invalid.</exception> /// <exception cref="InvalidOperationException">Section where the method is stored is not available.</exception> public static unsafe MethodBodyBlock GetMethodBody(this PEReader peReader, int relativeVirtualAddress) { if (peReader == null) { throw new ArgumentNullException("peReader"); } var block = peReader.GetSectionData(relativeVirtualAddress); if (block.Length == 0) { throw new BadImageFormatException(string.Format(MetadataResources.InvalidMethodRva, relativeVirtualAddress)); } // Call to validating public BlobReader constructor is by design -- we need to throw PlatformNotSupported on big-endian architecture. var blobReader = new BlobReader(block.Pointer, block.Length); return(MethodBodyBlock.Create(blobReader)); }