To demonstrate the functionality of the plugin interface options, a
demonstration plugin exists named "pluginifdemo". To build it using CMake, the
build option ENABLE_PLUGIN_IFDEMO
has to be enabled.
Plugins (as well as built-in dissectors) may implement menus within Wireshark which can be used to trigger options, start tools, open Websites, and other actions.
This menu structure is built using the plugin_if.h interface and its corresponding functions.
The menu items all call a callback provided by the plugin, which takes a pointer to the menuitem entry as data. This pointer may be used to provide userdata to each entry. The pointer must utilize WS_DLL_PUBLIC_DEF and has the following structure:
WS_DLL_PUBLIC_DEF void menu_cb(ext_menubar_gui_type gui_type, void *gui_data, void *user_data _U_) { ... Do something ... }
The menu entries themselves are generated with the following code structure:
ext_menu_t * ext_menu, *os_menu = NULL; ext_menu = ext_menubar_register_menu ( <your_proto_item>, "Some Menu Entry", true ); ext_menubar_add_entry(ext_menu, "Test Entry 1", "This is a tooltip", menu_cb, <user_data>); ext_menubar_add_entry(ext_menu, "Test Entry 2", NULL, menu_cb, <user_data>); os_menu = ext_menubar_add_submenu(ext_menu, "Sub Menu" ); ext_menubar_add_entry(os_menu, "Test Entry A", NULL, menu_cb, <user_data>); ext_menubar_add_entry(os_menu, "Test Entry B", NULL, menu_cb, <user_data>);
For a more detailed information, please refer to plugin_if.h.
Due to memory constraints on most platforms, plugin functionality cannot be called directly from a DLL context. Instead special functions will be used, which will implement certain options for plugins to utilize.
The following methods exist so far:
/* Applies the given filter string as display filter */ WS_DLL_PUBLIC void plugin_if_apply_filter (const char * filter_string, bool force); /* Saves the given preference to the main preference storage */ WS_DLL_PUBLIC void plugin_if_save_preference (const char * pref_module, const char * pref_key, const char * pref_value); /* Jumps to the given frame number */ WS_DLL_PUBLIC void plugin_if_goto_frame(uint32_t framenr);
A toolbar may be registered which allows implementing an interactive user interaction with the main application. The toolbar is generated using the following code:
ext_toolbar_t * tb = ext_toolbar_register_toolbar("Plugin Interface Demo Toolbar");
This registers a toolbar, which will be shown underneath "View→Additional Toolbars" in the main menu, as well as the popup action window when right-clicking on any other tool- or menubar.
It behaves identically to the existing toolbars and can be hidden as well as defined to appear specific to selected profiles. The name with which it is being shown is the given name in this function call.
To add items to the toolbar, 4 different types of elements do exist.
To add an element to the toolbar, the following function can be used:
ext_toolbar_add_entry( ext_toolbar_t * parent, ext_toolbar_item_t type, const char *label, const char *defvalue, const char *tooltip, bool capture_only, GList * value_list, bool is_required, const char * regex, ext_toolbar_action_cb callback, void *user_data) parent_bar - the parent toolbar for this entry, to be registered by ext_toolbar_register_toolbar name - the entry name (the internal used one) for the item, used to send updates to the element label - the entry label (the displayed name) for the item, visible to the user defvalue - the default value for the toolbar element - EXT_TOOLBAR_BOOLEAN - 1 is for a checked element, 0 is unchecked - EXT_TOOLBAR_STRING - Text already entered upon initial display tooltip - a tooltip to be displayed on mouse-over capture_only - entry is only active, if a capture is active callback - the action which will be invoked after the item is activated value_list - a non-null list of values created by ext_toolbar_add_val(), if the item type is EXT_TOOLBAR_SELECTOR valid_regex - a validation regular expression for EXT_TOOLBAR_STRING is_required - a zero entry for EXT_TOOLBAR_STRING is not allowed user_data - a user defined pointer, which will be added to the toolbar callback
In case of the toolbar type EXT_TOOLBAR_SELECTOR a value list has to be provided. This list is generated using ext_toolbar_add_val():
GList * entries = 0; entries = ext_toolbar_add_val(entries, "1", "ABCD", false ); entries = ext_toolbar_add_val(entries, "2", "EFG", false ); entries = ext_toolbar_add_val(entries, "3", "HIJ", true ); entries = ext_toolbar_add_val(entries, "4", "KLM", false );
If an item has been activated, the provided callback is being triggered.
void toolbar_cb(void *toolbar_item, void *item_data, void *user_data)
For EXT_TOOLBAR_BUTTON the callback is triggered upon a click on the button, for EXT_TOOLBAR_BOOLEAN and EXT_TOOLBAR_SELECTOR the callback is triggered with every change of the selection.
For EXT_TOOLBAR_STRING either the return key has to be hit or the apply button pressed.
The parameters of the callback are defined as follows:
A plugin may send updates to the toolbar entry, using one of the following methods. The parameter silent defines, if the registered toolbar callback is triggered by the update or not.
void ext_toolbar_update_value(ext_toolbar_t * entry, void *data, bool silent)
void ext_toolbar_update_data(ext_toolbar_t * entry, void *data, bool silent)
void ext_toolbar_update_data_by_index(ext_toolbar_t * entry, void *data, void *value, bool silent)