forked from busy10/AutoSpitta-x64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentry.c
186 lines (139 loc) · 4.8 KB
/
entry.c
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "mousehook.h"
#include "keyboardhook.h"
#include "entry.h"
#include "hacks.h"
#define IOCTL_PDC CTL_CODE( FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_SPECIAL_ACCESS )
NTSTATUS Function_IRP_MJ_CREATE(PDEVICE_OBJECT pDeviceObject, PIRP Irp)
{
UNREFERENCED_PARAMETER(pDeviceObject);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
}
NTSTATUS Function_IRP_MJ_CLOSE(PDEVICE_OBJECT pDeviceObject, PIRP Irp)
{
UNREFERENCED_PARAMETER(pDeviceObject);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Irp->IoStatus.Status;
}
NTSTATUS Function_IRP_UNSUPPORTED(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
NTSTATUS NtStatus = STATUS_SUCCESS;
DbgPrint("An unsupported majour function was requested. Returning STATUS_SUCCESS");
return NtStatus;
}
NTSTATUS Function_IRP_DEVICE_CONTROL(PDEVICE_OBJECT pDeviceObject, PIRP Irp)
{
UNREFERENCED_PARAMETER(pDeviceObject);
PIO_STACK_LOCATION pIoStackLocation;
NTSTATUS status = STATUS_SUCCESS;
PVOID pBuf = Irp->AssociatedIrp.SystemBuffer;
ULONG bytesIO = 0;
ULONG outputBufferLength;
pIoStackLocation = IoGetCurrentIrpStackLocation(Irp);
outputBufferLength = pIoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
do {
if (pIoStackLocation == NULL) {
status = STATUS_INTERNAL_ERROR;
break;
}
pBuf = Irp->AssociatedIrp.SystemBuffer;
if (pBuf == NULL) {
status = STATUS_INVALID_PARAMETER;
break;
}
switch (pIoStackLocation->Parameters.DeviceIoControl.IoControlCode) {
case IOCTL_PDC:
{
bytesIO = 0;
if ((pIoStackLocation->Parameters.DeviceIoControl.InputBufferLength) != (unsigned long)sizeof(PASSDATA)) { // 32x PTR to 64x PTR
status = STATUS_INVALID_PARAMETER;
break;
}
// FUNCTION THAT COPIES MEMORY
status = shotbot_thread((PASSDATACTRL)pBuf);
break;
}
default:
{
status = STATUS_INVALID_PARAMETER;
}
}
} while (FALSE);
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = bytesIO;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
NTSTATUS AutoSpitta_InternalIoctl(PDEVICE_OBJECT device, PIRP irp)
{
PIO_STACK_LOCATION ios;
PCONNECT_DATA cd;
NTSTATUS status;
ios = IoGetCurrentIrpStackLocation(irp);
if (ios->Parameters.DeviceIoControl.IoControlCode == MOUCLASS_CONNECT_REQUEST)
{
cd = ios->Parameters.DeviceIoControl.Type3InputBuffer;
MouseDpcRoutine = (MouseServiceDpc)cd->ClassService;
// DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "Mouse_IO_InternalIoctl ----> MouseDpcRoutine[%x]\n", MouseDpcRoutine);
}
else if (ios->Parameters.DeviceIoControl.IoControlCode == KBDCLASS_CONNECT_REQUEST)
{
cd = ios->Parameters.DeviceIoControl.Type3InputBuffer;
KeyboardDpcRoutine = (KeyboardServiceDpc)cd->ClassService;
// DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "Keyboard_IO_InternalIoctl ----> KeyboardDpcRoutine[%x]\n", KeyboardDpcRoutine);
}
else
{
Function_IRP_UNSUPPORTED(device, irp);
}
return STATUS_SUCCESS;
}
const WCHAR deviceNameBuffer[] = L"\\Device\\AutoSpitta";
const WCHAR deviceSymLinkBuffer[] = L"\\DosDevices\\AutoSpitta";
PDEVICE_OBJECT g_MyDevice;
NTSTATUS DriverEntry(IN PDRIVER_OBJECT driverObject, IN PUNICODE_STRING regPath)
{
CLIENT_ID nthread;
HANDLE thread;
NTSTATUS ntStatus = 0;
UNICODE_STRING deviceNameUnicodeString, deviceSymLinkUnicodeString;
// Normalize name and symbolic link.
RtlInitUnicodeString(&deviceNameUnicodeString,
deviceNameBuffer);
RtlInitUnicodeString(&deviceSymLinkUnicodeString,
deviceSymLinkBuffer);
// Create the device.
ntStatus = IoCreateDevice(driverObject,
0, // For driver extension
&deviceNameUnicodeString,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_UNKNOWN,
FALSE,
&g_MyDevice);
// Create the symbolic link
ntStatus = IoCreateSymbolicLink(&deviceSymLinkUnicodeString,
&deviceNameUnicodeString);
driverObject->DriverUnload = DriverUnload;
unsigned int i;
for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
driverObject->MajorFunction[i] = Function_IRP_UNSUPPORTED;
driverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = AutoSpitta_InternalIoctl;
driverObject->MajorFunction[IRP_MJ_CREATE] = Function_IRP_MJ_CREATE;
driverObject->MajorFunction[IRP_MJ_CLOSE] = Function_IRP_MJ_CLOSE;
driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Function_IRP_DEVICE_CONTROL;
DbgPrint("AutoSpitta V1 loaded./n");
Mouse_Create(driverObject);
Keyboard_Create(driverObject);
//PsCreateSystemThread(&thread, STANDARD_RIGHTS_ALL, NULL, NULL, &nthread, (PKSTART_ROUTINE)SystemRoutine, NULL);
//ZwClose(thread);
return STATUS_SUCCESS;
}
VOID NTAPI DriverUnload(IN DRIVER_OBJECT *DriverObject) {
UNICODE_STRING symLink;
RtlInitUnicodeString(&symLink, deviceSymLinkBuffer);
IoDeleteSymbolicLink(&symLink);
Mouse_Close(DriverObject);
Keyboard_Close(DriverObject);
IoDeleteDevice(DriverObject->DeviceObject);
DbgPrint("AutoSpitta V1 unloaded./n");
}