2013年6月29日星期六

IoRegisterDriverReinitialization.C

/*
文本就命名为:IoRegisterDriverReinitialization.C吧!
made by correy
made at 2013.06.29
Email:kouleguan at hotmail dot com
Homepage:http://correy.webs.com
*/

#include <ntifs.h>

DRIVER_REINITIALIZE Reinitialize;
VOID Reinitialize(__in struct _DRIVER_OBJECT  *DriverObject, __in_opt PVOID  Context, __in ULONG  Count)
{
    //如果是IoRegisterDriverReinitialization注册的,DriverEntry运行之后就走到这里了。
    //如果是IoRegisterBootDriverReinitialization注册的,DriverEntry运行之后不会走到这里,可能在系统启动的某个时候运行。

    /*
    A driver can call this routine only if its DriverEntry routine will return STATUS_SUCCESS.
    If the driver-supplied Reinitialize routine must use the registry,
    the DriverEntry routine should include a copy of the string to which RegistryPath points as part of the context passed to the Reinitialize routine in this call.

    If the driver is loaded dynamically,
    it is possible for this to occur during a normally running system,
    so all references to the reinitialization queue must be synchronized.

    The Count input to a DriverReinitializationRoutine indicates how many times this routine has been called, including the current call.

    The DriverEntry routine can call IoRegisterDriverReinitialization only once.
    If the Reinitialize routine should be run again after any other drivers' Reinitialize routines have returned control,
    the Reinitialize routine also can call IoRegisterDriverReinitialization as many times as the driver's Reinitialize routine should be run.

    Usually, a driver with a Reinitialize routine is a higher-level driver that controls both PnP and legacy devices.
    Such a driver must not only create device objects for the devices that the PnP manager detects (and for which the PnP manager calls the driver's AddDevice routine),
    the driver must also create device objects for legacy devices that the PnP manager does not detect.
    A driver can use a Reinitialize routine to create those device objects and layer the driver over the next-lower driver for the underlying device.
    */

    KdBreakPoint();
}

DRIVER_UNLOAD Unload;
VOID Unload(__in PDRIVER_OBJECT DriverObject)
{  

}

#pragma INITCODE
DRIVER_INITIALIZE DriverEntry;
NTSTATUS DriverEntry( __in struct _DRIVER_OBJECT  * DriverObject, __in PUNICODE_STRING  RegistryPath)
{
    NTSTATUS status = STATUS_UNSUCCESSFUL;

    KdBreakPoint();//#define KdBreakPoint() DbgBreakPoint()

    DriverObject->DriverUnload = Unload;      
       
    //IoRegisterBootDriverReinitialization(DriverObject,Reinitialize,0);
    IoRegisterDriverReinitialization(DriverObject,Reinitialize,0);
   
    return STATUS_SUCCESS;
}

没有评论:

发表评论