-
Notifications
You must be signed in to change notification settings - Fork 19
/
EventSourceManifest.cs
84 lines (78 loc) · 2.64 KB
/
EventSourceManifest.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace EventSourceProxy
{
/// <summary>
/// Exposes ETW manifest information for provider types.
/// </summary>
public static class EventSourceManifest
{
#region Metadata Members
/// <summary>
/// Return the GUID of a provider name.
/// </summary>
/// <param name="providerName">The name of the provider.</param>
/// <returns>The GUID representing the name.</returns>
public static Guid GetGuidFromProviderName(string providerName)
{
if (providerName == null) throw new ArgumentNullException("providerName");
string name = providerName.ToUpperInvariant();
byte[] buffer = new byte[(name.Length * 2) + 0x10];
uint num = 0x482c2db2;
uint num2 = 0xc39047c8;
uint num3 = 0x87f81a15;
uint num4 = 0xbfc130fb;
for (int i = 3; 0 <= i; i--)
{
buffer[i] = (byte)num;
num = num >> 8;
buffer[i + 4] = (byte)num2;
num2 = num2 >> 8;
buffer[i + 8] = (byte)num3;
num3 = num3 >> 8;
buffer[i + 12] = (byte)num4;
num4 = num4 >> 8;
}
for (int j = 0; j < name.Length; j++)
{
buffer[((2 * j) + 0x10) + 1] = (byte)name[j];
buffer[(2 * j) + 0x10] = (byte)(name[j] >> 8);
}
using (SHA1 sha = SHA1.Create())
{
byte[] buffer2 = sha.ComputeHash(buffer);
int a = (((((buffer2[3] << 8) + buffer2[2]) << 8) + buffer2[1]) << 8) + buffer2[0];
short b = (short)((buffer2[5] << 8) + buffer2[4]);
short num9 = (short)((buffer2[7] << 8) + buffer2[6]);
return new System.Guid(a, b, (short)((num9 & 0xfff) | 0x5000), buffer2[8], buffer2[9], buffer2[10], buffer2[11], buffer2[12], buffer2[13], buffer2[14], buffer2[15]);
}
}
/// <summary>
/// Return the GUID of a provider.
/// </summary>
/// <param name="type">The provider type.</param>
/// <returns>The GUID representing the name.</returns>
public static Guid GetGuid(Type type)
{
EventSource eventSource = EventSourceImplementer.GetEventSource(type);
return eventSource.Guid;
}
/// <summary>
/// Return the manifest of a provider for the given type.
/// </summary>
/// <param name="type">The provider type.</param>
/// <returns>The XML manifest content.</returns>
public static string GenerateManifest(Type type)
{
EventSource eventSource = EventSourceImplementer.GetEventSource(type);
return EventSource.GenerateManifest(eventSource.GetType(), Assembly.GetAssembly(type).Location);
}
#endregion
}
}