NTSTATUS DispatchIoctl(PDEVICE_OBJECT pDriver,PIRP pIrp)
{
NTSTATUS status
=
STATUS_INVALID_DEVICE_REQUEST;
PIO_STACK_LOCATION pIrpStack;
ULONG uIoControlCode;
PVOID pIoBuffer;
ULONG uInSize;
ULONG uOutSize;
ini
复制
/
/
获得IRP里的关键数据
pIrpStack
=
IoGetCurrentIrpStackLocation(pIrp);
/
/
获取控制码
uIoControlCode
=
pIrpStack
-
>Parameters.DeviceIoControl.IoControlCode;
/
/
输入和输出的缓冲区(DeviceIoControl的InBuffer和OutBuffer都是它)
pIoBuffer
=
pIrp
-
>AssociatedIrp.SystemBuffer;
/
/
EXE发送传入数据的
BUFFER
长度(DeviceIoControl的nInBufferSize)
uInSize
=
pIrpStack
-
>Parameters.DeviceIoControl.InputBufferLength;
/
/
EXE接收传出数据的
BUFFER
长度(DeviceIoControl的nOutBufferSize)
uOutSize
=
pIrpStack
-
>Parameters.DeviceIoControl.OutputBufferLength;
/
/
对不同控制信号的处理流程
switch (uIoControlCode)
{
case IOCTL_IO_LyShark:
{
DWORD dw
=
0
;
stylus
复制
/
/
得到输入参数
memcpy(&dw, pIoBuffer, sizeof(DWORD));
DbgPrint(
"[+] hello lyshark \n"
);
/
/
对输入参数进行处理
dw
+
+
;
/
/
设置输出参数
memcpy(pIoBuffer, &dw, sizeof(DWORD));
/
/
返回通信状态
status
=
STATUS_SUCCESS;
break
;
}
pIrp
-
>IoStatus.Status
=
status;
pIrp
-
>IoStatus.Information
=
uOutSize;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return
status;
}
/
/
设定DeviceIoControl的lpBytesReturned的值(如果通信失败则返回
0
长度)
if
(status
=
=
STATUS_SUCCESS)
pIrp
-
>IoStatus.Information
=
uOutSize;
else
pIrp
-
>IoStatus.Information
=
0
;
/
/
设定DeviceIoControl的返回值是成功还是失败
pIrp
-
>IoStatus.Status
=
status;
IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return
status;
}