Skip to content

Instantly share code, notes, and snippets.

@u130b8
Created May 14, 2024 19:53
Show Gist options
  • Select an option

  • Save u130b8/806ed627b95567ec8dbcc9477802f619 to your computer and use it in GitHub Desktop.

Select an option

Save u130b8/806ed627b95567ec8dbcc9477802f619 to your computer and use it in GitHub Desktop.
Build Wireshark plugins on Windows without CMake and Qt
@echo off
setlocal EnableDelayedExpansion
set DIR_ROOT=%~dp0.
set DIR_SRC=%DIR_ROOT%\src
set DIR_BUILD=%DIR_ROOT%\build
set DIR_WIRESHARK=%DIR_BUILD%\wireshark
set DIR_WINFLEXBISON=%DIR_BUILD%\winflexbison
set DIR_WIRESHARK_X64_LIBS=%DIR_BUILD%\wireshark-x64-libs
set DIR_WSBUILD64=%DIR_BUILD%\wsbuild64
set DIR_PLUGINSDK=%DIR_BUILD%\pluginsdk
if not exist "%DIR_BUILD%" ( mkdir "%DIR_BUILD%" )
if not exist "%DIR_WIRESHARK%" (
mkdir "%DIR_WIRESHARK%"
pushd "%DIR_WIRESHARK%"
git clone --depth=1 https://gitlab.com/wireshark/wireshark.git .
popd
)
if not exist "%DIR_WINFLEXBISON%" (
mkdir "%DIR_WINFLEXBISON%"
pushd "%DIR_WINFLEXBISON%"
curl -L -o winflexbison.zip https://github.com/lexxmark/winflexbison/releases/download/v2.5.25/win_flex_bison-2.5.25.zip
7z x winflexbison.zip
popd
)
if not exist "%DIR_WIRESHARK_X64_LIBS%" ( mkdir "%DIR_WIRESHARK_X64_LIBS%" )
if not exist "%DIR_WSBUILD64%" (
mkdir "%DIR_WSBUILD64%"
pushd "%DIR_WSBUILD64%"
set WIRESHARK_LIB_DIR=%DIR_WIRESHARK_X64_LIBS%
cmake ^
-DBUILD_wireshark=off ^
-DLEX_EXECUTABLE="%DIR_WINFLEXBISON%\win_flex.exe" ^
-G "Visual Studio 17 2022" ^
-A x64 ^
"%DIR_WIRESHARK%"
msbuild /m /p:Configuration=RelWithDebInfo Wireshark.sln
popd
)
if not exist "%DIR_PLUGINSDK%" (
mkdir "%DIR_PLUGINSDK%"
pushd "%DIR_PLUGINSDK%"
mkdir "%DIR_PLUGINSDK%\include"
mkdir "%DIR_PLUGINSDK%\lib"
for /d %%d in ("%DIR_WIRESHARK_X64_LIBS%\vcpkg-*") do (
robocopy /s "%%d\installed\x64-windows\include\glib-2.0" "%DIR_PLUGINSDK%\include" *.h >nul 2>&1
robocopy /s "%%d\installed\x64-windows\lib\glib-2.0\include" "%DIR_PLUGINSDK%\include" *.h >nul 2>&1
)
robocopy /s "%DIR_WIRESHARK%" "%DIR_PLUGINSDK%\include" *.h >nul 2>&1
rmdir /s /q "%DIR_PLUGINSDK%\include\include"
robocopy /s "%DIR_WIRESHARK%\include" "%DIR_PLUGINSDK%\include" *.h >nul 2>&1
robocopy "%DIR_WSBUILD64%" "%DIR_PLUGINSDK%\include" *.h >nul 2>&1
robocopy "%DIR_WSBUILD64%\run\RelWithDebInfo" "%DIR_PLUGINSDK%\lib" wireshark.lib >nul 2>&1
popd
)
pushd "%DIR_BUILD%"
cl /nologo /utf-8 /W3 /WX /MP /std:c11 ^
"%DIR_SRC%\main.c" ^
/I"%DIR_PLUGINSDK%\include" ^
/link /DLL /OUT:foo.dll ^
/LIBPATH:"%DIR_PLUGINSDK%\lib" ^
wireshark.lib || exit /b 1
popd
#define WS_BUILD_DLL
#include <wireshark.h>
#include <wsutil/plugins.h>
#include <epan/packet.h>
#include <epan/proto.h>
WS_DLL_PUBLIC_DEF const char plugin_version[] = "0.0.0";
WS_DLL_PUBLIC_DEF const int plugin_want_major = WIRESHARK_VERSION_MAJOR;
WS_DLL_PUBLIC_DEF const int plugin_want_minor = WIRESHARK_VERSION_MINOR;
WS_DLL_PUBLIC void plugin_register(void);
WS_DLL_PUBLIC uint32_t plugin_describe(void);
#define FOO_PORT 1234
static int proto_foo;
static int dissect_foo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_) {
col_set_str(pinfo->cinfo, COL_PROTOCOL, "FOO");
/* Clear the info column */
col_clear(pinfo->cinfo,COL_INFO);
return tvb_captured_length(tvb);
}
static void foo_register_protoinfo(void) {
proto_foo = proto_register_protocol (
"FOO Protocol", /* name */
"FOO", /* short_name */
"foo" /* filter_name */
);
}
static void foo_register_handoff(void) {
static dissector_handle_t foo_handle;
foo_handle = create_dissector_handle(dissect_foo, proto_foo);
dissector_add_uint("udp.port", FOO_PORT, foo_handle);
}
void plugin_register() {
static proto_plugin plug;
plug.register_protoinfo = foo_register_protoinfo;
plug.register_handoff = foo_register_handoff;
proto_register_plugin(&plug);
}
uint32_t plugin_describe() {
return WS_PLUGIN_DESC_DISSECTOR;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment