forked from lilhoser/livedump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveDump.hpp
144 lines (121 loc) · 3.61 KB
/
LiveDump.hpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#pragma once
#include <assert.h>
#include <stdio.h>
#include <windows.h>
#include <winternl.h>
#include <TlHelp32.h>
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
#define TRIAGE_SIZE 0x100000 // must be >132kB and <1MB
#pragma comment(lib, "ntdll")
// Taken from https://github.com/winsiderss/systeminformer/blob/82c625783a035fa7eac355783f527bb53fb1a384/phnt/include/ntexapi.h#L4654
typedef enum _SYSDBG_COMMAND
{
SysDbgQueryModuleInformation,
SysDbgQueryTraceInformation,
SysDbgSetTracepoint,
SysDbgSetSpecialCall, // PVOID
SysDbgClearSpecialCalls, // void
SysDbgQuerySpecialCalls,
SysDbgBreakPoint,
SysDbgQueryVersion, // DBGKD_GET_VERSION64
SysDbgReadVirtual, // SYSDBG_VIRTUAL
SysDbgWriteVirtual, // SYSDBG_VIRTUAL
SysDbgReadPhysical, // SYSDBG_PHYSICAL // 10
SysDbgWritePhysical, // SYSDBG_PHYSICAL
SysDbgReadControlSpace, // SYSDBG_CONTROL_SPACE
SysDbgWriteControlSpace, // SYSDBG_CONTROL_SPACE
SysDbgReadIoSpace, // SYSDBG_IO_SPACE
SysDbgWriteIoSpace, // SYSDBG_IO_SPACE
SysDbgReadMsr, // SYSDBG_MSR
SysDbgWriteMsr, // SYSDBG_MSR
SysDbgReadBusData, // SYSDBG_BUS_DATA
SysDbgWriteBusData, // SYSDBG_BUS_DATA
SysDbgCheckLowMemory, // 20
SysDbgEnableKernelDebugger,
SysDbgDisableKernelDebugger,
SysDbgGetAutoKdEnable,
SysDbgSetAutoKdEnable,
SysDbgGetPrintBufferSize,
SysDbgSetPrintBufferSize,
SysDbgGetKdUmExceptionEnable,
SysDbgSetKdUmExceptionEnable,
SysDbgGetTriageDump, // SYSDBG_TRIAGE_DUMP, CONTROL_TRIAGE_DUMP
SysDbgGetKdBlockEnable, // 30
SysDbgSetKdBlockEnable,
SysDbgRegisterForUmBreakInfo,
SysDbgGetUmBreakPid,
SysDbgClearUmBreakPid,
SysDbgGetUmAttachPid,
SysDbgClearUmAttachPid,
SysDbgGetLiveKernelDump, // SYSDBG_LIVEDUMP_CONTROL, CONTROL_KERNEL_DUMP
SysDbgKdPullRemoteFile, // SYSDBG_KD_PULL_REMOTE_FILE
SysDbgMaxInfoClass
} SYSDBG_COMMAND;
//
// From NDK, argument required for parameter 29.
//
typedef struct _SYSDBG_TRIAGE_DUMP
{
ULONG Flags;
ULONG BugCheckCode;
ULONG_PTR BugCheckParam1;
ULONG_PTR BugCheckParam2;
ULONG_PTR BugCheckParam3;
ULONG_PTR BugCheckParam4;
ULONG ProcessHandles;
ULONG ThreadHandles;
PHANDLE Handles;
} SYSDBG_TRIAGE_DUMP, *PSYSDBG_TRIAGE_DUMP;
//
// Undocumented. Structures relevant for new parameter 37.
// Greetz to Alex I.
//
typedef union _SYSDBG_LIVEDUMP_CONTROL_FLAGS
{
struct
{
ULONG UseDumpStorageStack : 1;
ULONG CompressMemoryPagesData : 1;
ULONG IncludeUserSpaceMemoryPages : 1;
ULONG Reserved : 29;
};
ULONG AsUlong;
} SYSDBG_LIVEDUMP_CONTROL_FLAGS;
typedef union _SYSDBG_LIVEDUMP_CONTROL_ADDPAGES
{
struct
{
ULONG HypervisorPages : 1;
ULONG Reserved : 31;
};
ULONG AsUlong;
} SYSDBG_LIVEDUMP_CONTROL_ADDPAGES;
typedef struct _SYSDBG_LIVEDUMP_CONTROL
{
ULONG Version;
ULONG BugCheckCode;
ULONG_PTR BugCheckParam1;
ULONG_PTR BugCheckParam2;
ULONG_PTR BugCheckParam3;
ULONG_PTR BugCheckParam4;
PVOID DumpFileHandle;
PVOID CancelEventHandle;
SYSDBG_LIVEDUMP_CONTROL_FLAGS Flags;
SYSDBG_LIVEDUMP_CONTROL_ADDPAGES AddPagesControl;
} SYSDBG_LIVEDUMP_CONTROL, *PSYSDBG_LIVEDUMP_CONTROL;
typedef NTSTATUS(__stdcall * NtSystemDebugControl)(
ULONG ControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength,
PULONG ReturnLength);
BOOL EnablePrivilege(__in PCWSTR PrivilegeName, __in BOOLEAN Acquire);
NTSTATUS
CreateTriageDump(__in HANDLE FileHandle, __in ULONG Pid, __in ULONG numThreads);
NTSTATUS
CreateKernelDump(
__in HANDLE FileHandle,
__in SYSDBG_LIVEDUMP_CONTROL_FLAGS Flags,
__in SYSDBG_LIVEDUMP_CONTROL_ADDPAGES Pages);
INT wmain(__in INT Argc, __in PWCHAR Argv[]);