是否可以在不重新启动的情况下卸载内核驱动程序?

发布于 2024-10-14 18:03:28 字数 291 浏览 9 评论 0原文

我正在研究 Win7 DDK 中的内核驱动程序示例之一。我可以修改编译并构建我的 *.sys 文件。我也可以使用其 INF(使用设备管理器或 devcon)或直接使用服务控制管理器来安装它。当我进行下一个更改并生成更新的 *.sys 文件时,我似乎在这个新文件和我现在停止的驱动程序之间发生冲突(我尝试使用 Servcie Control Manager“停止”和“删除服务”等)。如果重新启动,我可以安装新驱动程序并正常运行。同样,如果我在设备管理器中选择卸载,Windows 会提示我重新启动。

那么,如何轻松测试对内核驱动程序的增量修改呢? 谢谢

I'm playing about with one of the kernel driver examples in the Win7 DDK. I can modify compile and build my *.sys file. I can install it too with its INF (using device manager or devcon) or using the Service control manager directly. When I make the next change though and generate an updated *.sys file I seem to get a conflict between this new file and my now stopped driver (I've tried using Servcie Control Manager 'stop' and 'delete service' etc). If I reboot, I can install the new driver and run it fine. Similarly, if I choose uninstall in Device Manager, Windows prompts me to reboot.

So, how can one easily test incremental modifications to a kernal driver easily?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

当梦初醒 2024-10-21 18:03:28

查看安装 API 日志可能是一个不错的起点:http://msdn.microsoft.com/en-us/library/ff550887%28v=VS.85%29.aspx

如果 devcon 提示重新启动,您可以查看 DDK 中的代码,调试它为什么这么问并以这种方式深入研究问题。

Looking at the Setup API logs might be a good place to start: http://msdn.microsoft.com/en-us/library/ff550887%28v=VS.85%29.aspx

If devcon prompts for a reboot, you could look at the code in the DDK, debug why it's asking and dig into the issue that way as well.

时光与爱终年不遇 2024-10-21 18:03:28

是的。 sc stop 应该停止您的驱动程序。如果您的驱动程序与特定的 PnP devnode 关联,则应在删除 devnode 后卸载它。

Yes. sc stop <driver name> should stop your driver. If your driver is associated with a particular PnP devnode, it should be unloaded after the devnode is removed.

执手闯天涯 2024-10-21 18:03:28

如果您希望能够卸载驱动程序,则必须设置一个基本上在每次卸载驱动程序时执行的函数 - 最有可能的是您将放置释放分配的缓冲区和生命周期中可能“活动”的任何其他资源的代码司机的。这是一个示例代码:

VOID  Unload(IN  PDRIVER_OBJECT  pDriverObject) { 
                 //do whatever you like here
                //this deletes the device
        IoDeleteDevice( pDriverObject->DeviceObject);


    return;
}

NTSTATUS  DriverEntry(IN  PDRIVER_OBJECT  pDriverObject,  IN  PUNICODE_STRING  regPath) { 


    //initialize your driver and the major function array 

//set the unload function 
    pDriverObject->DriverUnload  =  &Unload; 
}

If you want to be able to unload your driver you have to set up a function which basically executes each time the driver is unloaded - most likely you will put code which frees allocated buffers and any other resource which might be "alive" during the lifecycle of the of the driver. Here is an example code:

VOID  Unload(IN  PDRIVER_OBJECT  pDriverObject) { 
                 //do whatever you like here
                //this deletes the device
        IoDeleteDevice( pDriverObject->DeviceObject);


    return;
}

NTSTATUS  DriverEntry(IN  PDRIVER_OBJECT  pDriverObject,  IN  PUNICODE_STRING  regPath) { 


    //initialize your driver and the major function array 

//set the unload function 
    pDriverObject->DriverUnload  =  &Unload; 
}
我不在是我 2024-10-21 18:03:28

尝试编译、签名并加载此代码:

#include <ntddk.h>     
VOID OnUnload( IN PDRIVER_OBJECT driverObjectA ) {
    DbgPrint("Unload\n");
}
NTSTATUS DriverEntry( PDRIVER_OBJECT driverObjectA, PUNICODE_STRING RegistryPath ){
    DbgPrint("DriverEntry\n"); 
    driverObjectA->DriverUnload = OnUnload;
return STATUS_SUCCESS;
}  

然后下载 DebugView,解压以管理员身份运行它,然后“捕获”菜单项下的“捕获内核”。下载、解压并运行OSR Driver Loader,注册驱动程序,“启动服务”。您将在 DbgView 中观察到“DriverEntry”日志消息。现在,在 OSR 驱动程序加载程序中,“停止服务”并观察 Unload 消息。希望这能让你继续前进。

Try compiling, signing, and loading this code:

#include <ntddk.h>     
VOID OnUnload( IN PDRIVER_OBJECT driverObjectA ) {
    DbgPrint("Unload\n");
}
NTSTATUS DriverEntry( PDRIVER_OBJECT driverObjectA, PUNICODE_STRING RegistryPath ){
    DbgPrint("DriverEntry\n"); 
    driverObjectA->DriverUnload = OnUnload;
return STATUS_SUCCESS;
}  

Then download DebugView, unzip it, run it as administrator, and then "Capture Kernel" under the "Capture" menu item. Download, unzip, and run the OSR Driver Loader, register the driver, the "Start Service". You will observe a "DriverEntry" log message in DbgView. Now in the the OSR Driver loader, "Stop Service" and observe an Unload message. Hopefully that gets you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文