在一个驱动中,我明明设置了:
DriverObject->DriverUnload=Ctrl2capUnload;
可是运行后,在DriverMonitor点stop卸载,却提示:
Error 1052:The driver is not in a state to accept this command
为何没有对应派遣函数?我明明设置了啊。。
这个驱动一直卸载不了,还请各位指点一下。谢谢
摘录一段代码:
VOID Ctrl2capUnload( IN PDRIVER_OBJECT Driver );
NTSTATUS DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
....
DriverObject->DriverUnload=Ctrl2capUnload;
....
}
VOID Ctrl2capUnload(IN PDRIVER_OBJECT pdoGlobalDrvObj)
{
KTIMER kTimer;
LARGE_INTEGER timeout;
PDEVICE_OBJECT pDevObj;
PDEVICE_EXTENSION pdx;
UNICODE_STRING ntUnicodString;
UNICODE_STRING pLinkName;
PRKTHREAD CurrentThread;
DbgPrint(("Drive Unload!\n")); //根本没有执行到这,为什么派遣函数对应不起来?
pDevObj = pdoGlobalDrvObj->DeviceObject;
pdx = (PDEVICE_EXTENSION) pDevObj->DeviceExtension;
//当前线程设置为低实时模式
CurrentThread = KeGetCurrentThread();
KeSetPriorityThread(CurrentThread,LOW_REALTIME_PRIORITY);
UNREFERENCED_PARAMETER(pdoGlobalDrvObj);
pLinkName =pdx->ustrSymLinkName;
IoDeleteSymbolicLink(&pLinkName); //获取并删除符号链接
IoDetachDevice ( pdx->TopOfStack); //TopOfStack存放下层设备,解除绑定
timeout = RtlConvertLongToLargeInteger(-10*1000);
while(num)
{
KeDelayExecutionThread(KernelMode, FALSE, &timeout); //让当前工作线程睡眠直到超时
KeWaitForSingleObject(aThread, Executive, KernelMode, FALSE, NULL); //等待线程结束
}
Ter = TRUE; //线程结束标记
KeReleaseSemaphore(&sem, 0, 1, FALSE); //释放信号灯
//
// 如果还有 IRP 未完成,且当前 IRP 有效则尝试取消这个 IRP
//
if (pdx->IrpsInProgress > 0 && pDevObj->CurrentIrp != NULL )
{
if ( CancelKeyboardIrp( pDevObj->CurrentIrp ) )
{
//
// 成功则直接退出删除键盘过滤设备
//
DbgPrint(( "CancelKeyboardIrp() is ok\n" ));
goto __End;
}
}
//
// 如果取消失败,则一直等待按键
//
while ( pdx->IrpsInProgress > 0 )
{
DbgPrint(( "Irp Count:%d\n", pdx->IrpsInProgress ));
}
__End:
IoDeleteDevice( pDevObj);
ZwClose(hfile);
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)