-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.cpp
100 lines (78 loc) · 2 KB
/
main.cpp
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
#include "stdafx.h"
#include <intrin.h>
#include "ProcessorExecute.h"
#include "main.tmh" // Windows software trace preprocessor
//////////////////////////////////////////////////////////////////////////
#pragma pack(push, 1)
typedef struct _KDESCRIPTOR
{
UINT16 Limit;
PVOID Base;
}KDESCRIPTOR, *PKDESCRIPTOR;
#pragma pack(pop)
extern"C"
{
DRIVER_INITIALIZE DriverEntry;
}
static auto AdjustIDTLimit(UINT16 aDiff)
-> NTSTATUS
{
NTSTATUS vStatus = STATUS_SUCCESS;
TraceEntry();
for (;;)
{
static UINT16 sOldLimit = 0;
if (0 == aDiff)
{
if (0 == sOldLimit)
{
break;
}
aDiff = sOldLimit;
}
ProcessorExecute([](UINT32 aProcessorNumber, void* aContext) -> void
{
auto vLimitDiff = (INT16)(SIZE_T)aContext;
auto vIdt = KDESCRIPTOR{};
__sidt(&vIdt);
if (0 == sOldLimit)
{
sOldLimit = vIdt.Limit;
}
vIdt.Limit = vLimitDiff;
__lidt(&vIdt);
TraceInfo("Cpu[%d] idt base: 0x%p, limit: 0x%04X to 0x%04X", aProcessorNumber, vIdt.Base, sOldLimit, vIdt.Limit);
}, (void*)(SIZE_T)aDiff);
break;
}
TraceExit(vStatus);
return vStatus;
}
static auto DriverUnload(PDRIVER_OBJECT aDriverObject)
-> void
{
AdjustIDTLimit(static_cast<UINT16>(0u));
WPP_CLEANUP(aDriverObject);
}
auto DriverEntry(PDRIVER_OBJECT aDriverObject, PUNICODE_STRING aRegistryPath)
-> NTSTATUS
{
NTSTATUS vStatus = STATUS_UNSUCCESSFUL;
for (;;)
{
WPP_INIT_TRACING(aDriverObject, aRegistryPath);
vStatus = AdjustIDTLimit(static_cast<UINT16>(-1));
if (!NT_SUCCESS(vStatus))
{
break;
}
aDriverObject->DriverUnload = DriverUnload;
break;
}
TraceReturn(vStatus);
if (!NT_SUCCESS(vStatus))
{
DriverUnload(aDriverObject);
}
return vStatus;
}