-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadwrite.c
65 lines (55 loc) · 1.74 KB
/
readwrite.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
#include "private.h"
NTSTATUS MyDriverDispatchIoRead(IN DEVICE_OBJECT *DeviceObject, IN IRP *Irp)
{
NTSTATUS status;
ULONG ulLength;
IO_STACK_LOCATION *IoStackLocation;
PVOID pBuf;
char *szStr;
UNREFERENCED_PARAMETER(DeviceObject);
status = STATUS_SUCCESS;
ulLength = 0;
IoStackLocation = NULL;
pBuf = NULL;
szStr = NULL;
MyDriver_DbgPrint(LOG_INFO, ("Enter MyDriverDispatchIoRead."));
szStr = "This is a test string!";
pBuf = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
ulLength = IoStackLocation->Parameters.Read.Length;
if (ulLength < strlen(szStr) + 1)
{
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
Irp->IoStatus.Information = 0;
}
else
{
RtlCopyMemory(pBuf, szStr, strlen(szStr) + 1);
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = strlen(szStr) + 1;
}
IoCompleteRequest(Irp, IO_NO_INCREMENT);
MyDriver_DbgPrint(LOG_INFO, ("Exit MyDriverDispatchIoRead."));
return STATUS_SUCCESS;
}
NTSTATUS MyDriverDispatchIoWrite(IN DEVICE_OBJECT *DeviceObject, IN IRP *Irp)
{
NTSTATUS status;
ULONG ulLength;
IO_STACK_LOCATION *IoStackLocation;
PVOID pBuf;
UNREFERENCED_PARAMETER(DeviceObject);
status = STATUS_SUCCESS;
ulLength = 0;
IoStackLocation = NULL;
pBuf = NULL;
MyDriver_DbgPrint(LOG_INFO, ("Enter MyDriverDispatchIoWrite."));
pBuf = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
ulLength = IoStackLocation->Parameters.Read.Length;
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = ulLength;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
MyDriver_DbgPrint(LOG_INFO, ("Exit MyDriverDispatchIoWrite."));
return STATUS_SUCCESS;
}