Hi, just don’t know why the user-mode could not send the specified command to kernel-mode component,
here's the source of user mode :
#define BASE_IOCTL (FILE_DEVICE_UNKNOWN \<\< 16) | (FILE_READ_ACCESS \<\< 14) | METHOD_BUFFERED
#define IOCTL_DBG BASE_IOCTL | (1 \<\< 2)
#include <windows.h><br>#include <winioctl.h><br>#include <stdio.h><br><br>int __cdecl main(void)<br>{<br> char szTemp[256] = {0};<br> HANDLE hFile ;<br> DWORD dwReturn ;<br> hFile = CreateFile("\\\\.\\DeVx",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);<br> if(hFile)<br> {<br> DeviceIoControl(hFile,IOCTL_DBG,NULL,0,NULL,0,&dwReturn,NULL);<br> }<br> CloseHandle(hFile);<br> return 0;<br>}<br>```<br><br>& here's the kernel-mode :<br><br>```<br>#include <ntddk.h><br><br>typedef char * PCHAR;<br><br>#define BASE_IOCTL (FILE_DEVICE_UNKNOWN << 16) | (FILE_READ_ACCESS << 14) | METHOD_BUFFERED<br>#define IOCTL_DBG BASE_IOCTL | (1 << 2)<br><br>void ioDbg()<br>{ <br> DbgPrint("\nioDbg - Successful - Congratulations!"); <br>}<br>NTSTATUS Unsupported_Function(PDEVICE_OBJECT DeviceObject, PIRP Irp)<br>{<br> NTSTATUS NtStatus = STATUS_NOT_SUPPORTED;<br> DbgPrint("\nUnsupported Function ...");<br> return NtStatus ;<br>}<br>NTSTATUS eClose(PDEVICE_OBJECT DeviceObject, PIRP Irp)<br>{<br> NTSTATUS NtStatus = STATUS_SUCCESS;<br> DbgPrint("\neCLose()");<br> return STATUS_SUCCESS;<br>}<br>NTSTATUS eCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp)<br>{<br> NTSTATUS NtStatus = STATUS_SUCCESS;<br> DbgPrint("\neCreate");<br> return NtStatus ;<br>}<br>NTSTATUS eIoControl(IN PDEVICE_OBJECT pDeviceObject, IN PIRP Irp)<br>{<br> PIO_STACK_LOCATION irpStack;<br> NTSTATUS NtStatus = STATUS_SUCCESS;<br> PVOID inputBuffer;<br> PVOID outputBuffer;<br> ULONG inputBufferLength;<br> ULONG outputBufferLength;<br> ULONG ioctrlCode;<br> Irp->IoStatus.Status = STATUS_SUCCESS;<br> Irp->IoStatus.Information = 0;<br> inputBuffer = Irp->AssociatedIrp.SystemBuffer;<br> outputBuffer = Irp->AssociatedIrp.SystemBuffer;<br><br>irpStack = IoGetCurrentIrpStackLocation(Irp);<br> inputBufferLength = irpStack->Parameters.DeviceIoControl.InputBufferLength;<br> outputBufferLength = irpStack->Parameters.DeviceIoControl.OutputBufferLength;<br> ioctrlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;<br> DbgPrint("\neIoControl");<br> switch(ioctrlCode)<br> {<br> case IOCTL_DBG:<br> ioDbg();<br> break;<br><br>default:<br> DbgPrint("\neIoControl - Error !");<br> break;<br> }<br> return STATUS_SUCCESS;<br><br>}<br>VOID eUnload(PDRIVER_OBJECT DriverObject)<br>{<br> UNICODE_STRING usDosDeviceName ;<br> DbgPrint("\neUnload ...");<br> RtlInitUnicodeString(&usDosDeviceName,L"\\DosDevices\\DeVx");<br> IoDeleteSymbolicLink(&usDosDeviceName);<br> IoDeleteDevice(DriverObject->DeviceObject);<br>}<br><br>NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING RegistryPath)<br>{<br> int i ;<br> NTSTATUS NtStatus ;<br> PDEVICE_OBJECT pDeviceObject = NULL;<br> UNICODE_STRING usDriverName, usDosDeviceName ;<br> DbgPrint("\nDriverEntry");<br> RtlInitUnicodeString(&usDriverName,L"\\Device\\DeVx") ;<br> RtlInitUnicodeString(&usDosDeviceName,L"\\DosDevices\\DeVx");<br> NtStatus = IoCreateDevice(pDriverObject, 0, &usDriverName,FILE_DEVICE_UNKNOWN,FILE_DEVICE_SECURE_OPEN,FALSE,&pDeviceObject);<br> if(NT_SUCCESS(NtStatus))<br> {<br> for(i=0 ; i<irp_mj_maximum_function i> pDriverObject->MajorFunction[i] = Unsupported_Function ;<br><br>pDriverObject->MajorFunction[IRP_MJ_CLOSE] = eClose;<br> pDriverObject->MajorFunction[IRP_MJ_CREATE] = eCreate;<br> pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = eIoControl;<br><br>pDriverObject->DriverUnload = eUnload; <br><br>IoCreateSymbolicLink(&usDosDeviceName,&usDriverName);<br> }<br><br>return NtStatus ;<br>}<br>```<br><br>Simple IOCTL connection for just send an empty command to kernel-mode with IOCTL_DBG & this simply refer to ioDbg() function which just shows a dbgprint statement to the kernel debugger .<br><br>If anyone could catch this sikt problem it's good to say here .<br><br>regards.</irp_mj_maximum_function></ntddk.h></stdio.h></winioctl.h></windows.h>