-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdbgext.cxx
163 lines (130 loc) · 2.89 KB
/
dbgext.cxx
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "stdafx.h"
#include "dbgext.hpp"
PDEBUG_CLIENT4 g_ExtClient;
PDEBUG_CONTROL4 g_ExtControl;
PDEBUG_SYMBOLS2 g_ExtSymbols;
WINDBG_EXTENSION_APIS ExtensionApis;
ULONG TargetMachine;
BOOL Connected;
// Queries for all debugger interfaces.
extern "C" HRESULT
ExtQuery(PDEBUG_CLIENT4 Client)
{
HRESULT Status;
if ((Status = Client->QueryInterface(__uuidof(IDebugControl4),
(void**)&g_ExtControl)) != S_OK)
{
goto Fail;
}
if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols2),
(void**)&g_ExtSymbols)) != S_OK)
{
goto Fail;
}
g_ExtClient = Client;
return S_OK;
Fail:
ExtRelease();
return Status;
}
// Cleans up all debugger interfaces.
void
ExtRelease(void)
{
g_ExtClient = NULL;
EXT_RELEASE(g_ExtControl);
EXT_RELEASE(g_ExtSymbols);
}
// Normal output.
void __cdecl
ExtOut(PCSTR Format, ...)
{
va_list Args;
va_start(Args, Format);
g_ExtControl->OutputVaList(DEBUG_OUTPUT_NORMAL, Format, Args);
va_end(Args);
}
// Error output.
void __cdecl
ExtErr(PCSTR Format, ...)
{
va_list Args;
va_start(Args, Format);
g_ExtControl->OutputVaList(DEBUG_OUTPUT_ERROR, Format, Args);
va_end(Args);
}
// Warning output.
void __cdecl
ExtWarn(PCSTR Format, ...)
{
va_list Args;
va_start(Args, Format);
g_ExtControl->OutputVaList(DEBUG_OUTPUT_WARNING, Format, Args);
va_end(Args);
}
void __cdecl
ExtOutDml(PCSTR Format, ...)
{
va_list Args;
va_start(Args, Format);
g_ExtControl->ControlledOutputVaList(DEBUG_OUTCTL_DML, DEBUG_OUTPUT_NORMAL, Format, Args);
va_end(Args);
}
EXTERN_C
WIN32KEXT_API
HRESULT
CALLBACK
DebugExtensionInitialize(
OUT PULONG Version,
OUT PULONG Flags)
{
IDebugClient* DebugClient;
PDEBUG_CONTROL4 DebugControl;
HRESULT hr = S_OK;
*Version = DEBUG_EXTENSION_VERSION(1, 0);
*Flags = 0;
//
// Create a new debugclient
//
if ((hr = DebugCreate(__uuidof(IDebugClient), (void**)&DebugClient)) != S_OK) {
return hr;
}
if ((hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
(void**)&DebugControl)) == S_OK){
//
// Get the windbg-style extension APIS
//
ExtensionApis.nSize = sizeof(ExtensionApis);
hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis);
//
// check is in kernel mode
//
ULONG dbgClass, dbgQualifier;
if (SUCCEEDED(DebugControl->GetDebuggeeType(&dbgClass, &dbgQualifier))) {
if (dbgClass != DEBUG_CLASS_KERNEL) {
dprintf("This extension is for kernel-mode only\n");
hr = S_FALSE;
}
}
//
// check os
//
ULONG PlatformId, Win32Major, Win32Minor, KdMajor, KdMinor;
if (SUCCEEDED(DebugControl->GetSystemVersionValues(&PlatformId, &Win32Major, &Win32Minor,
&KdMajor, &KdMinor))) {
DEBUGPRINT("OS Detected: %d.%d.%d.%d\n", Win32Major, Win32Minor, KdMajor, KdMinor);
}
DebugControl->Release();
}
DebugClient->Release();
return hr;
}
EXTERN_C
WIN32KEXT_API
void
CALLBACK
DebugExtensionUninitialize(void)
{
//DEBUGPRINT("DebugExtensionUninitialize\n");
return;
}