blob: dd5d69b1fb0228c1ca2efb715f28dba6ef6bf83a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
namespace System.Reflection.Metadata
{
public static class AssemblyExtensions
{
[DllImport(JitHelpers.QCall)]
[SecurityCritical] // unsafe method
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
private unsafe static extern bool InternalTryGetRawMetadata(RuntimeAssembly assembly, ref byte* blob, ref int length);
// Retrieves the metadata section of the assembly, for use with System.Reflection.Metadata.MetadataReader.
// - Returns false upon failure. Metadata might not be available for some assemblies, such as AssemblyBuilder, .NET
// native images, etc.
// - Callers should not write to the metadata blob
// - The metadata blob pointer will remain valid as long as the AssemblyLoadContext with which the assembly is
// associated, is alive. The caller is responsible for keeping the assembly object alive while accessing the
// metadata blob.
[CLSCompliant(false)] // out byte* blob
[SecurityCritical] // unsafe method
public unsafe static bool TryGetRawMetadata(this Assembly assembly, out byte* blob, out int length)
{
if (assembly == null)
{
throw new ArgumentNullException("assembly");
}
blob = null;
length = 0;
var runtimeAssembly = assembly as RuntimeAssembly;
if (runtimeAssembly == null)
{
return false;
}
return InternalTryGetRawMetadata(runtimeAssembly, ref blob, ref length);
}
}
}
|