Compiling WinPcap for Windows 7 x64

 

Compiling WinPcap for Windows 7 x64
2009-08-08 6:17 PM PDT
 
Well, since WinPcap team doesn't yet have an official Windows 7 version of WinPcap driver and the current installer refuses to install it (should work in Vista compatibility mode, but I had some problems with it), I went ahead and compiled and installed it manually myself.

Since compiling drivers on Windows requires the correct version of Windows Driver Kit, compiling it for Windows 7 was impossible because the version of WDK that supports Win7 was not publicly available. Yesterday I got e-mail from Microsoft telling that I now have download access to the kit, so I downloaded and got to work.

So this is my story. I'm writing this in a tutorial-style so that it would be easy for others to also try it and act as a reminder for me how I did it.

List of software needed:


I assume that you have the Microsoft products installed and ready for use. Download the WinPcap source code and AirPcap dev pack. Both come as ZIP files. Create a new folder where you will be working in. Extract the "winpcap" folder from the WinPcap zip to the working folder (make it as a subfolder), and the "Airpcap_Devpack" folder from the AirPcap zip.

So at this point you should have two folders in the working folder you created.

Compiling the NPF driver

The lowest level component of WinPcap is the virtual device driver. As the name says, you need to use Windows Driver Kit to compile it, so start x64 Free Build Environment from the Windows Driver Kit start-menu group.

The build command prompt opens, navigate to your working folder with usual commands. Go inside winpcap\packetNtx with cd command and type in CompileDriver command. It may list some warnings or defects, but the compilation should finish up successfully. The compiled driver npf.sys can now be found from winpcap\packetNtx\driver\bin\amd64

Compiling Packet.dll

The next component required by WinPcap is the middle level dynamic link library Packet.dll. This is compiled in Visual Studio. Open the project Packet.sln from winpcap\packetNtx\Dll\Project and allow Visual Studio to convert it (assuming you are using VS 200

Select the configuration Release, x64. If you now try to build the solution, it will fail with missing npptools.lib. This is because the file is no longer included in Windows SDK. However, it is part of Windows Driver Kit, so go edit the properties of Release | x64. Under Linker edit the Additional Library Directories and add lib\wnet\amd64 from inside WDK (for example C:\WinDDK\7600.16385.0\lib\wnet\amd64). After that the x64 build should finish without errors.

Since some programs requiring WinPcap might be 32-bit versions, you also want to compile that too, so change to Release | Win32 and do the same change to Linker directories, except this time use the i386 folder instead of amd64.

Compiling wpcap.dll

The last file to compile is the actual high level interface of WinPcap, the file that most applications use for WinPcap, wpcap.dll.

This is also compiled as a Visual Studio project, winpcap\wpcap\PRJ\wpcap.sln (allow VS to convert it)

If you just try to build the Release of either Win32 or x64, it will fail with 12 errors. To fix it, open winpcap\wpcap\libpcap\pcap-stdinc.h for editing. There comment out line 64, so that
Code:

#define vsnprintf _vsnprintf

becomes
Code:

/* #define vsnprintf _vsnprintf */


After doing that change you should be able to build both Win32 and x64 Release configurations.

Installing WinPcap manually

Now that you have the files you need to make them usable by the system.

First copy the npf.sys file into C:\Windows\System32\drivers (or wherever your Windows is installed to), the file can be found from winpcap\packetNtx\driver\bin\amd64 inside the working folder.

Then locate the Packet.dll files from winpcap\packetNtx\Dll\Project\Release. If you compiled both 32 and 64 bit versions, you have two folders there, x86 and x64. Copy the Packet.dll from x86 to C:\Windows\SYSWOW64 and the Packet.dll from x64 to C:\Windows\System32 (yes, the 64-bit file goes to system folder with 32 in the name and the 32-bit file to folder with 64 in the name... ask Microsoft)

The last files are wpcap.dll that you find from winpcap\wpcap\PRJ\Release. Copy the wpcap.dll files to the System folders in the same fashion as Packet.dll files above.

Now all the files are in place. All that is left is letting Windows know the existence of the NPF kernel mode driver to enable WinPcap to work. To do this, open Registry Editor and navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services

There create a new key named "NPF" and insert these values in it (type in parenthesis):

(REG_SZ) DisplayName = NPF (WinPcap manual install)
(REG_DWORD) ErrorControl = 1
(REG_EXPAND_SZ) ImagePath = \SystemRoot\system32\DRIVERS\npf.sys
(REG_DWORD) Start = 2
(REG_DWORD) Type = 1

There's a little problem, though. 64-bit version of Windows 7 does not allow unsigned kernel mode drivers, but the NPF driver of WinPcap is like that, and since you compiled it yourself, it does not have official signature.

This can be bypassed, though. When you start up Windows 7, press F8 to go into boot menu. You can disable the signature checking of drivers from there, allowing Windows to load and use your self-compiled WinPcap driver (you might need to do this on every boot, though)


After that applications requiring WinPcap should work normally, provided they do not have any other incompatibilities with Windows 7. At least you know that your version of WinPcap is specifically compiled for Windows 7 so there wouldn't be any issues 
views: 4497

 

 

 
COMMENTS
 
 
 
 
godjonez (godjonez) 2009-08-10 7:19 AM PDT
Here are the steps on how to allow Windows to load the driver automatically without needing to use the boot menu every time.

The trick is that Windows allows "Test mode" where self-signed kernel drivers are allowed to be loaded without the need for a trusted Certificate Authority. So we turn Windows into test mode and make up a self-signed certificate for the npf.sys file.

First start the x64 Free Build Environment as Administrator (must be full administrator with elevated privilegies if using UAC).

To put Windows into Test mode where test-signed kernel modules are accepted, write in this command:
Code:

bcdedit /set testsigning on

You can review the current boot parameters by writing "bcdedit" without parameters, it should say Testsigning: Yes for the current Operating System.

Now use "cd" and other required commands to navigate to the build folder where npf.sys is (do not do this inside System32\drivers, rather do it in the build folder). First use "makecert" to generate a self-signed certificate file:
Code:

makecert -r -pe -ss PrivateCertStore -n CN=MeAndMyself npf.cer

The command will create a self-signed (-r) exportable (-pe) certificate and store it in PrivateCertStore storage (-ss PrivateCertStore). The certificate will be saved in file npf.cer and is named as MeAndMyself (-n CN=MeAndMyself). Note that self-signed certificate has the "issued to" field the same as the certificate name. So this is your personal certificate, issued to yourself by yourself 

Next you want to apply this certificate to the driver file npf.sys. Use "signtool" for it:
Code:

signtool sign /v /s PrivateC
ertStore /n MeAndMyself /t http://timestamp.verisign.com/scripts/timestamp.dll n
pf.sys

The "sign" parameter tells the action that we want to sign a file, /v turns on verbose output so you see what it does. The certificate named MeAndMyself (/n MeAndMyself) is selected from storage PrivateCertStore (/s PrivateCertStore). The certificate can be timestamped using the online tool from VeriSign (/t http://timestamp.verisign.com/scripts/timestamp.dll) and it will be applied to the file npf.sys.

Now copy this test-signed npf.sys file to System32\drivers and reboot your computer. Since you enabled Test mode using bcdedit, it should now load the driver without any input from the boot menu.

 

内容概要:本文深入探讨了AMESim仿真平台在电动汽车(EV)热泵空调系统设计与优化中的应用。首先介绍了AMESim的基础建模方法,如构建制冷循环模型中的压缩机、蒸发器和冷凝器等组件,并详细解释了各部件的工作原理及其参数设定。接着重点阐述了EV热泵空调系统的特殊之处,即不仅能够制冷还可以在冬季提供高效的制热功能,这对于提高电动汽车在寒冷条件下的续航里程和乘坐舒适性非常重要。文中给出了几个具体的案例,包括通过改变压缩机运行频率来进行性能优化,以及针对低温环境下热泵系统的控制策略,如四通阀切换逻辑、电子膨胀阀开度调节等。此外,还讨论了热泵系统与其他子系统(如电池温控)之间的协同工作方式,强调了系统集成的重要性。最后分享了一些实用的经验技巧,例如如何避免仿真过程中可能出现的问题,怎样评估系统的整体性能等。 适合人群:从事汽车工程、暖通空调(HVAC)领域的研究人员和技术人员,特别是关注新能源汽车热管理系统的专业人士。 使用场景及目标:适用于希望深入了解电动汽车热泵空调系统特性的工程师们,旨在帮助他们掌握基于AMESim进行系统建模、仿真分析的方法论,以便更好地指导实际产品研发。 阅读建议:由于涉及到较多的专业术语和技术细节,建议读者具备一定的机械工程背景知识,同时配合官方文档或其他参考资料一起研读,以加深理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值