⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kerneldllrtns.cpp

📁 windows驱动程序
💻 CPP
字号:
//****************************************************************************//
//*                                                                           //
//* Copyright (C) 2003, James Antognini, antognini@mindspring.com.            //
//*                                                                           //
//****************************************************************************//

/**************************************************************************************************/      
/*                                                                                                */      
/* Derived in part from Charles Saperstein, "Guest Article:  Kernel Mode DLLs," NT Insider,       */      
/* Nov/Dec 1997.                                                                                  */      
/*                                                                                                */      
/* See also Walter Oney, "Re: export_driver dllinitialize not called,"                            */
/* microsoft.public.development.device.drivers, 2002-10-15 03:08:08.                              */                                                      
/*                                                                                                */      
/* Notes:                                                                                         */
/*        1) It is not strictly necessary for the executable to be located under the directory    */      
/*           %systemroot%\system32\drivers.  It will work if the executable is located in the     */      
/*           same place as that for the driver that causes the DLL to be loaded.  Neither is the  */      
/*           DLLDEF statement necessary in the soources file.                                     */      
/*                                                                                                */      
/*        2) This kernel DLL will be loaded automagically by the OS when the first driver         */      
/*           importing from this DLL is about to be loaded.  The DLL will be unloaded by the OS   */      
/*           when the last importing driver has been unloaded.                                    */      
/*                                                                                                */      
/*        3) For unloading to be done, both DllInitialize() and DllUnload() must be present and   */      
/*           defined in KernelDLLRtns.def.                                                        */
/*                                                                                                */      
/**************************************************************************************************/      

#define JADrvNm         "KernelDLLRtns"
#define JADrvNmW       L"KernelDLLRtns"

#define JADrvVer        "1.00"                                                                  
                                                                                                
#ifdef __cplusplus  // C++ conversion.                                                          
extern "C"                                                                                      
{                                                                                               
#endif              // End #ifdef C++ conversion.                                               
                                                                                                
#include <ntddk.h>
                                                                                                
#define  ExportKernelDLL    1                                                                                              
#define  JADriverKernelMode 1                         // Ensure kernel pieces available.        
#include "KernelDLL.h"
                                                                                                
#ifdef __cplusplus  // C++ conversion.                                                          
}                                                                                               
#endif              // End #ifdef C++ conversion.                                               

//***************************************************************************//
//                                                                           //
// Routine prototypes.                                                       //
//                                                                           //
//***************************************************************************//

//****************************************************************************//
//*                                                                           //
//* Globals.                                                                  //
//*                                                                           //
//****************************************************************************//

#define CompDateTimeStr "dd mmm yyyy hh:mm:ss"      
                                                    
char DrvCompileInfo[sizeof(CompDateTimeStr)+1];

/**************************************************************************************************/
/*                                                                                                */
/* DriverEntry                                                                                    */
/*                                                                                                */
/* Notes:                                                                                         */
/*        1) DriverEntry() is required for linking but is never invoked.  DllInitialize() and     */
/*           DllUnload() instead are invoked when the DLL is loaded and unloaded, respectively.   */
/*                                                                                                */
/**************************************************************************************************/
extern "C"
NTSTATUS
DriverEntry(PDRIVER_OBJECT, PUNICODE_STRING)
{
 return STATUS_SUCCESS;
}

/**************************************************************************************************/
/*                                                                                                */
/* Test routine that will be imported and invoked by CallKernelDLL.sys.                           */
/*                                                                                                */
/**************************************************************************************************/
__declspec(dllexport)
NTSTATUS
KernelDLLRtnsTest(
                  PDEVICE_OBJECT pDevObj
                 )
{
 NTSTATUS                status = STATUS_SUCCESS;

 DbgPrint((JADrvNm ".KernelDLLRtnsTest()\n"));

 return status;
}

/**************************************************************************************************/
/*                                                                                                */
/* Routine that is invoked when the DLL is loaded.                                                */
/*                                                                                                */
/* Notes:                                                                                         */
/*        1) Support for this routine appeared in Win2K.                                          */
/*        2) The presence of DllInitialize() and DllUnload() allows the DLL to be unloaded.       */
/*                                                                                                */
/**************************************************************************************************/
extern "C"
NTSTATUS 
DllInitialize(PUNICODE_STRING pRegistryPath) 
{
 NTSTATUS                status = STATUS_SUCCESS;

 char                     static DateCompiledBase[] = __DATE__,                                                                             
                                 TimeCompiledBase[] = " "__TIME__;                                                                             
 char                            DateCompiled[] =     // Build date in preferred (dd mmm yyyy) format.                                      
                                   {DateCompiledBase[4], DateCompiledBase[5], DateCompiledBase[6],                         
                                    DateCompiledBase[0], DateCompiledBase[1], DateCompiledBase[2], DateCompiledBase[3],
                                    DateCompiledBase[7], DateCompiledBase[8], DateCompiledBase[9], DateCompiledBase[10],
                                    0x0
                                   };

 if (' '==DateCompiled[0])                            // Leading blank (eg, in ' 1 Apr 2003')?              
  strcpy(DrvCompileInfo, DateCompiled+1);                                               
 else                                                                                   
  strcpy(DrvCompileInfo, DateCompiled+0);                                               
                                                                                       
 strcat(DrvCompileInfo, TimeCompiledBase);                                              

 DbgPrint((JADrvNm " v" JADrvVer " (compiled %s) -- DllInitialize()\n", DrvCompileInfo));

 return status;
}

/**************************************************************************************************/
/*                                                                                                */
/* Routine that is invoked when the DLL is unloaded.                                              */
/*                                                                                                */
/* Notes:                                                                                         */
/*        1) Support for this routine appeared in Win2K.                                          */
/*        2) The presence of DllInitialize() and DllUnload() allows the DLL to be unloaded.       */
/*                                                                                                */
/**************************************************************************************************/
extern "C"
NTSTATUS 
DllUnload()  
{
 NTSTATUS                status = STATUS_SUCCESS;

 DbgPrint((JADrvNm ".DllUnload()\n"));

 return status;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -