阅读:1985回复:10
各位老大帮忙看看,我照FILEMON写的代码,为什么DriverUnload不执行?
#define FILEMON_DEVICE_NAME L"\Device\FileMon"
#define FILEMON_DOSLINK_NAME L"\DosDevices\FileMon" PDEVICE_OBJECT g_pDevObj; NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { DbgPrint (("Filemon.SYS: entering DriverEntryn")); DrvFileMon_AddDevice(DriverObject, FILEMON_DEVICE_NAME); DriverObject->DriverUnload = FilemonUnload; return STATUS_SUCCESS ; } NTSTATUS DrvFileMon_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PWSTR pwDeviceName) { NTSTATUS status; UNICODE_STRING DeviceNameStr; UNICODE_STRING LinkNameStr; RtlInitUnicodeString( &DeviceNameStr, pwDeviceName); status = IoCreateDevice( DriverObject, 0, &DeviceNameStr, FILE_DEVICE_FILEMON, 0, FALSE, &g_pDevObj); //if( NT_SUCCESS(status)) if(status == STATUS_SUCCESS) { DbgPrint(("Filemon: Successful to create our device!n")); // Create a symbolic link that the GUI can specify to gain access // to this driver/device RtlInitUnicodeString (&LinkNameStr, FILEMON_DOSLINK_NAME ); status = IoCreateSymbolicLink (&LinkNameStr, &DeviceNameStr ); if (!NT_SUCCESS(status)) { IoDeleteDevice(g_pDevObj); DbgPrint (("Filemon.SYS: IoCreateSymbolicLink Failedn")); } else { DbgPrint (("Filemon.SYS: IoCreateSymbolicLink Successfuln")); } return status; } return STATUS_SUCCESS ; } VOID FilemonUnload( IN PDRIVER_OBJECT DriverObject ) { UNICODE_STRING LinkNameStr; RtlInitUnicodeString (&LinkNameStr, FILEMON_DOSLINK_NAME ); IoDeleteSymbolicLink( &LinkNameStr); IoDeleteDevice(g_pDevObj); DbgPrint(("Filemon.SYS: unloadingn")); } |
|
沙发#
发布于:2004-08-21 21:35
我定义了
DriverObject->DriverUnload = FilemonUnload; 但是FilemonUnload函数一直没有被执行,请教这是因为什么原因呢? |
|
板凳#
发布于:2004-08-21 21:41
不知道对不对,我记得DriverObject->DriverUnload 好像是对静态安装的驱动程序的卸载,filemon的驱动程序是NT的核心模式驱动,可动态加载卸载,这样的话是不是应该在IRP_MJ_CLOSE中卸载?。。。。。。。。。。。。。。
|
|
|
地板#
发布于:2004-08-23 08:44
谢谢高手指点,我调试看看是不是这个原因。
|
|
地下室#
发布于:2004-08-27 08:27
我该怎么给分呢? :cool:
|
|
5楼#
发布于:2004-08-28 13:08
我该怎么给分呢? :cool: 多灌灌水在给分吧. |
|
6楼#
发布于:2004-09-01 09:00
OK
|
|
7楼#
发布于:2004-09-03 17:05
你的FILEMON竟然还有ADD DEVICE. 是WDM版的还是PNP的. ADD DEVICE和UNLOAD例程打算谁来调用? PNP MANAGER?
|
|
|
8楼#
发布于:2004-09-03 17:57
他的ADDDEVICE是在DriverEntry中调用的,是假的,只是个函数调用而已.不是WDM中的那个由PNP来调用的ADDDEVICE.
|
|
|
9楼#
发布于:2004-09-07 09:02
是的,我的ADDDEVICE只是个函数调用。
刚开始学driver,不是很清楚,以后请多指教 :D 照我的理解filemon应该是wdm版的。 UNLOAD例程在filemon的代码中当中也有,filemon不是为pnp设备写的,应该不是由PNP MANAGER调用。 不知道我的这个概念是不是正确的。。。 谢谢! |
|
10楼#
发布于:2004-09-07 09:04
以下是filemon中关于DriverUnload 的代码:
#if DBG // // Driver unload is only set if we are debugging Filemon. This is // because unloading a filter is not really safe - threads could // be in our fastio routines (or about to enter them), for example, // and there is no way to tell. When debugging, we can risk the // occasional unload crash as a trade-off for not having to // reboot as often. // // DriverObject->DriverUnload = FilemonUnload; #endif // DBG |
|