简体   繁体   English

将Windows驱动程序连接到Userland服务

[英]Connecting Windows Driver to Userland Service

How do I communicate with a driver from the userland in Windows? 如何与Windows中的用户区域的驱动程序进行通信? (Vista if that makes a difference.) Can I, and how, communicate with the service from the driver site? (Vista,如果这有所不同。)我可以,以及如何与驱动程序站点的服务进行通信?

I am actually not very lazy and should probably get my boss to buy me a book, but I don't know which. 我实际上不是很懒,应该让我的老板给我买一本书,但我不知道哪一本。 And guessing commands and sections from the MSDN is kinda taking a lot of nerves and time without the right terms to search for. 猜测来自MSDN的命令和部分有点紧张和时间没有正确的搜索条件。 Can someone drop me some terms to look for in the documentation? 有人可以在文档中删除我要查找的一些术语吗?

OSR online is a good source of information on writing windows drivers. OSR在线是编写Windows驱动程序的良好信息来源。

How to name devices in kernel mode (with a link to access security). 如何在内核模式下命名设备 (带有访问安全性的链接)。

The basic path is : 基本路径是:

Name your device object with one of the naming functions (eg WdfDeviceInitAssignName). 使用其中一个命名函数命名您的设备对象(例如WdfDeviceInitAssignName)。

In the service you do : 在您的服务中:

hDev = CreateFile( <obj name>, ..., OVERLAPPED )

DeviceIOControl( hDev, .. , OVERLAPPED);

while( !end )
   SleepEx( 100, true /*bAltertable*/ );

...

In the driver, you have an IRP queue, in which you queue requests from the service. 在驱动程序中,您有一个IRP队列,您可以在其中对来自服务的请求进行排队。 When you want to call the service, you complete one of the IRPs. 如果要调用该服务,请完成其中一个IRP。

NB: Its a bit complex ... and depends on the driver framework/model you are working with. 注意:它有点复杂......并且取决于您正在使用的驱动程序框架/模型。 I had to do this only once with in a NDIS filter driver. 我只需要在NDIS过滤器驱动程序中执行此操作一次。 Ask again, if you need more info. 再问一次,如果您需要更多信息。

I have to do this as an answer to keep the links, not as a comment to Christopher. 我必须这样做作为保持链接的答案,而不是对克里斯托弗的评论。

thanks again. 再次感谢。 And thanks to this tutorial I may add another answer shortly. 由于本教程,我可能会在短期内添加另一个答案。 It is the naming eg. 这是命名,例如。 by 通过

IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);

that I needed. 我需要的。 (I recommend above tutorial for making a complex topic easily understood) (我推荐上面的教程,以便轻松理解复杂的主题)

Userland programs may then communicate with the driver by opening a filehandle: 然后Userland程序可以通过打开文件句柄与驱动程序通信:

CreateFile("\\\\.\\Example",

In addition to what's been said above, your question: "Can I, and how, communicate with the service from the driver site?" 除了上面所说的,你的问题是:“我可以,以及如何与驱动网站上的服务进行通信?”

This is typically done through what they refer to as an "inverted call". 这通常通过他们称之为“反向呼叫”的方式来完成。 You'll send an IOCTL down and block until the driver fills it with the data requested. 你将发送一个IOCTL并阻塞,直到驱动程序用请求的数据填充它。

Also, with regard to what books to order, I actually enjoyed the Greg Hoglund Rootkits book for basic driver writing (that is, Hello World driver). 另外,关于订购哪些书籍,我实际上喜欢Greg Hoglund Rootkits的基本驱动程序编写书(即Hello World驱动程序)。 OSR Online is excellent. OSR Online非常棒。 An old one but still great is Windows NT Device Driver Development. 一个旧的但仍然很棒的是Windows NT设备驱动程序开发。 OSR has classic reprints of great books to get. OSR拥有经典的重读书籍。

Really though, the examples that come with the WDK from Microsoft will probably answer many of your questions. 实际上,微软WDK附带的例子可能会回答你的很多问题。

在书中:“使用Windows驱动程序基础开发驱动程序”一直是建议学习编程驱动程序的答案

The ready-to-build-and-execute WDK sample SIOCTL is your best bet. 准备构建并执行WDK示例SIOCTL是您最好的选择。 Just few hundred lines of code (mostly comment and spaces) will give you a quick start and understanding of Windows I/O model, which is the official way of user <==> kernel communication method. 只需几百行代码(主要是注释和空格)就可以让您快速了解Windows I / O模型,这是用户<==>内核通信方法的官方方式。

Every Windows driver learner should start with this one. 每个Windows驱动程序学习者都应该从这个开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM