Repository navigation
Expand file tree
/
Copy pathmousehook.cpp
More file actions
116 lines (97 loc) · 2.51 KB
/
Copy pathmousehook.cpp
File metadata and controls
116 lines (97 loc) · 2.51 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
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
#include "mousehook.h"
#include "Helper.h"
#include "ObCallback.h"
//=============================================================================
// Meta Interface
//=============================================================================
NTSTATUS
InitMouseHook(PDRIVER_OBJECT pDriverObject) {
UNICODE_STRING usDeviceName = {};
BOOLEAN fMclLoaded = FALSE;
BOOLEAN fMhkLoaded = FALSE;
BOOLEAN fMhmLoaded = FALSE;
NTSTATUS ntstatus = STATUS_SUCCESS;
LogDebug("Loading Mouse hook");
//
// Load the driver modules.
//
ntstatus = MhdDriverEntry();
if (!NT_SUCCESS(ntstatus))
{
LogDebug("MhdDriverEntry failed: 0x%X", ntstatus);
goto exit;
}
ntstatus = MclDriverEntry(pDriverObject);
if (!NT_SUCCESS(ntstatus))
{
LogDebug("MclDriverEntry failed: 0x%X", ntstatus);
goto exit;
}
//
fMclLoaded = TRUE;
ntstatus = MhkDriverEntry();
if (!NT_SUCCESS(ntstatus))
{
LogDebug("MhkDriverEntry failed: 0x%X", ntstatus);
goto exit;
}
//
fMhkLoaded = TRUE;
ntstatus = MhmDriverEntry();
if (!NT_SUCCESS(ntstatus))
{
LogDebug("MhmDriverEntry failed: 0x%X", ntstatus);
goto exit;
}
//
fMhmLoaded = TRUE;
LogDebug("Mouse hook loaded");
exit:
if (!NT_SUCCESS(ntstatus))
{
if (fMhmLoaded)
{
MhmDriverUnload();
}
if (fMhkLoaded)
{
MhkDriverUnload();
}
if (fMclLoaded)
{
MclDriverUnload();
}
}
return ntstatus;
}
VOID
UnloadMouseHook(PDRIVER_OBJECT pDriverObject) {
UNREFERENCED_PARAMETER(pDriverObject);
DBG_PRINT("Unloading Mouse hook.");
//
// Unload the driver modules.
//
MhmDriverUnload();
MhkDriverUnload();
MclDriverUnload();
DBG_PRINT("Mouse hook unloaded.");
}
//=============================================================================
// Private Interface
//=============================================================================
EXTERN_C
NTSTATUS
DispatchCreate(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) {
UNREFERENCED_PARAMETER(pDeviceObject);
DBG_PRINT("Processing IRP_MJ_CREATE.");
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
EXTERN_C
NTSTATUS
DispatchClose(PDEVICE_OBJECT pDeviceObject,PIRP pIrp) {
UNREFERENCED_PARAMETER(pDeviceObject);
DBG_PRINT("Processing IRP_MJ_CLOSE.");
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}