11.3. GUI Support

11.3.1. ProgDlg

Creates and manages a modal progress bar. This is intended to be used with coroutines, where a main UI thread controls the progress bar dialog while a background coroutine (worker thread) yields to the main thread between steps. The main thread checks the status of the Cancel button and if it’s not set, returns control to the coroutine.

Figure 11.1. A progress bar in action

wslua progdlg

The legacy (GTK+) user interface displayed this as a separate dialog, hence the “Dlg” suffix. The Qt user interface shows a progress bar inside the main status bar.

11.3.1.1. ProgDlg.new([title], [task])

Creates and displays a new ProgDlg progress bar with a Cancel button and optional title. It is highly recommended that you wrap code that uses a ProgDlg instance because it does not automatically close itself upon encountering an error. Requires a GUI.

11.3.1.2. Example

    if not gui_enabled() then return end

    local p = ProgDlg.new("Constructing", "tacos")

    -- We have to wrap the ProgDlg code in a pcall in case some unexpected
    -- error occurs.
    local ok, errmsg = pcall(function()
            local co = coroutine.create(
                    function()
                            local limit = 100000
                            for i=1,limit do
                                    print("co", i)
                                    coroutine.yield(i/limit, "step "..i.." of "..limit)
                            end
                    end
            )

            -- Whenever coroutine yields, check the status of the cancel button to determine
            -- when to break. Wait up to 20 sec for coroutine to finish.
            local start_time = os.time()
            while coroutine.status(co) ~= 'dead' do
                    local elapsed = os.time() - start_time

                    -- Quit if cancel button pressed or 20 seconds elapsed
                    if p:stopped() or elapsed > 20 then
                            break
                    end

                    local res, val, val2 = coroutine.resume(co)
                    if not res or res == false then
                            if val then
                                    debug(val)
                            end
                            print('coroutine error')
                            break
                    end

                    -- show progress in progress dialog
                    p:update(val, val2)
            end
    end)

    p:close()

    if not ok and errmsg then
            report_failure(errmsg)
    end
Arguments
title (optional)
Title of the progress bar. Defaults to "Progress".
task (optional)
Optional task name, which will be appended to the title. Defaults to the empty string ("").
Returns

The newly created ProgDlg object.

11.3.1.3. progdlg:update(progress, [task])

Sets the progress dialog’s progress bar position based on percentage done.

Arguments
progress
Progress value, e.g. 0.75. Value must be between 0.0 and 1.0 inclusive.
task (optional)
Task name. Currently ignored. Defaults to empty string ("").
Errors
  • GUI not available
  • Cannot be called for something not a ProgDlg
  • Progress value out of range (must be between 0.0 and 1.0)

11.3.1.4. progdlg:stopped()

Checks whether the user has pressed the Cancel button.

Returns

Boolean true if the user has asked to stop the operation, false otherwise.

11.3.1.5. progdlg:close()

Hides the progress bar.

Returns

A string specifying whether the Progress Dialog has stopped or not.

Errors
  • GUI not available

11.3.2. TextWindow

Creates and manages a text window. The text can be read-only or editable, and buttons can be added below the text.

Figure 11.2. A text window in action

wslua textwindow

11.3.2.1. TextWindow.new([title])

Creates a new TextWindow text window and displays it. Requires a GUI.

11.3.2.2. Example

    if not gui_enabled() then return end

    -- create new text window and initialize its text
    local win = TextWindow.new("Log")
    win:set("Hello world!")

    -- add buttons to clear text window and to enable editing
    win:add_button("Clear", function() win:clear() end)
    win:add_button("Enable edit", function() win:set_editable(true) end)

    -- add button to change text to uppercase
    win:add_button("Uppercase", function()
            local text = win:get_text()
            if text ~= "" then
                    win:set(string.upper(text))
            end
    end)

    -- print "closing" to stdout when the user closes the text windw
    win:set_atclose(function() print("closing") end)
Arguments
title (optional)
Title of the new window. Optional. Defaults to "Untitled Window".
Returns

The newly created TextWindow object.

Errors
  • GUI not available

11.3.2.3. textwindow:set_atclose(action)

Set the function that will be called when the text window closes.

Arguments
action
A Lua function to be executed when the user closes the text window.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.4. textwindow:set(text)

Sets the text to be displayed.

Arguments
text
The text to be displayed.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.5. textwindow:append(text)

Appends text to the current window contents.

Arguments
text
The text to be appended.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.6. textwindow:prepend(text)

Prepends text to the current window contents.

Arguments
text
The text to be prepended.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.7. textwindow:clear()

Erases all of the text in the window.

Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.8. textwindow:get_text()

Get the text of the window.

Returns

The `TextWindow’s text.

Errors
  • GUI not available

11.3.2.9. textwindow:close()

Close the window.

Errors
  • GUI not available

11.3.2.10. textwindow:set_editable([editable])

Make this text window editable.

Arguments
editable (optional)
true to make the text editable, false otherwise. Defaults to true.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.2.11. textwindow:add_button(label, function)

Adds a button with an action handler to the text window.

Arguments
label
The button label.
function
The Lua function to be called when the button is pressed.
Returns

The TextWindow object.

Errors
  • GUI not available

11.3.3. Global Functions

11.3.3.1. gui_enabled()

Checks if we’re running inside a GUI (i.e. Wireshark) or not.

Returns

Boolean true if a GUI is available, false if it isn’t.

11.3.3.2. register_menu(name, action, [group])

Register a menu item in one of the main menus. Requires a GUI.

Arguments
name
The name of the menu item. Use slashes to separate submenus. (e.g. Lua ScriptsMy Fancy Statistics). (string)
action
The function to be called when the menu item is invoked. The function must take no arguments and return nothing.
group (optional)

Where to place the item in the menu hierarchy. If omitted, defaults to MENU_STAT_GENERIC. One of:

  • MENU_STAT_UNSORTED: Statistics
  • MENU_STAT_GENERIC: Statistics, first section
  • MENU_STAT_CONVERSATION: StatisticsConversation List
  • MENU_STAT_ENDPOINT: StatisticsEndpoint List
  • MENU_STAT_RESPONSE: StatisticsService Response Time
  • MENU_STAT_TELEPHONY: Telephony
  • MENU_STAT_TELEPHONY_ANSI: TelephonyANSI
  • MENU_STAT_TELEPHONY_GSM: TelephonyGSM
  • MENU_STAT_TELEPHONY_LTE: TelephonyLTE
  • MENU_STAT_TELEPHONY_MTP3: TelephonyMTP3
  • MENU_STAT_TELEPHONY_SCTP: TelephonySCTP
  • MENU_ANALYZE: Analyze
  • MENU_ANALYZE_CONVERSATION: AnalyzeConversation Filter
  • MENU_TOOLS_UNSORTED: Tools

11.3.3.3. new_dialog(title, action, …​)

Displays a dialog, prompting for input. The dialog includes an OK button and Cancel button. Requires a GUI.

Figure 11.3. An input dialog in action

wslua new dialog

11.3.3.4. Example

    if not gui_enabled() then return end

    -- Prompt for IP and port and then print them to stdout
    local label_ip = "IP address"
    local label_port = "Port"
    local function print_ip(ip, port)
            print(label_ip, ip)
            print(label_port, port)
    end
    new_dialog("Enter IP address", print_ip, label_ip, label_port)

    -- Prompt for 4 numbers and then print their product to stdout
    new_dialog(
            "Enter 4 numbers",
            function (a, b, c, d) print(a * b * c * d) end,
            "a", "b", "c", "d"
            )
Arguments
title
The title of the dialog.
action
Action to be performed when the user presses OK.
…​
Strings to be used a labels of the dialog’s fields. Each string creates a new labeled field. The first field is required.
Errors
  • GUI not available
  • At least one field required
  • All fields must be strings

11.3.3.5. retap_packets()

Rescans all packets and runs each tap listener without reconstructing the display.

11.3.3.6. copy_to_clipboard(text)

Copy a string into the clipboard. Requires a GUI.

Arguments
text
The string to be copied into the clipboard.

11.3.3.7. open_capture_file(filename, filter)

Open and display a capture file. Requires a GUI.

Arguments
filename
The name of the file to be opened.
filter
The display filter to be applied once the file is opened.

11.3.3.8. get_filter()

Get the main filter text.

11.3.3.9. set_filter(text)

Set the main filter text.

Arguments
text
The filter’s text.

11.3.3.10. get_color_filter_slot(row)

Gets the current packet coloring rule (by index) for the current session. Wireshark reserves 10 slots for these coloring rules. Requires a GUI.

Arguments
row
The index (1-10) of the desired color filter value in the temporary coloring rules list.

Table 11.1. Default background colors

IndexRGB (hex)Color

1

ffc0c0

pink 1

2

ffc0ff

pink 2

3

e0c0e0

purple 1

4

c0c0ff

purple 2

5

c0e0e0

green 1

6

c0ffff

green 2

7

c0ffc0

green 3

8

ffffc0

yellow 1

9

e0e0c0

yellow 2

10

e0e0e0

gray


11.3.3.11. set_color_filter_slot(row, text)

Sets a packet coloring rule (by index) for the current session. Wireshark reserves 10 slots for these coloring rules. Requires a GUI.

Arguments
row
The index (1-10) of the desired color in the temporary coloring rules list. The default foreground is black and the default backgrounds are listed below.

Table 11.2. Default background colors

IndexRGB (hex)Color

1

ffc0c0

pink 1

2

ffc0ff

pink 2

3

e0c0e0

purple 1

4

c0c0ff

purple 2

5

c0e0e0

green 1

6

c0ffff

green 2

7

c0ffc0

green 3

8

ffffc0

yellow 1

9

e0e0c0

yellow 2

10

e0e0e0

gray


The color list can be set from the command line using two unofficial preferences: gui.colorized_frame.bg and gui.colorized_frame.fg, which require 10 hex RGB codes (6 hex digits each), e.g.

wireshark -o gui.colorized_frame.bg:${RGB0},${RGB1},${RGB2},${RGB3},${RGB4},${RGB5},${RGB6},${RGB7},${RGB8},${RGB9}

For example, this command yields the same results as the table above (and with all foregrounds set to black):

wireshark -o gui.colorized_frame.bg:ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0 -o gui.colorized_frame.fg:000000,000000,000000,000000,000000,000000,000000,000000
text
The display filter for selecting packets to be colorized .

11.3.3.12. apply_filter()

Apply the filter in the main filter box. Requires a GUI.

[Warning]Warning

Avoid calling this from within a dissector function or else an infinite loop can occur if it causes the dissector to be called again. This function is best used in a button callback (from a dialog or text window) or menu callback.

11.3.3.13. reload()

Reload the current capture file. Deprecated. Use reload_packets() instead.

11.3.3.14. reload_packets()

Reload the current capture file. Requires a GUI.

[Warning]Warning

Avoid calling this from within a dissector function or else an infinite loop can occur if it causes the dissector to be called again. This function is best used in a button callback (from a dialog or text window) or menu callback.

11.3.3.15. reload_lua_plugins()

Reload all Lua plugins.

11.3.3.16. browser_open_url(url)

Opens an URL in a web browser. Requires a GUI.

[Warning]Warning

Do not pass an untrusted URL to this function.

It will be passed to the system’s URL handler, which might execute malicious code, switch on your Bluetooth-connected foghorn, or any of a number of unexpected or harmful things.

Arguments
url
The url.

11.3.3.17. browser_open_data_file(filename)

Open a file located in the data directory (specified in the Wireshark preferences) in the web browser. If the file does not exist, the function silently ignores the request. Requires a GUI.

[Warning]Warning

Do not pass an untrusted URL to this function.

It will be passed to the system’s URL handler, which might execute malicious code, switch on your Bluetooth-connected foghorn, or any of a number of unexpected or harmful things.

Arguments
filename
The file name.