关闭

TDI 编程--kernel socket 源码---DrvMain.cpp

1672人阅读 评论(0) 收藏 举报

#include "KernelHeader.h"
#include "DrvMain.h"
#include "function.h"

 

#include "NetDrv.h"

 

extern "C"
{
VOID TDIFunLib_DriverUnload(PDRIVER_OBJECT  DriverObject);
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING  pRegistryPath);

}


#pragma alloc_text( INIT, DriverEntry )
#pragma alloc_text( PAGE, TDIFunLib_DriverUnload)

 

/**********************************************************
 *
 * Fun: DriverEntry
 *
 *
 **********************************************************/

NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING  pRegistryPath)
{
 NTSTATUS NtStatus = STATUS_SUCCESS; 
 UNICODE_STRING usDriverName = {0};
 UNICODE_STRING usSymbolicLinkName = {0};
 PDEVICE_OBJECT pControlDeviceObject = NULL;
 UINT uiIndex = 0;

 RtlInitUnicodeString( &usDriverName, TDIFunLib_DEVICE_NAME);
 RtlInitUnicodeString( &usSymbolicLinkName, TDIFunLib_DOSDEVICE_NAME);
 

 /*
  * Create Named Control Device Object
  */

 NtStatus = IoCreateDevice( DriverObject, sizeof(TDIFunLib_DEVICE_EXTENSION), &usDriverName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN,FALSE, &pControlDeviceObject);
 if ( NtStatus != STATUS_SUCCESS ) 
 {
  return NtStatus ;
 }

 /*
  * Assign Dispatch Routine
  */
  
 for (uiIndex=0; uiIndex < IRP_MJ_MAXIMUM_FUNCTION; uiIndex++)
 {
  DriverObject->MajorFunction[uiIndex] = TDIFunLib_CommonDispatch;
 }
 
 DriverObject->MajorFunction[ IRP_MJ_CREATE ] = TDIFunLib_CreateDispatch;
 DriverObject->MajorFunction[ IRP_MJ_READ ]  = TDIFunLib_ReadDispatch;
 DriverObject->MajorFunction[ IRP_MJ_WRITE ]  = TDIFunLib_WriteDispatch;
 DriverObject->MajorFunction[ IRP_MJ_CLEANUP ] = TDIFunLib_CleanUpDispatch;
 DriverObject->MajorFunction[ IRP_MJ_CLOSE ]  = TDIFunLib_CloseDispatch;
 DriverObject->MajorFunction[ IRP_MJ_DEVICE_CONTROL ] = TDIFunLib_IoControlDispatch;
 DriverObject->MajorFunction[ IRP_MJ_INTERNAL_DEVICE_CONTROL ] = TDIFunLib_IoControlInternal;
 
 /*
  * If this Fun is missing, Driver can't be dynamically Unloaded.
  */

 DriverObject->DriverUnload = TDIFunLib_DriverUnload;
 

 /*
  * Set Flag On ControlDeviceObject to determin type of IO.  IO Manager Copy Data from Databuffer
  * given by user-mode app to sysBuffer On behalf of driver.
  */

 pControlDeviceObject->Flags |= DO_BUFFERED_IO;
 

 /*
  * Driver  Iniitalizing OK !!
  */

 pControlDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
 

 /*
  * Create symbolicLink to ControlDeviceObject
  */
 
 IoCreateSymbolicLink(&usSymbolicLinkName, &usDriverName); 

 

 return NtStatus;
}

 

/**********************************************************
 *
 * Fun: TDIFunLib_DriverUnload
 *
 *
 **********************************************************/

VOID TDIFunLib_DriverUnload(PDRIVER_OBJECT  DriverObject)
{
 UNICODE_STRING usSymbolicLinkName;


 /*
  * Delete SymbolicLinkName
  */

 RtlInitUnicodeString( &usSymbolicLinkName, TDIFunLib_DOSDEVICE_NAME );

 IoDeleteSymbolicLink( &usSymbolicLinkName );


 /*
  * Delete DeviceObject
  */
 
  IoDeleteDevice( DriverObject->DeviceObject );
 
 
  /*
   *
   * Release Other resouces
   *
   */

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:456827次
    • 积分:7048
    • 等级:
    • 排名:第3382名
    • 原创:156篇
    • 转载:76篇
    • 译文:12篇
    • 评论:77条
    最新评论