[英]Unable to use NDIS related functions from a Visual Studio's Empty WDM Driver template
I was looking at try writing an NDIS miniport driver and created a new project in my VS2019 installation, choosing the "Empty WDM Driver" as my starting template.我正在考虑尝试编写 NDIS 微型端口驱动程序,并在我的 VS2019 安装中创建了一个新项目,选择“Empty WDM 驱动程序”作为我的起始模板。 I can include ndis.h, but many functions appear not be available including important things like NDIS_MINIPORT_DRIVER_CHARACTERISTICS
and NdisMRegisterMiniportDriver
cannot be used.我可以包含 ndis.h,但许多功能似乎不可用,包括无法使用NDIS_MINIPORT_DRIVER_CHARACTERISTICS
和NdisMRegisterMiniportDriver
等重要功能。 Quickly searching for these in the actual ndis.h file shows that they are greyed out under the preprocessor directive #if NDIS_SUPPORT_NDIS6
在实际的 ndis.h 文件中快速搜索这些显示它们在预处理器指令#if NDIS_SUPPORT_NDIS6
下显示为灰色
I have the driver samples repository cloned, and the miniport driver sample works fine, with nothing and uses the same WDK installation.我克隆了驱动程序示例存储库,微型端口驱动程序示例工作正常,没有任何内容并使用相同的 WDK 安装。 Looking at the configuration between my project and the samples, the options under the "Driver Settings" section are completely different.查看我的项目和示例之间的配置,“驱动程序设置”部分下的选项完全不同。 I'm still rather new to all this, so I'm assuming this is some misconfiguration on my part.我对这一切还是很陌生,所以我假设这是我的一些错误配置。 Is there anything else I have to edit in my project configuration?在我的项目配置中我还有什么需要编辑的吗? The only change I've mad so far in making sure the linker links with the NDIS library.到目前为止,我唯一疯狂的改变是确保 linker 与 NDIS 库链接。 Perhaps the WDM driver template is not what I want for this type of driver, though in that case I'm not sure how to properly set up my project.对于这种类型的驱动程序,也许 WDM 驱动程序模板不是我想要的,但在这种情况下,我不确定如何正确设置我的项目。 VS only has one NDIS template and it's for filter drivers. VS 只有一个 NDIS 模板,用于过滤驱动程序。
To make all those APIs show up, you need to set the NDIS version that you're targeting.要显示所有这些 API,您需要设置目标的 NDIS 版本。 For example, if you're targeting Windows 7 and later, that would be NDIS 6.20, so you'd put this somewhere before including ndis.h:例如,如果您的目标是 Windows 7 及更高版本,那将是 NDIS 6.20,因此您可以在包含 ndis.h 之前将其放在某处:
#define NDIS620_MINIPORT 1
That's all you have to define;这就是您必须定义的全部内容; ndis.h will automatically fill out the other versioning macros on your behalf. ndis.h 将代表您自动填写其他版本控制宏。
To see a list of all NDIS versions, look at the top of ndis.h.要查看所有 NDIS 版本的列表,请查看 ndis.h 的顶部。
In general, you can bang on the "WDM template" or even a completely empty.C file until it becomes an NDIS driver.通常,您可以敲击“WDM 模板”甚至是完全空的.C 文件,直到它成为 NDIS 驱动程序。 If you're starting from scratch, you should ensure that you:如果您从头开始,则应确保:
/DNDIS620_MINIPORT=1
above定义一个 NDIS 版本宏,例如上面的/DNDIS620_MINIPORT=1
/kernel
flag使用/kernel
标志编译/GS /guard:cf /Qspectre
, but seems to change often, so consider this answer to already be out of date)使用推荐的一组安全标志进行编译(目前包括/GS /guard:cf /Qspectre
,但似乎经常更改,所以认为这个答案已经过时了)DriverEntry
that doesn't touch the DRIVER_OBJECT
directly;添加一个不直接接触DRIVER_OBJECT
的DriverEntry
; let NdisMRegisterMiniportDriver
do that instead让NdisMRegisterMiniportDriver
代替If you're using a generic WDM template, note that you'll have to replace any DriverUnload
(NDIS has its own flavor of that) and delete any AddDevice
(NDIS handles that on your behalf).如果您使用的是通用 WDM 模板,请注意您必须替换任何DriverUnload
(NDIS 有其自己的风格)并删除任何AddDevice
(NDIS 代表您处理)。 You'll probably want to delete anything that mentions IRPs.您可能想要删除任何提及 IRP 的内容。 While NDIS allows you to handle IRP_MJ_DEVICE_CONTROL
with a control device object (CDO) created via NdisRegisterDeviceEx
, it's not strictly necessary and many real-world miniports don't use IRPs at all.虽然 NDIS 允许您使用通过NdisRegisterDeviceEx
创建的控制设备 object (CDO) 来处理IRP_MJ_DEVICE_CONTROL
,但这并不是绝对必要的,而且许多现实世界的微型端口根本不使用 IRP。
Once you fill out all the callbacks that NdisMRegisterMiniportDriver
demands, you'll have a skeleton of an NDIS miniport driver.填写NdisMRegisterMiniportDriver
要求的所有回调后,您将拥有 NDIS 微型端口驱动程序的骨架。 This is a valuable educational exercise, and I do recommend building a driver from scratch, so you'll see how all the pieces fall together.这是一个有价值的教育练习,我建议从头开始构建一个驱动程序,这样你就会看到所有部分是如何组合在一起的。 But you don't have to do this yourself, if you're in a hurry.但是,如果您赶时间,您不必自己执行此操作。 We have a sample miniport here .我们在这里有一个示例微型端口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.