windows - 如何从内部卸载 Windows 内核模式驱动程序?

标签 windows kernel driver windows-kernel

我正在编写一个 Windows 内核驱动程序,我正在尝试实现以下内容。

假设驱动程序已通过DeviceIoControl 从用户模式调用具有特定 IOCTL 代码的函数。在这种情况下,驱动程序如何卸载自身?换句话说,如何实现与运行 net stop 命令相同的行为?

更准确地说,实现DispatchDeviceControl callback时我应该写什么?

NTSTATUS IoctlDeviceControl(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) {
    // some code...

    switch (ioctlCode) {
        case IOCTL_MY_UNLOAD:  <---
        ...
    }

    return Status;
}

最佳答案

可以使用ZwUnloadDriver内核函数!

文档:

The ZwUnloadDriver routine unloads a driver from the system. Use this routine with extreme caution. (See the following Remarks section.)

C/C++ 定义:

NTSTATUS ZwUnloadDriver(
  _In_  PUNICODE_STRING DriverServiceName
);

MSDN 来源:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff567117(v=vs.85).aspx

关于windows - 如何从内部卸载 Windows 内核模式驱动程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19694915/

相关文章:

C编程调用FILE *variable

build - 如何构建freebsd内核?

java.nio.file.path : inconsistent behaviour with name count?

c# - 在缺少 setup.py 的 Windows 上构建 Apache QPID

c - Linux 内核延迟,低于 jiffies,没有忙等待

android - Creative Ziio 和安卓开发,adb

driver - Windows IoT Core 上的 NDIS 协议(protocol)驱动程序

Linux 设备驱动程序 - 如何在关闭文件时解锁读取线程?

c# - 如何向 Windows 窗体面板动态添加标签或其他元素?

c# - 完全关闭辅助窗口