3 There are a multitude of plugin options available in Wireshark that allow to
4 extend its functionality without changing the source code itself. Using the
5 available APIs gives you the means to do this.
7 Currently plugin APIs are available for dissectors (epan), capture file types
8 (wiretap) and media decoders (codecs). This README focuses primarily on
9 dissector plugins; most of the descriptions are applicable to the other plugin
14 Writing a "plugin" dissector is not very different from writing a standard
15 one. In fact all of the functions described in README.dissector can be
16 used in the plugins exactly as they are used in standard dissectors.
18 (Note, however, that not all OSes on which Wireshark runs can support
21 If you've chosen "foo" as the name of your plugin (typically, that would
22 be a short name for your protocol, in all lower case), the following
23 instructions tell you how to implement it as a plugin. All occurrences
24 of "foo" below should be replaced by the name of your plugin.
26 2. The directory for the plugin, and its files
28 The plugin should be placed in a new plugins/epan/foo directory which should
29 contain at least the following files:
34 The README can be brief but it should provide essential information relevant
35 to developers and users. Optionally AUTHORS and ChangeLog files can be added.
36 Optionally you can add your own plugin.rc.in.
38 And of course the source and header files for your dissector.
40 Examples of these files can be found in plugins/epan/gryphon.
44 For your plugins/epan/foo/CMakeLists.txt file, see the corresponding file in
45 plugins/epan/gryphon. Replace all occurrences of "gryphon" in those files
46 with "foo" and add your source files to the DISSECTOR_SRC variable.
50 Your plugins/epan/foo/plugin.rc.in is the Windows resource template file used
51 to add the plugin specific information as resources to the DLL.
52 If not provided the plugins/plugin.rc.in file will be used.
54 3. Changes to existing Wireshark files
56 There are two ways to add your plugin dissector to the build, as a custom
57 extension or as a permanent addition. The custom extension is easy to
58 configure, but won't be used for inclusion in the distribution if that's
59 your goal. Setting up the permanent addition is somewhat more involved.
63 For CMake builds, either pass the custom plugin dir on the CMake generation
66 CMake ... -DCUSTOM_PLUGIN_SRC_DIR="plugins/epan/foo"
68 or copy the top-level file CMakeListsCustom.txt.example to CMakeListsCustom.txt
69 (also in the top-level source dir) and edit so that CUSTOM_PLUGIN_SRC_DIR is
70 set() to the relative path of your plugin, e.g.
72 set(CUSTOM_PLUGIN_SRC_DIR plugins/epan/foo)
74 and re-run the CMake generation step.
76 To build the plugin, run your normal Wireshark build step.
78 If you want to add the plugin to your own Windows installer add a text
79 file named custom_plugins.txt to the packaging/nsis directory, with a
80 "File" statement for NSIS:
82 File "${STAGING_DIR}\plugins\${MAJOR_VERSION}.${MINOR_VERSION}\epan\foo.dll"
84 3.2 Permanent addition
86 In order to be able to permanently add a plugin take the following steps.
87 You will need to change the following files:
89 packaging/nsis/wireshark.nsi
91 You might also want to search your Wireshark development directory for
92 occurrences of an existing plugin name, in case this document is out of
93 date with the current directory structure. For example,
97 could be used from a shell prompt.
99 3.2.1 Changes to CMakeLists.txt
101 Add your plugin (in alphabetical order) to the PLUGIN_SRC_DIRS:
107 plugins/epan/ethercat
113 3.2.2 Changes to the installers
115 If you want to include your plugin in an installer you have to add lines
116 in the NSIS installer wireshark.nsi file.
118 3.2.2.1 Changes to packaging/nsis/wireshark.nsi
120 Add the relative path of your plugin DLL (in alphabetical order) to the
121 list of "File" statements in the "Dissector Plugins" section:
123 File "${STAGING_DIR}\plugins\${MAJOR_VERSION}.${MINOR_VERSION}\epan\ethercat.dll"
124 File "${STAGING_DIR}\plugins\${MAJOR_VERSION}.${MINOR_VERSION}\epan\foo.dll"
125 File "${STAGING_DIR}\plugins\${MAJOR_VERSION}.${MINOR_VERSION}\epan\gryphon.dll"
126 File "${STAGING_DIR}\plugins\${MAJOR_VERSION}.${MINOR_VERSION}\epan\irda.dll"
128 3.2.2.2 Other installers
130 The PortableApps installer copies plugins from the build directory
131 and should not require configuration.
133 4. Development and plugins on Unix
135 Plugins make some aspects of development easier and some harder.
137 The first thing is that you'll have to run cmake once more to setup your
140 The good news is that if you are working on a single plugin then you will
141 find recompiling the plugin MUCH faster than recompiling a dissector and
142 then linking it back into Wireshark. Use "make plugins" to compile just
145 The bad news is that Wireshark will not use the plugins unless the plugins
146 are installed in one of the places it expects them to find.
148 One way of dealing with this problem is to set an environment variable
149 when running Wireshark: WIRESHARK_RUN_FROM_BUILD_DIRECTORY=1.
151 Another way to deal with this problem is to set up a working root for
152 wireshark, say in $HOME/build/root and build Wireshark to install
155 cmake -D CMAKE_INSTALL_PREFIX=${HOME}/build/root && make install
157 then subsequent rebuilds/installs of your plugin can be accomplished
158 by going to the plugins/foo directory and running
162 5. Update "old style" plugins
164 5.1 How to update an "old style" plugin (since Wireshark 2.5)
166 Plugins need exactly four visible symbols: plugin_version, plugin_want_major,
167 plugin_want_minor and plugin_register. Each plugin is either a codec plugin,
168 libwiretap plugin or libwireshark plugin and the library will call
169 "plugin_register" after loading the plugin. "plugin_register" in turn calls all
170 the hooks necessary to enable the plugin. So if you had two function like so:
172 WS_DLL_PUBLIC void plugin_register(void);
173 WS_DLL_PUBLIC void plugin_reg_handoff(void);
175 void plugin_register(void) {...};
176 void plugin_reg_handoff(void) {...};
178 You'll have to rewrite it as:
180 WS_DLL_PUBLIC void plugin_register(void);
182 static void proto_register_foo(void) {...};
183 static void proto_reg_handoff_foo(void) {...};
185 void plugin_register(void)
187 static proto_plugin plugin_foo;
189 plugin_foo.register_protoinfo = proto_register_foo;
190 plugin_foo.register_handoff = proto_reg_handoff_foo;
191 proto_register_plugin(&plugin_foo);
194 See doc/plugins.example for an example.
196 5.2 How to update an "old style" plugin (using plugin_register and
197 plugin_reg_handoff functions).
199 The plugin registration has changed with the extension of the build
200 scripts. These now generate the additional code needed for plugin
201 encapsulation in plugin.c. When using the new style build scripts,
202 strips the parts outlined below:
204 o Remove the following include statements:
207 #include "moduleinfo.h"
209 o Removed the definition:
211 #ifndef ENABLE_STATIC
212 WS_DLL_PUBLIC_DEF char version[] = VERSION;
215 o Move relevant code from the blocks and delete these functions:
217 #ifndef ENABLE_STATIC
222 #ifndef ENABLE_STATIC
227 This will leave a clean dissector source file without plugin specifics.
229 5.3 How to update an "old style" plugin (using plugin_init function)
231 The plugin registering has changed between 0.10.9 and 0.10.10; everyone
232 is encouraged to update their plugins as outlined below:
234 o Remove following include statements from all plugin sources:
236 #include "plugins/plugin_api.h"
237 #include "plugins/plugin_api_defs.h"
239 o Remove the init function.
241 6 How to plugin related interface options
243 To demonstrate the functionality of the plugin interface options, a
244 demonstration plugin exists (pluginifdemo). To build it using cmake, the
245 build option ENABLE_PLUGIN_IFDEMO has to be enabled.
247 6.1 Implement a plugin GUI menu
249 A plugin (as well as built-in dissectors) may implement a menu within
250 Wireshark to be used to trigger options, start tools, open Websites, ...
252 This menu structure is built using the plugin_if.h interface and its
253 corresponding functions.
255 The menu items all call a callback provided by the plugin, which takes
256 a pointer to the menuitem entry as data. This pointer may be used to
257 provide userdata to each entry. The pointer must utilize WS_DLL_PUBLIC_DEF
258 and has the following structure:
260 WS_DLL_PUBLIC_DEF void
261 menu_cb(ext_menubar_gui_type gui_type, void *gui_data,
267 The menu entries themselves are generated with the following code structure:
269 ext_menu_t * ext_menu, *os_menu = NULL;
271 ext_menu = ext_menubar_register_menu (
272 <your_proto_item>, "Some Menu Entry", true );
273 ext_menubar_add_entry(ext_menu, "Test Entry 1",
274 "This is a tooltip", menu_cb, <user_data>);
275 ext_menubar_add_entry(ext_menu, "Test Entry 2",
276 NULL, menu_cb, <user_data>);
278 os_menu = ext_menubar_add_submenu(ext_menu, "Sub Menu" );
279 ext_menubar_add_entry(os_menu, "Test Entry A",
280 NULL, menu_cb, <user_data>);
281 ext_menubar_add_entry(os_menu, "Test Entry B",
282 NULL, menu_cb, <user_data>);
284 For a more detailed information, please refer to plugin_if.h
286 6.2 Implement interactions with the main interface
288 Due to memory constraints on most platforms, plugin functionality cannot be
289 called directly from a DLL context. Instead special functions will be used,
290 which will implement certain options for plugins to utilize.
292 The following methods exist so far:
294 /* Applies the given filter string as display filter */
295 WS_DLL_PUBLIC void plugin_if_apply_filter
296 (const char * filter_string, bool force);
298 /* Saves the given preference to the main preference storage */
299 WS_DLL_PUBLIC void plugin_if_save_preference
300 (const char * pref_module, const char * pref_key, const char * pref_value);
302 /* Jumps to the given frame number */
303 WS_DLL_PUBLIC void plugin_if_goto_frame(uint32_t framenr);
305 6.3 Implement a plugin specific toolbar
307 A toolbar may be registered which allows implementing an interactive user
308 interaction with the main application. The toolbar is generated using the following
311 ext_toolbar_t * tb = ext_toolbar_register_toolbar("Plugin Interface Demo Toolbar");
313 This registers a toolbar, which will be shown underneath "View->Additional Toolbars" in
314 the main menu, as well as the popup action window when right-clicking on any other tool-
317 It behaves identically to the existing toolbars and can be hidden as well as defined to
318 appear specific to selected profiles. The name with which it is being shown is the given
319 name in this function call.
321 6.3.1 Register elements for the toolbar
323 To add items to the toolbar, 4 different types of elements do exist.
325 * BOOLEAN - a checkbox to select / unselect
326 * BUTTON - a button to click
327 * STRING - a text field with validation options
328 * SELECTOR - a dropdown selection field
330 To add an element to the toolbar, the following function is being used:
332 ext_toolbar_add_entry( ext_toolbar_t * parent, ext_toolbar_item_t type, const char *label,
333 const char *defvalue, const char *tooltip, bool capture_only, GList * value_list,
334 bool is_required, const char * regex, ext_toolbar_action_cb callback, void *user_data)
336 parent_bar - the parent toolbar for this entry, to be registered by ext_toolbar_register_toolbar
337 name - the entry name (the internal used one) for the item, used to send updates to the element
338 label - the entry label (the displayed name) for the item, visible to the user
339 defvalue - the default value for the toolbar element
340 - EXT_TOOLBAR_BOOLEAN - 1 is for a checked element, 0 is unchecked
341 - EXT_TOOLBAR_STRING - Text already entered upon initial display
342 tooltip - a tooltip to be displayed on mouse-over
343 capture_only - entry is only active, if a capture is active
344 callback - the action which will be invoked after the item is activated
345 value_list - a non-null list of values created by ext_toolbar_add_val(), if the item type
346 is EXT_TOOLBAR_SELECTOR
347 valid_regex - a validation regular expression for EXT_TOOLBAR_STRING
348 is_required - a zero entry for EXT_TOOLBAR_STRING is not allowed
349 user_data - a user defined pointer, which will be added to the toolbar callback
351 In case of the toolbar type EXT_TOOLBAR_SELECTOR a value list has to be provided. This list
352 is generated using ext_toolbar_add_val():
355 entries = ext_toolbar_add_val(entries, "1", "ABCD", false );
356 entries = ext_toolbar_add_val(entries, "2", "EFG", false );
357 entries = ext_toolbar_add_val(entries, "3", "HIJ", true );
358 entries = ext_toolbar_add_val(entries, "4", "KLM", false );
360 6.3.2 Callback for activation of an item
362 If an item has been activated, the provided callback is being triggered.
364 void toolbar_cb(void *toolbar_item, void *item_data, void *user_data)
366 For EXT_TOOLBAR_BUTTON the callback is triggered upon a click on the button, for
367 EXT_TOOLBAR_BOOLEAN and EXT_TOOLBAR_SELECTOR the callback is triggered with every change
370 For EXT_TOOLBAR_STRING either the return key has to be hit or the apply button pressed.
372 The parameters of the callback are defined as follows:
374 toolbar_item - an element of the type ext_toolbar_t * representing the item that has been
376 item_data - the data of the item during activation. The content depends on the item type:
377 - EXT_TOOLBAR_BUTTON - the entry is null
378 - EXT_TOOLBAR_BOOLEAN - the entry is 0 if the checkbox is unchecked and 1 if it is checked
379 - EXT_TOOLBAR_STRING - a string representing the context of the textbox. Only valid strings
380 are being passed, it can be safely assumed, that an applied regular expression has
382 - EXT_TOOLBAR_SELECTOR - the value of the selected entry
383 user_data - the data provided during element registration
385 6.3.3 Sending updates to the toolbar items
387 A plugin may send updates to the toolbar entry, using one of the following methods. The parameter
388 silent defines, if the registered toolbar callback is triggered by the update or not.
390 void ext_toolbar_update_value(ext_toolbar_t * entry, void *data, bool silent)
392 - EXT_TOOLBAR_BUTTON, EXT_TOOLBAR_STRING - the displayed text (on the button or in the textbox)
393 are being changed, in that case data is expected to be a string
394 - EXT_TOOLBAR_BOOLEAN - the checkbox value is being changed, to either 0 or 1, in both cases
395 data is expected to be an integer sent by GINT_TO_POINTER(n)
396 - EXT_TOOLBAR_SELECTOR - the display text to be changed. If no element exists with this text,
399 void ext_toolbar_update_data(ext_toolbar_t * entry, void *data, bool silent)
401 - EXT_TOOLBAR_SELECTOR - change the value list to the one provided with data. Attention! this
402 does not change the list stored within the item just the one in the displayed combobox
404 void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, void *data, void *value,
407 - EXT_TOOLBAR_SELECTOR - change the display text for the entry with the provided value. Both
408 data and value must be char * pointer.
413 Ed Warnicke <hagbard@physics.rutgers.edu>
414 Guy Harris <guy@alum.mit.edu>
416 Derived and expanded from the plugin section of README.developers
417 which was originally written by
419 James Coe <jammer@cin.net>
420 Gilbert Ramirez <gram@alumni.rice.edu>
421 Jeff Foster <jfoste@woodward.com>
422 Olivier Abad <oabad@cybercable.fr>
423 Laurent Deniel <laurent.deniel@free.fr>
424 Jaap Keuter <jaap.keuter@xs4all.nl>