2012年7月5日星期四

IoRegisterFsRegistrationChange.C


/*
IoRegisterFsRegistrationChange这个函数,大多数人都知道.
在文件过滤驱动中大多用到,也都知道字面的意思.
本人笨拙,要刨根问底,进一步知晓,只有我编写代码,调试并查看效果,我才算掌握这个函数.
与其说回调,不如说:在一般的情况下是枚举(文件系统相关的).这是不正确但形象的说明.
这个函数费了我半天的时间.
*/

//#include <ntddk.h>
#include <Ntifs.h>

VOID DriverNotificationRoutine(__in PDEVICE_OBJECT DeviceObject,__in BOOLEAN FsActive)
{
    if (FsActive) 
    {
        DbgPrint("/////////////////////////////////////////////////////////////////////////\n");
        DbgPrint("the file system has registered\n"); //\n后面不能有空格,不然会蓝屏.
        DbgPrint("本设备对象所在的驱动对象的驱动名字:%wZ \n",&DeviceObject->DriverObject->DriverName);//\FileSystem\Fs_Rec重复出现好几次.
        if(DeviceObject->NextDevice) //不判断会蓝屏.因为有的没有.
        {
            DbgPrint("本设备对象的下一个设备对象的驱动对象的驱动名字:%wZ \n",&DeviceObject->NextDevice->DriverObject->DriverName);
        }
        if (DeviceObject->AttachedDevice)
        {
            DbgPrint("本设备对象的附加设备对象的所在驱动的驱动的名字:%wZ \n",&DeviceObject->AttachedDevice->DriverObject->DriverName);
        }

        //这个和第一个显示的是一样的.就是:&DeviceObject->DriverObject->DriverName,注释掉,不显示了.
        //DbgPrint("本设备对象的扩展信息中的驱动对象的驱动名字:%wZ \n",&DeviceObject->DeviceObjectExtension->DeviceObject->DriverObject->DriverName);
    } 
    else 
    { 
        DbgPrint("the file system has unregistered\n"); 
    }
}

VOID Unload(PDRIVER_OBJECT DriverObject)
{
    IoUnregisterFsRegistrationChange(DriverObject, DriverNotificationRoutine);
}

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING pRegistryPath)
{
    _asm int 3
    DriverObject->DriverUnload = Unload; 
    IoRegisterFsRegistrationChange(DriverObject, DriverNotificationRoutine);     

    return STATUS_SUCCESS;
}
//made at 2012.06.29

没有评论:

发表评论