Chapter 12. Wireshark’s Lua API Reference Manual

Table of Contents

12.1. Utility Functions
12.1.1. Global Functions
12.2. GUI Support
12.2.1. ProgDlg
12.2.2. TextWindow
12.2.3. Global Functions
12.3. Functions For New Protocols And Dissectors
12.3.1. Dissector
12.3.2. DissectorTable
12.3.3. Pref
12.3.4. Prefs
12.3.5. Proto
12.3.6. ProtoExpert
12.3.7. ProtoField
12.3.8. Global Functions
12.4. Obtaining Dissection Data
12.4.1. Field
12.4.2. FieldInfo
12.4.3. Global Functions
12.5. Obtaining Packet Information
12.5.1. Address
12.5.2. Column
12.5.3. Columns
12.5.4. Conversation
12.5.5. NSTime
12.5.6. Pinfo
12.5.7. PrivateTable
12.6. Functions For Handling Packet Data
12.6.1. ByteArray
12.6.2. Tvb
12.6.3. TvbRange
12.7. Adding Information To The Dissection Tree
12.7.1. TreeItem
12.8. Post-Dissection Packet Analysis
12.8.1. Listener
12.9. Saving Capture Files
12.9.1. Dumper
12.9.2. PseudoHeader
12.10. Wtap Functions For Handling Capture File Types
12.10.1. Global Functions
12.11. Custom File Format Reading And Writing
12.11.1. CaptureInfo
12.11.2. CaptureInfoConst
12.11.3. File
12.11.4. FileHandler
12.11.5. FrameInfo
12.11.6. FrameInfoConst
12.11.7. Global Functions
12.12. Directory Handling Functions
12.12.1. Dir
12.12.2. Example
12.12.3. Example
12.13. Handling 64-bit Integers
12.13.1. Int64
12.13.2. UInt64
12.14. Binary encode/decode support
12.14.1. Struct
12.15. Gcrypt symmetric cipher functions
12.15.1. GcryptCipher
12.15.2. Global Functions
12.16. PCRE2 Regular Expressions
12.17. Bitwise Operations

This Part of the User Guide describes the Wireshark specific functions in the embedded Lua.

Classes group certain functionality, the following notational conventions are used:

Trying to access a non-existing property, function or method currently gives an error, but do not rely on it as the behavior may change in the future.

12.1. Utility Functions

12.1.1. Global Functions

12.1.1.1. get_version()

Gets the Wireshark version as a string.

Returns

The version string, e.g. "3.2.5".

12.1.1.2. ssl_starttls_ack(tls_handle, pinfo, app_handle)

TLS protocol will be started after this fame

Arguments
tls_handle
the tls dissector
pinfo
The packet’s Pinfo.
app_handle
The app dissector

12.1.1.3. ssl_starttls_post_ack(tls_handle, pinfo, app_handle)

TLS protocol is started with this frame

Arguments
tls_handle
the tls dissector
pinfo
The packet’s Pinfo.
app_handle
The app dissector

12.1.1.4. set_plugin_info(table)

Set a Lua table with meta-data about the plugin, such as version.

The passed-in Lua table entries need to be keyed/indexed by the following:

  • "version" with a string value identifying the plugin version (required)
  • "description" with a string value describing the plugin (optional)
  • "author" with a string value of the author’s name(s) (optional)
  • "repository" with a string value of a URL to a repository (optional)

Not all of the above key entries need to be in the table. The 'version' entry is required, however. The others are not currently used for anything, but might be in the future and thus using them might be useful. Table entries keyed by other strings are ignored, and do not cause an error.

12.1.1.5. Example

    local my_info = {
        version = "1.0.1",
        author = "Jane Doe",
        repository = "https://github.com/octocat/Spoon-Knife"
    }

    set_plugin_info(my_info)
Arguments
table
The Lua table of information.

12.1.1.6. format_date(timestamp)

Formats an absolute timestamp into a human readable date.

Arguments
timestamp
A timestamp value to convert.
Returns

A string with the formated date

12.1.1.7. format_time(timestamp)

Formats a relative timestamp in a human readable time.

Arguments
timestamp
A timestamp value to convert.
Returns

A string with the formated time

12.1.1.8. get_preference(preference)

Get a preference value.

Arguments
preference
The name of the preference.
Returns

The preference value, or nil if not found.

12.1.1.9. set_preference(preference, value)

Set a preference value.

Arguments
preference
The name of the preference.
value
The preference value to set.
Returns

true if changed, false if unchanged or nil if not found.

12.1.1.10. reset_preference(preference)

Reset a preference to default value.

Arguments
preference
The name of the preference.
Returns

true if valid preference

12.1.1.11. apply_preferences()

Write preferences to file and apply changes.

12.1.1.12. report_failure(text)

Reports a failure to the user.

Arguments
text
Message text to report.

12.1.1.13. dofile(filename)

Loads a Lua file and executes it as a Lua chunk, similar to the standard dofile but searches additional directories. The search order is the current directory, followed by the user’s personal configuration directory, and finally the global configuration directory.

[Tip]The configuration directories are not the plugin directories.

The configuration directories searched are not the global and personal plugin directories. All Lua files in the plugin directories are loaded at startup; dofile is for loading files from additional locations. The file path can be absolute or relative to one of the search directories.

Arguments
filename
Name of the file to be run. If the file does not exist in the current directory, the user and system directories are searched.

12.1.1.14. loadfile(filename)

Loads a Lua file and compiles it into a Lua chunk, similar to the standard loadfile but searches additional directories. The search order is the current directory, followed by the user’s personal configuration directory, and finally the global configuration directory.

12.1.1.15. Example

    -- Assume foo.lua contains definition for foo(a,b). Load the chunk
    -- from the file and execute it to add foo(a,b) to the global table.
    -- These two lines are effectively the same as dofile('foo.lua').
    local loaded_chunk = assert(loadfile('foo.lua'))
    loaded_chunk()

    -- ok to call foo at this point
    foo(1,2)
Arguments
filename
Name of the file to be loaded. If the file does not exist in the current directory, the user and system directories are searched.

12.1.1.16. register_stat_cmd_arg(argument, [action])

Register a function to handle a -z option

Arguments
argument
The name of the option argument.
action (optional)
The function to be called when the command is invoked.