-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugEvent.cs
More file actions
34 lines (29 loc) · 1.52 KB
/
DebugEvent.cs
File metadata and controls
34 lines (29 loc) · 1.52 KB
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
using System;
using System.Runtime.InteropServices;
namespace DebugNET.PInvoke {
[StructLayout(LayoutKind.Sequential)]
internal struct DebugEvent {
public DebugEventType DebugEventCode;
public int ProcessId;
public int ThreadId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 86, ArraySubType = UnmanagedType.U1)]
private byte[] debugInfo;
public ExceptionDebugInfo Exception => GetDebugInfo<ExceptionDebugInfo>();
public CreateThreadDebugInfo CreateThread => GetDebugInfo<CreateThreadDebugInfo>();
public CreateProcessDebugInfo CreateProcessInfo => GetDebugInfo<CreateProcessDebugInfo>();
public ExitThreadDebugInfo ExitThread => GetDebugInfo<ExitThreadDebugInfo>();
public ExitProcessDebugInfo ExitProcess => GetDebugInfo<ExitProcessDebugInfo>();
public LoadDLLDebugInfo LoadDll => GetDebugInfo<LoadDLLDebugInfo>();
public UnloadDLLDebugInfo UnloadDll => GetDebugInfo<UnloadDLLDebugInfo>();
public OutputDebugStringInfo DebugString => GetDebugInfo<OutputDebugStringInfo>();
public RIPInfo RipInfo => GetDebugInfo<RIPInfo>();
private T GetDebugInfo<T>() where T : struct {
int structSize = Marshal.SizeOf(typeof(T));
IntPtr pointer = Marshal.AllocHGlobal(structSize);
Marshal.Copy(debugInfo, 0, pointer, structSize);
object result = Marshal.PtrToStructure(pointer, typeof(T));
Marshal.FreeHGlobal(pointer);
return (T)result;
}
}
}