21 #include <ddk/ntddk.h>
22 #include "../fbportio.h"
24 #define DEVICE_NAME L"\\Device\\fbportio"
25 #define DEVICE_DOS_NAME L"\\DosDevices\\fbportio"
26 #define IOPM_SIZE 0x2000
32 __declspec(dllimport) NTSTATUS NTAPI PsLookupProcessByProcessId(IN
HANDLE, OUT PEPROCESS *);
36 __declspec(dllimport)
void NTAPI Ke386IoSetAccessProcess(PEPROCESS,
int);
38 static NTSTATUS STDCALL device_dispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
40 Irp->IoStatus.Information = 0;
41 Irp->IoStatus.Status = STATUS_SUCCESS;
42 IoCompleteRequest(Irp, IO_NO_INCREMENT);
43 return STATUS_SUCCESS;
46 static NTSTATUS STDCALL
device_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
48 PIO_STACK_LOCATION stack;
51 ULONG in_size, out_size;
52 ULONG written_bytes = 0;
54 struct _EPROCESS *process;
56 stack = IoGetCurrentIrpStackLocation(Irp);
57 in_size = stack->Parameters.DeviceIoControl.InputBufferLength;
58 out_size = stack->Parameters.DeviceIoControl.OutputBufferLength;
59 ldata = (PULONG) Irp->AssociatedIrp.SystemBuffer;
60 sdata = (PUSHORT) Irp->AssociatedIrp.SystemBuffer;
62 switch (stack->Parameters.DeviceIoControl.IoControlCode) {
65 status = STATUS_BUFFER_TOO_SMALL;
68 status = PsLookupProcessByProcessId(pid, &process);
69 if (NT_SUCCESS(status)) {
73 Ke386IoSetAccessProcess(process, 1);
74 status = STATUS_SUCCESS;
81 status = STATUS_BUFFER_TOO_SMALL;
85 status = STATUS_SUCCESS;
90 status = STATUS_UNSUCCESSFUL;
94 Irp->IoStatus.Information = written_bytes;
95 Irp->IoStatus.Status = status;
96 IoCompleteRequest(Irp, IO_NO_INCREMENT);
105 UNICODE_STRING unicode_dos_name;
111 RtlInitUnicodeString(&unicode_dos_name, dos_name_buffer);
112 IoDeleteSymbolicLink(&unicode_dos_name);
113 IoDeleteDevice(DriverObject->DeviceObject);
116 NTSTATUS STDCALL
DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
118 PDEVICE_OBJECT device_object;
122 UNICODE_STRING unicode_name, unicode_dos_name;
126 return STATUS_INSUFFICIENT_RESOURCES;
131 RtlInitUnicodeString(&unicode_name, name_buffer);
132 RtlInitUnicodeString(&unicode_dos_name, dos_name_buffer);
134 status = IoCreateDevice(DriverObject, 0, &unicode_name, FILE_DEVICE_UNKNOWN,
135 0,
FALSE, &device_object);
136 if (!NT_SUCCESS(status)) {
140 status = IoCreateSymbolicLink(&unicode_dos_name, &unicode_name);
141 if (!NT_SUCCESS(status)) {
145 DriverObject->MajorFunction[IRP_MJ_CREATE] = device_dispatch;
146 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
device_control;
149 return STATUS_SUCCESS;