Да вот он , ток это вроде как элементарный пример
//=========================================================
//= Start.cxx #ifdef __cplusplus
extern "C"
{
#endif
#include "ntddk.h"
//#include "wdm.h"
#ifdef __cplusplus
}
#endif
#include <stdio.h>
#include "INCLUDE\MY.h"
#include "INCLUDE\WORK_PROJECT.h"
//= PROTO
extern "C" NTSTATUS DriverEntryProc ( IN PDRIVER_OBJECT pDriverObject ,
IN PUNICODE_STRING RegistryPath ) ;
NTSTATUS DriverCreateCloseProc (IN PDEVICE_OBJECT FDO , IN PIRP IRP );
NTSTATUS DriverReadWriteProc (IN PDEVICE_OBJECT FDO , IN PIRP IRP );
NTSTATUS DriverIOControlProc (IN PDEVICE_OBJECT FDO , IN PIRP IRP );
VOID DriverUnloadProc (IN PDRIVER_OBJECT pDriverObject );
NTSTATUS AddDeviceProc (IN PDRIVER_OBJECT pDriverObject ,
IN PDEVICE_OBJECT pDeviceObject );
NTSTATUS CompleteIrp (PIRP IRP , NTSTATUS STATUS , ULONG INFO );
//=
//r
//& ENTRY proc
//r
#pragma code_seg("INIT")
NTSTATUS DriverEntryProc ( IN PDRIVER_OBJECT pDriverObject ,
IN PUNICODE_STRING RegistryPath ) {
NTSTATUS STATUS =0 ;
UNICODE_STRING _uniDevName;
UNICODE_STRING _uniLinkName;
PDEVICE_OBJECT _FDO ;
PDEVICE_EXTENSION _pDevExt ;
//"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
RtlInitUnicodeString(&_uniDevName , L"\\Device\\EMPTY" );
RtlInitUnicodeString( &_uniLinkName , L"\\??\\EMPTY" );
//""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
pDriverObject ->DriverUnload = DriverUnloadProc ;
pDriverObject ->MajorFunction [ IRP_MJ_CREATE ] =DriverCreateCloseProc;
pDriverObject ->MajorFunction [ IRP_MJ_CLOSE ] =DriverCreateCloseProc;
pDriverObject->DriverExtension->AddDevice = AddDeviceProc ; //""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
STATUS = IoCreateDevice( pDriverObject , sizeof( DEVICE_EXTENSION ), &_uniDevName , FILE_DEVICE_UNKNOWN , 0 , FALSE, & _FDO);
IF ( ! NT_SUCCESS( STATUS ))
{
DbgPrint("=START= ERROR ." ); RETURN STATUS ;//ERROR
} //"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
STATUS = IoCreateSymbolicLink(& _uniLinkName , &_uniDevName);
IF ( ! NT_SUCCESS( STATUS ))
{
DbgPrint("create symbolic error\n");
IoDeleteDevice( _FDO ); RETURN STATUS;
}
_pDevExt = (PDEVICE_EXTENSION)_FDO->DeviceExtension;
_pDevExt->SymbolicLink = _uniLinkName;
_pDevExt->DeviceObject=_FDO;
DbgPrint("=Example= ENTRY OK ." );
RETURN STATUS ;
}
//r
//& Add Device proc
//r
#pragma code_seg("PAGE")
NTSTATUS AddDeviceProc (IN PDRIVER_OBJECT pDriverObject ,
IN PDEVICE_OBJECT pDeviceObject ){
//- DATA
NTSTATUS STATUS =0 , status =0;
UNICODE_STRING _uniDevName;
UNICODE_STRING _uniLinkName;
PDEVICE_OBJECT _FDO ;
PDEVICE_EXTENSION _pDevExt ;
//- BODY
DbgPrint("=Example= ADD OK " );
RETURN STATUS_SUCCESS;
}
//r
//&CREATE CLOSE FILE proc
//r
#pragma code_seg()
NTSTATUS DriverCreateCloseProc ( IN PDEVICE_OBJECT FDO , IN PIRP IRP ){
//- DATA
NTSTATUS STATUS = STATUS_SUCCESS ;
PIO_STACK_LOCATION _pIrpStack = IoGetCurrentIrpStackLocation( IRP );
//- BODY
switch ( _pIrpStack ->MajorFunction )
{
case IRP_MJ_CREATE:
break;
case IRP_MJ_CLOSE:
break;
default:
STATUS = STATUS_NOT_IMPLEMENTED;
break;
}
RETURN CompleteIrp ( IRP , STATUS , 0);
}
//r
//& READ WRITE FILE proc
//r
#pragma code_seg()
NTSTATUS DriverReadWriteProc ( IN PDEVICE_OBJECT FDO , IN PIRP IRP ){
//- DATA
PIO_STACK_LOCATION _pIrpStack = IoGetCurrentIrpStackLocation( IRP );
ULONG _Length = _pIrpStack->Parameters.Read.Length;
PVOID _pBuffer = IRP->UserBuffer;
//- BODY
DbgPrint("=Example= READ WRITE %d." , _Length);
RETURN CompleteIrp ( IRP , STATUS_SUCCESS, 0);
}
//r
//& UNLOAD EXIT proc
//r
#pragma code_seg("PAGE")
VOID DriverUnloadProc (IN PDRIVER_OBJECT pDriverObject ){
//- INIT
NTSTATUS STATUS = STATUS_SUCCESS ;
PDEVICE_EXTENSION _pDevExt = (PDEVICE_EXTENSION)
pDriverObject->DeviceObject->DeviceExtension;
//- BODY
DbgPrint("UNLOAD DRIVER " );
STATUS =IoDeleteSymbolicLink( &(_pDevExt->SymbolicLink) );
IF ( ! NT_SUCCESS( STATUS ))
DbgPrint( " ERROR EXIT %ws ", _pDevExt->SymbolicLink) ;
IoDeleteDevice( _pDevExt->DeviceObject );
RETURN;
}
//r
//& COMPLETE proc
//r
#pragma code_seg()
NTSTATUS CompleteIrp(PIRP IRP , NTSTATUS STATUS , ULONG INFO ){
IRP ->IoStatus.Status = STATUS;
IRP ->IoStatus.Information = INFO ;
IoCompleteRequest( IRP , IO_NO_INCREMENT );
RETURN STATUS ;
}
//===========================================================================
//=My.h [/b]
#define DriverEntryProc DriverEntry
#define BOOL bool
#define BYTE unsigned char
#define WORD unsigned short
#define QWORD LARGE_INTEGER
#define FOR for
#define IF if
#define WHILE while
#define ELSE else
#define False false
#define True true
#define null 0
//#define NULL 0
//#define Null NULL
//#define null NULL
#define RETURN return
#define BREAK break
#define invoke
//=============================================================
//= WORK_PROJECT.h[/b]
typedef struct tagDEVICE_EXTENSION
{
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT LowerDeviceObject;
DEVICE_STATE DevState;
UNICODE_STRING SymbolicLink;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
//*////////////////////////////////////////////////////////////