c++ - 如何在驱动程序的 INF 文件中使用变量?

标签 c++ c windows driver inf

我正在使用 Visual Studio 2015 和 WDK 10 开发 NDIS 过滤器驱动程序。要求是使用 INF 文件中的不同 FilterClass(compressionms_medium_converter_128)编译驱动程序。我不想维护两个几乎相同的 INF 文件,除了不同的 FilterClass

我的问题是:有什么方法可以在 INF 文件中使用变量或宏吗? 这样我就可以在 Visual Studio 中使用不同的配置来控制实际编译的 INF 内容。效果是这样的:

HKR, Ndi,FilterClass,, %MACRO_OR_VAR_FILTER_CLASS%

然后我可以在 VS 中控制 %MACRO_OR_VAR_FILTER_CLASS%

最后附上我的整个INF文件:

;-------------------------------------------------------------------------
; NPF.INF -- Npcap NDIS 6.x LightWeight Filter Driver
;
; Copyright (c) 2015, Insecure.Com LLC.  All rights reserved.
;------------------------------------------------------------------------
[version]
Signature       = "$Windows NT$"
Class           = NetService
ClassGUID       = {4D36E974-E325-11CE-BFC1-08002BE10318}
CatalogFile     = %NPF_DriverName%.cat
Provider        = %Insecure%
DriverVer=05/15/2015,14.48.38.905


[Manufacturer]
%Insecure%=Insecure,NTx86,NTia64,NTamd64

[Insecure.NTx86]
%NPF_Desc%=Install, INSECURE_NPF

[Insecure.NTia64]
%NPF_Desc%=Install, INSECURE_NPF

[Insecure.NTamd64]
%NPF_Desc%=Install, INSECURE_NPF

;-------------------------------------------------------------------------
; Installation Section
;-------------------------------------------------------------------------
[Install]
AddReg=Inst_Ndi
Characteristics=0x40000
NetCfgInstanceId="{7daf2ac8-e9f6-4765-a842-f1f5d2501340}"
Copyfiles = npf.copyfiles.sys

[SourceDisksNames]
1=%NPF_Desc%,"",,

[SourceDisksFiles]
npf.sys=1

[DestinationDirs]
DefaultDestDir=12
npf.copyfiles.sys=12

[npf.copyfiles.sys]
%NPF_DriverName%.sys,,,2


;-------------------------------------------------------------------------
; Ndi installation support
;-------------------------------------------------------------------------
[Inst_Ndi]
HKR, Ndi,Service,,%NPF_DriverName%
HKR, Ndi,CoServices,0x00010000,%NPF_DriverName%
HKR, Ndi,HelpText,,%NPF_HelpText%
HKR, Ndi,FilterClass,, ms_medium_converter_128


; For a Monitoring filter, use this:
;     HKR, Ndi,FilterType,0x00010001, 1 ; Monitoring filter
; For a Modifying filter, use this:
;     HKR, Ndi,FilterType,0x00010001, 2 ; Modifying filter
HKR, Ndi,FilterType,0x00010001,2


HKR, Ndi\Interfaces,UpperRange, , noupper
HKR, Ndi\Interfaces,LowerRange, , "ndis5,ndis4"


; TODO: Ensure that the list of media types below is correct.  Typically,
; filters include "ethernet".  Filters may also include "ppip" to include
; native WWAN stacks, but you must be prepared to handle the packet framing.
; Possible values are listed on MSDN, but common values include:
;     ethernet, wan, ppip, wlan
HKR, Ndi\Interfaces, FilterMediaTypes,,"ethernet, fddi, wan, ppip, wlan, bluetooth, ndis5, vwifi, flpp4, flpp6, vchannel, nolower"


; For a Mandatory filter, use this:
;     HKR, Ndi,FilterRunType,0x00010001, 1 ; Mandatory filter
; For an Optional filter, use this:
;     HKR, Ndi,FilterRunType,0x00010001, 2 ; Optional filter
HKR, Ndi,FilterRunType,0x00010001, 2 ; Optional filter


; By default, Mandatory filters unbind all protocols when they are
; installed/uninstalled, while Optional filters merely pause the stack.  If you
; would like to override this behavior, you can include these options.  These
; options only take effect with 6.30 filters on Windows "8" or later.
; To prevent a full unbind, and merely pause/restart protocols:
;     HKR, Ndi,UnbindOnAttach,0x00010001, 0 ; Do not unbind during FilterAttach
;     HKR, Ndi,UnbindOnDetach,0x00010001, 0 ; Do not unbind during FilterDetach
; To force a full unbind/bind (which includes pause/restart, of course):
;     HKR, Ndi,UnbindOnAttach,0x00010001, 1 ; Unbind during FilterAttach
;     HKR, Ndi,UnbindOnDetach,0x00010001, 1 ; Unbind during FilterDetach
;

;-------------------------------------------------------------------------
; Service installation support
;-------------------------------------------------------------------------
[Install.Services]
AddService=%NPF_DriverName%,,NPF_Service_Inst

[NPF_Service_Inst]
DisplayName     = %NPF_Desc%
ServiceType     = 1 ;SERVICE_KERNEL_DRIVER
StartType       = 3 ;SERVICE_DEMAND_START
ErrorControl    = 1 ;SERVICE_ERROR_NORMAL
ServiceBinary   = %12%\%NPF_DriverName%.sys
LoadOrderGroup  = NDIS
Description     = %NPF_Desc%
AddReg          = Common.Params.reg, NdisImPlatformBindingOptions.reg

[Install.Remove.Services]
DelService=%NPF_DriverName%,0x200 ; SPSVCINST_STOPSERVICE

[Common.Params.reg]

[NdisImPlatformBindingOptions.reg]
; By default, when an LBFO team or Bridge is created, all filters will be
; unbound from the underlying members and bound to the TNic(s). This keyword
; allows a component to opt out of the default behavior
; To prevent binding this filter to the TNic(s):
;   HKR, Parameters, NdisImPlatformBindingOptions,0x00010001,1 ; Do not bind to TNic
; To prevent unbinding this filter from underlying members:
;   HKR, Parameters, NdisImPlatformBindingOptions,0x00010001,2 ; Do not unbind from Members
; To prevent both binding to TNic and unbinding from members:
;   HKR, Parameters, NdisImPlatformBindingOptions,0x00010001,3 ; Do not bind to TNic or unbind from Members
HKR, Parameters, NdisImPlatformBindingOptions,0x00010001,0 ; Subscribe to default behavior

[Strings]
NPF_DriverName = "npf"
Insecure = "Nmap Project"
NPF_Desc = "Npcap Packet Driver (NPCAP)"
NPF_HelpText = "A NDIS 6 filter driver & WFP callout driver to support packet capturing and sending under Windows 7, 8 & 10"

最佳答案

我认为 Inf“语言”中没有这样的功能。 但是您可以通过使用可以接受 VS 构建宏的简单预构建脚本轻松实现您的目标。这样的脚本可以将所需的值注入(inject)到您的 inf 文件中 - 您可以使用 VS 宏从脚本访问 inf,例如 ($SolutionDir)($ProjectDir) 等. 该脚本可以集成到 VS 解决方案中,因此编写后无需额外的工作即可运行。

enter image description here

关于c++ - 如何在驱动程序的 INF 文件中使用变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36101071/

相关文章:

android - 编译.c库Eclipse for Android错误

c - 功能是打印我的字符远离它应该在的地方

c# - 如何 : Prevent Timeout When Inspecting Unavailable Network Share - C#

C语言: pointer returned by malloc() and casting

c++ - Eigen 错误 : please_protect_your_min_with_parentheses

c++ - C++ 中的对象实例化类型

C++在WM6.1上锁定tabskbar但也锁定windows键

c++ - 如何使 char 数组与输入的大小相同(或者可以使用字符串库而不是 C 样式数组字符串来完成)?

windows - 如何在Windows服务上添加证书

c++ - 使用 std::complex<double> 时出现 gcc4.9.1 的段错误