wireshark开发环境搭建(windows)

wireshark开发环境搭建(windows)

一、相关链接

【wireshark官网】https://www.wireshark.org

【wireshark源码】https://gitlab.com/wireshark/wireshark/-/tree/master

【wireshark编译指南】https://www.wireshark.org/docs/wsdg_html_chunked/ChSetupWin32.html

二、安装依赖

提示:

  • 请尽量将依赖安装在默认路径,避免不必要的麻烦
  • 如果自定义路径安装,路径最好全英文且不带空格
  • 所有通过命令行执行的步骤,最好都在管理员权限下执行

1.Chocolatey

【chocolatey官网】https://chocolatey.org/install#individual

#1 采用individual方式安装,按win+X,运行power shell(管理员)
#输入Get-ExecutionPolicy,如果得到Restricted,则变更执行策略,如果看到Allsigned,可直接进行安装
Get-ExecutionPolicy
#变更执行策略,如果有提示,输入Y确认变更
Set-ExecutionPolicy AllSigned
#安装
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
#exit
exit
#以管理员身份打开cmd,执行 choco 或 choco -? ,看下是否安装成功
choco -?
#如果需要升级chocolatey执行 
choco upgrade chocolatey
#如果需要卸载安装的程序执行 
choco uninstall xxx
#如果需要查看安装列表执行 
choco list -local-only
#使用choco命令下载的安装包会存在C:\Users\user\AppData\Local\Temp\chocolatey目录

2.VS2022

安装时选择C/C++开发工具,安装在C盘需要6g左右的空间,下载的文件在安装后可以不必保存。

3.QT

【Qt官网】https://www.qt.io/

【下载链接】https://www.qt.io/download-qt-installer

首先注册一个QT账号,然后下载在线安装程序,打开在线安装程序会要求登录,之后选择自定义安装,在Select Components这一步点击Default会帮你勾选默认安装的组件(包含Cmake),然后再勾选QT5.15.2下的MSVC 2019 64-bit,然后进行安装。(大概需要3g的系统盘空间)

添加环境变量,变量名CMAKE_PREFIX_PATH,变量值C:\Qt\5.15.2\msvc2019_64

4.Python3

https://www.python.org/downloads/

5.Perl

http://strawberryperl.com/

6.Git(非必须)

https://git-scm.com/

7.CMake

https://cmake.org/download/

安装至默认目录,并添加环境变量,确保cmake.exe在Path中。

如果已经在VS或者QT中安装过CMake则可以忽略。

8.Asciidoctor, Xsltproc, And DocBook和winflexbison

Asciidoctor依赖于jre,使用Chocolatey来安装Asciidoctorj并不会安装jre,你需要再安装一个匹配版本的jre(推荐安装jdk)。

如果手动安装winflexbison3,要确保win_flex.exe在环境变量Path中。使用choco安装则会自动为你配置好环境变量。

#以管理员方式打开cmd
choco install -y asciidoctorj xsltproc docbook-bundle
choco install -y winflexbison3

三、编译

(1)下载wireshark源码

mkdir C:\Development
cd C:\Development
git clone https://gitlab.com/wireshark/wireshark.git

如果下载速度太慢,也可以直接进入源码网站打包下载,然后解压到目录C:\Development

(2)编译

#从开始菜单以管理员身份打开x64 Native Tools Command Prompt for VS 2022
#set WIRESHARK_VERSION_EXTRA=-P03 说指定编译版本的后缀,如-P00将会得到wireshark-3.7.0-P00
#set CMAKE_PREFIX_PATH=C:\Qt\6.2.2\msvc2019_64 如果安装QT时未添加环境变量,也可用set指定
mkdir C:\Development\wsbuild64
%comspec% /k "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
set WIRESHARK_BASE_DIR=C:\Development
set WIRESHARK_LIB_DIR=C:\wireshark-win64-libs
set CMAKE_PREFIX_PATH=C:\Qt\6.2.2\msvc2019_64
set WIRESHARK_VERSION_EXTRA=-P00
cd C:\Development\wsbuild64
cmake -G "Visual Studio 17 2022" -A x64 ..\wireshark

msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln

#If compilation fails for suspicious reasons after you changed some source files try to clean the build files by running "msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln" 
#如果编译失败,可以使用以下命令make clean
msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln /t:Clean

#Create User's and Developer's Guide
#(可选)创建User Guide
msbuild /m /p:Configuration=RelWithDebInfo docbook\all_guides.vcxproj

#If you’ve closed the Visual Studio Command Prompt prepare it again. run the following command
#(可选)创建installer安装包
msbuild /m /p:Configuration=RelWithDebInfo nsis_package_prep.vcxproj
msbuild /m /p:Configuration=RelWithDebInfo nsis_package.vcxproj

#to build a Wireshark installer. If you sign your executables you should do so between the “nsis_package_prep” and “nsis_package” steps. run the following command
packaging\nsis\wireshark-win64-{wireshark-version}-myprotocol123.exe

四、可能的错误

1.CMake Error at … NOT find Perl (missing: PERL_EXECUTABLE)

(1)可能是没有安装好Perl,重新安装
(2)Cmake的时候没有以管理员权限执行,以管理员权限打开x64 Native Tools Command Prompt for VS 2022,重新编译
(3)如过是其它依赖包没找到也是一样的,仔细看下安装依赖部分的说明

2.产生的‘C:\DEVELOPMENT\WIRESHARK\WSBUILD64\PACKAGING\NSIS\QT-DLL-MANIFEST.NSH’。无法并行生成项。”

检查C:\Development\wsbuild64\packaging\nsis目录下是否缺少qt-dll-manifest.nsh,如果是,手动添加qt-dll-manifest.nsh文件(注意所在位置确实有指定的这些文件),然后重新执行命令:
msbuild /m /p:Configuration=RelWithDebInfo nsis_package_prep.vcxproj

qt-dll-manifest.nsh

#
# Automatically generated by windeployqt-to-nsis.ps1
#
# Qt version 5.15.2
#
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Core.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Gui.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Multimedia.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Network.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5PrintSupport.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Svg.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5Widgets.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\Qt5WinExtras.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\libGLESV2.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\libEGL.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\d3dcompiler_47.dll"
File "C:\Development\wsbuild64\run\RelWithDebInfo\opengl32sw.dll"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\audio"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\bearer"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\iconengines"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\imageformats"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\mediaservice"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\platforms"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\playlistformats"
File /r "C:\Development\wsbuild64\run\RelWithDebInfo\printsupport"

3.File: “VCREDIST_EXE-NOTFOUND” -> no files found. error MSB8066

Error in script “wireshark.nsi” on line 535 – aborting creation process

解决办法: 修改 C:\Development\wireshark\packaging\nsis\wireshark.nsi 的第535行,注释掉该行或指定一个文件路径。

修改前为:File "${VCREDIST_EXE}"

; C-runtime redistributable
; vcredist_x64.exe or vc_redist_x86.exe - copy and execute the redistributable installer
File "C:\Qt\vcredist\vcredist_x64.exe"
; If the user already has the redistributable installed they will see a
; Big Ugly Dialog by default, asking if they want to uninstall or repair.
; Ideally we should add a checkbox for this somewhere. In the meantime,
; just do a "quiet" install.

这里指定的是QT中的,VS中的应该也可以:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\v143\vc_redist.x64.exe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值