Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions | Variables
wslua.h File Reference
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <ws_log_defs.h>
#include <wiretap/wtap.h>
#include <wsutil/report_message.h>
#include <wsutil/nstime.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>
#include <epan/packet.h>
#include <epan/strutil.h>
#include <epan/to_str.h>
#include <epan/uat-int.h>
#include <epan/uat.h>
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/proto.h>
#include <epan/epan_dissect.h>
#include <epan/tap.h>
#include <epan/column-utils.h>
#include <wsutil/filesystem.h>
#include <wsutil/wsgcrypt.h>
#include <epan/funnel.h>
#include <epan/tvbparse.h>
#include <epan/epan.h>
#include <epan/expert.h>
#include <epan/exceptions.h>
#include <epan/show_exception.h>
#include <epan/conversation.h>
#include <epan/wslua/declare_wslua.h>

Go to the source code of this file.

Classes

struct  _wslua_tvb
 
struct  _wslua_pinfo
 
struct  _wslua_tvbrange
 
struct  _wslua_tw
 
struct  _wslua_field_t
 
struct  _wslua_expert_field_t
 
struct  _wslua_pref_t
 
struct  _wslua_proto_t
 
struct  _wslua_conv_data_t
 
struct  _wslua_distbl_t
 
struct  _wslua_col_info
 
struct  _wslua_cols
 
struct  _wslua_private_table
 
struct  _wslua_treeitem
 
struct  _wslua_header_field_info
 
struct  _wslua_field_info
 
struct  _wslua_func_saver
 
struct  _wslua_tap
 
struct  _wslua_file
 
struct  _wslua_captureinfo
 
struct  _wslua_rec
 
struct  _wslua_const_rec
 
struct  _wslua_filehandler
 
struct  _wslua_dir
 
struct  _wslua_progdlg
 
struct  tappable_t
 
struct  wslua_ft_types_t
 
struct  wslua_conv_types_t
 
struct  _wslua_attribute_table
 
struct  _wslua_class
 Type for defining new classes. More...
 

Macros

#define WSLUA_INIT_ROUTINES   "init_routines"
 
#define WSLUA_PREFS_CHANGED   "prefs_changed"
 
#define wslua_toint(L, i)   (int) ( lua_tointeger(L,i) )
 
#define wslua_toint32(L, i)   (int32_t) ( lua_tointeger(L,i) )
 
#define wslua_toint64(L, i)   (int64_t) ( lua_tonumber(L,i) )
 
#define wslua_touint64(L, i)   (uint64_t) ( lua_tonumber(L,i) )
 
#define wslua_checkint(L, i)   (int) ( luaL_checkinteger(L,i) )
 
#define wslua_checkint32(L, i)   (int32_t) ( luaL_checkinteger(L,i) )
 
#define wslua_checkint64(L, i)   (int64_t) ( luaL_checknumber(L,i) )
 
#define wslua_checkuint64(L, i)   (uint64_t) ( luaL_checknumber(L,i) )
 
#define wslua_optint(L, i, d)   (int) ( luaL_optinteger(L,i,d) )
 
#define wslua_optint32(L, i, d)   (int32_t) ( luaL_optinteger(L,i,d) )
 
#define wslua_optint64(L, i, d)   (int64_t) ( luaL_optnumber(L,i,d) )
 
#define wslua_optuint64(L, i, d)   (uint64_t) ( luaL_optnumber(L,i,d) )
 
#define wslua_touint(L, i)   (unsigned) ( lua_tounsigned(L,i) )
 
#define wslua_touint32(L, i)   (uint32_t) ( lua_tounsigned(L,i) )
 
#define wslua_checkuint(L, i)   (unsigned) ( luaL_checkunsigned(L,i) )
 
#define wslua_checkuint32(L, i)   (uint32_t) ( luaL_checkunsigned(L,i) )
 
#define wslua_optuint(L, i, d)   (unsigned) ( luaL_optunsigned(L,i,d) )
 
#define wslua_optuint32(L, i, d)   (uint32_t) ( luaL_optunsigned(L,i,d) )
 
#define WSLUA_CLASS_DEFINE(C, check_code)    WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
 
#define WSLUA_CLASS_DEFINE_BASE(C, check_code, retval)
 
#define WSLUA_TYPEOF_FIELD   "__typeof"
 
#define WSLUA_FUNCTION   extern int
 
#define WSLUA_INTERNAL_FUNCTION   extern int
 
#define WSLUA_REGISTER_FUNCTION(name)   { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
 
#define WSLUA_REGISTER   extern int
 
#define WSLUA_METHOD   static int
 
#define WSLUA_CONSTRUCTOR   static int
 
#define WSLUA_ATTR_SET   static int
 
#define WSLUA_ATTR_GET   static int
 
#define WSLUA_METAMETHOD   static int
 
#define WSLUA_METHODS   static const luaL_Reg
 
#define WSLUA_META   static const luaL_Reg
 
#define WSLUA_CLASS_FNREG(class, name)   { #name, class##_##name }
 
#define WSLUA_CLASS_FNREG_ALIAS(class, aliasname, name)   { #aliasname, class##_##name }
 
#define WSLUA_CLASS_MTREG(class, name)   { "__" #name, class##__##name }
 
#define WSLUA_ATTRIBUTES   static const wslua_attribute_table
 
#define WSLUA_ATTRIBUTE_RWREG(class, name)   { #name, class##_get_##name, class##_set_##name }
 
#define WSLUA_ATTRIBUTE_ROREG(class, name)   { #name, class##_get_##name, NULL }
 
#define WSLUA_ATTRIBUTE_WOREG(class, name)   { #name, NULL, class##_set_##name }
 
#define WSLUA_STATELESS_PAIRS_BODY(C)
 
#define WSLUA_ATTRIBUTE_FUNC_SETTER(C, field)
 
#define WSLUA_ATTRIBUTE_GET(C, name, block)
 
#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C, name, member)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
 
#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C, name, member)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
 
#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C, member)    WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
 
#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C, name, block)    WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
 
#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C, name, member)
 
#define WSLUA_ATTRIBUTE_STRING_GETTER(C, member)    WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C, name, member, option)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C, name, member, option)
 
#define WSLUA_ATTRIBUTE_SET(C, name, block)
 
#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C, name, member)
 
#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C, name, member, cast)
 
#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C, member, cast)    WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
 
#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C, field, member, need_free)
 
#define WSLUA_ATTRIBUTE_STRING_SETTER(C, field, need_free)    WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C, field, member, option)
 
#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C, field, member, option)
 
#define WSLUA_ERROR(name, error)   { luaL_error(L, "%s%s", #name ": ", error); }
 
#define WSLUA_ARG_ERROR(name, attr, error)   { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
 
#define WSLUA_OPTARG_ERROR(name, attr, error)   { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
 
#define WSLUA_REG_GLOBAL_BOOL(L, n, v)   { lua_pushboolean(L,v); lua_setglobal(L,n); }
 
#define WSLUA_REG_GLOBAL_STRING(L, n, v)   { lua_pushstring(L,v); lua_setglobal(L,n); }
 
#define WSLUA_REG_GLOBAL_INTEGER(L, n, v)   { lua_pushinteger(L,v); lua_setglobal(L,n); }
 
#define WSLUA_RETURN(i)   return (i)
 
#define WSLUA_API   extern
 
#define NOP   (void)p
 
#define FAIL_ON_NULL(s)   if (! *p) luaL_argerror(L,idx,"null " s)
 
#define FAIL_ON_NULL_OR_EXPIRED(s)
 
#define CLEAR_OUTSTANDING(C, marker, marker_val)
 
#define WSLUA_CLASS_DECLARE(C)
 
#define THROW_LUA_ERROR(...)    THROW_FORMATTED(DissectorError, __VA_ARGS__)
 
#define WRAP_NON_LUA_EXCEPTIONS(code)
 

Typedefs

typedef struct _wslua_field_t wslua_field_t
 
typedef struct _wslua_expert_field_t wslua_expert_field_t
 
typedef struct _wslua_pref_t wslua_pref_t
 
typedef struct _wslua_proto_t wslua_proto_t
 
typedef struct _wslua_conv_data_t wslua_conv_data_t
 
typedef void(* tap_extractor_t) (lua_State *, const void *)
 
typedef wslua_pref_tPref
 
typedef wslua_pref_tPrefs
 
typedef struct _wslua_field_tProtoField
 
typedef struct _wslua_expert_field_tProtoExpert
 
typedef struct _wslua_proto_tProto
 
typedef struct _wslua_distbl_tDissectorTable
 
typedef dissector_handle_t Dissector
 
typedef GByteArray * ByteArray
 
typedef gcry_cipher_hd_t * GcryptCipher
 
typedef struct _wslua_tvbTvb
 
typedef struct _wslua_tvbrangeTvbRange
 
typedef struct _wslua_col_infoColumn
 
typedef struct _wslua_colsColumns
 
typedef struct _wslua_pinfoPinfo
 
typedef struct _wslua_treeitemTreeItem
 
typedef addressAddress
 
typedef nstime_tNSTime
 
typedef int64_t Int64
 
typedef uint64_t UInt64
 
typedef struct _wslua_header_field_infoField
 
typedef struct _wslua_field_infoFieldInfo
 
typedef struct _wslua_tapListener
 
typedef struct _wslua_twTextWindow
 
typedef struct _wslua_progdlgProgDlg
 
typedef struct _wslua_fileFile
 
typedef struct _wslua_captureinfoCaptureInfo
 
typedef struct _wslua_captureinfoCaptureInfoConst
 
typedef struct _wslua_recFrameInfo
 
typedef struct _wslua_const_recFrameInfoConst
 
typedef struct _wslua_filehandlerFileHandler
 
typedef wtap_dumperDumper
 
typedef struct lua_pseudo_headerPseudoHeader
 
typedef tvbparse_tParser
 
typedef tvbparse_wanted_tRule
 
typedef tvbparse_elem_tNode
 
typedef tvbparse_action_t * Shortcut
 
typedef struct _wslua_dirDir
 
typedef struct _wslua_private_tablePrivateTable
 
typedef conversation_tConversation
 
typedef char * Struct
 
typedef struct _wslua_attribute_table wslua_attribute_table
 
typedef struct _wslua_class wslua_class
 Type for defining new classes.
 

Functions

int wslua_reg_attributes (lua_State *L, const wslua_attribute_table *t, bool is_getter)
 Registers attributes for a Lua table.
 
lua_State * wslua_state (void)
 Retrieves the Lua state associated with Wireshark.
 
void wslua_register_classinstance_meta (lua_State *L, const wslua_class *cls_def)
 
void wslua_register_class (lua_State *L, const wslua_class *cls_def)
 
int wslua__concat (lua_State *L)
 Concatenates two objects to a string.
 
bool wslua_toboolean (lua_State *L, int n)
 Converts a Lua value to a boolean.
 
bool wslua_checkboolean (lua_State *L, int n)
 Checks if a Lua value at a given index is a boolean.
 
bool wslua_optbool (lua_State *L, int n, bool def)
 Checks if a Lua value at a given index is a boolean and returns its value, or a default value if not.
 
lua_Integer wslua_tointeger (lua_State *L, int n)
 Converts a Lua value to an integer.
 
int wslua_optboolint (lua_State *L, int n, int def)
 Retrieves an optional boolean or integer value from the Lua stack.
 
const char * wslua_checklstring_only (lua_State *L, int n, size_t *l)
 Checks if the value at the given index is a Lua string and returns it.
 
const char * wslua_checkstring_only (lua_State *L, int n)
 Checks if a Lua value at a given index is a string.
 
void wslua_setfuncs (lua_State *L, const luaL_Reg *l, int nup)
 Set functions in a Lua table.
 
const char * wslua_typeof (lua_State *L, int idx)
 
bool wslua_get_table (lua_State *L, int idx, const char *name)
 
bool wslua_get_field (lua_State *L, int idx, const char *name)
 
int dissect_lua (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 
bool heur_dissect_lua (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
 
expert_fieldwslua_get_expert_field (const int group, const int severity)
 Retrieves an expert field based on group and severity.
 
void wslua_prefs_changed (void)
 Notify Lua scripts that preferences have changed.
 
void proto_register_lua (void)
 Registers the Lua protocol.
 
GString * lua_register_all_taps (void)
 Registers all Lua taps.
 
void wslua_prime_dfilter (epan_dissect_t *edt)
 Prime the dissector filter with a protocol tree.
 
bool wslua_has_field_extractors (void)
 Checks if there are any registered field extractors.
 
void lua_prime_all_fields (proto_tree *tree)
 Primes all fields in the protocol tree.
 
int Proto_commit (lua_State *L)
 Commits protocol changes.
 
TreeItem create_TreeItem (proto_tree *tree, proto_item *item)
 Creates a new TreeItem.
 
void clear_outstanding_FuncSavers (lua_State *L)
 Clears outstanding function savers associated with a Lua state.
 
void Int64_pack (lua_State *L, luaL_Buffer *b, int idx, bool asLittleEndian)
 Packs a 64-bit integer into a Lua string using the specified endianness.
 
int Int64_unpack (lua_State *L, const char *buff, bool asLittleEndian)
 Unpacks a 64-bit integer from a buffer with specified endianness and pushes it onto the Lua stack.
 
void UInt64_pack (lua_State *L, luaL_Buffer *b, int idx, bool asLittleEndian)
 Packs a 64-bit unsigned integer into a Lua string buffer with specified endianness.
 
int UInt64_unpack (lua_State *L, const char *buff, bool asLittleEndian)
 Unpacks a 64-bit unsigned integer from a buffer with specified endianness and pushes it onto the Lua stack.
 
uint64_t getUInt64 (lua_State *L, int i)
 Retrieves a 64-bit unsigned integer from the Lua stack.
 
Tvbpush_Tvb (lua_State *L, tvbuff_t *tvb)
 Pushes a tvbuff_t to the Lua stack as a Tvb object.
 
int push_wsluaTvb (lua_State *L, Tvb t)
 Pushes a Tvb object onto the Lua stack.
 
bool push_TvbRange (lua_State *L, tvbuff_t *tvb, int offset, int len)
 Pushes a TvbRange object onto the Lua stack.
 
void clear_outstanding_Tvb (void)
 Clears all outstanding Tvb objects.
 
void clear_outstanding_TvbRange (void)
 Clears all outstanding TvbRange objects.
 
Pinfopush_Pinfo (lua_State *L, packet_info *p)
 Pushes a packet information structure onto the Lua stack.
 
void clear_outstanding_Pinfo (void)
 Clears all outstanding Pinfo objects.
 
void clear_outstanding_Column (void)
 Clears all outstanding Column objects.
 
void clear_outstanding_Columns (void)
 Clears all outstanding Column objects.
 
void clear_outstanding_PrivateTable (void)
 Clears any outstanding PrivateTable entries.
 
int get_hf_wslua_text (void)
 Retrieves the value of hf_wslua_text.
 
TreeItem push_TreeItem (lua_State *L, proto_tree *tree, proto_item *item)
 Pushes a TreeItem onto the Lua stack.
 
void clear_outstanding_TreeItem (void)
 Clears all outstanding TreeItem objects.
 
FieldInfopush_FieldInfo (lua_State *L, field_info *f)
 Pushes a field information object onto the Lua stack.
 
void clear_outstanding_FieldInfo (void)
 Clears any outstanding FieldInfo structures.
 
void wslua_print_stack (char *s, lua_State *L)
 Prints the stack of a Lua state with a given prefix.
 
void wslua_init (register_cb cb, void *client_data, const char *app_env_var_prefix)
 Initialize Wireshark Lua support.
 
void wslua_early_cleanup (void)
 
void wslua_cleanup (void)
 Cleans up Lua resources.
 
tap_extractor_t wslua_get_tap_extractor (const char *name)
 Retrieves a tap extractor by name.
 
int wslua_set_tap_enums (lua_State *L)
 Set tap enumerations in Lua.
 
ProtoField wslua_is_field_available (lua_State *L, const char *field_abbr)
 
char * wslua_get_actual_filename (const char *fname)
 Retrieves the actual filename with normalized path separators.
 
int wslua_bin2hex (lua_State *L, const uint8_t *data, const unsigned len, const bool lowercase, const char *sep)
 Convert binary data to hexadecimal string.
 
int wslua_hex2bin (lua_State *L, const char *data, const unsigned len, const char *sep)
 Convert hexadecimal string to binary data.
 
int luaopen_rex_pcre2 (lua_State *L)
 Open the Lua library for PCRE2 regular expressions.
 
const char * get_current_plugin_version (void)
 Get the current plugin version.
 
void clear_current_plugin_version (void)
 Clear the current plugin version.
 
int wslua_deregister_heur_dissectors (lua_State *L)
 Deregisters all Lua-based heuristics dissectors.
 
int wslua_deregister_protocols (lua_State *L)
 Deregisters all Lua-based protocol dissectors.
 
int wslua_deregister_dissector_tables (lua_State *L)
 Deregisters all registered dissector tables.
 
int wslua_deregister_listeners (lua_State *L)
 
int wslua_deregister_fields (lua_State *L)
 Deregisters Lua fields.
 
int wslua_deregister_filehandlers (lua_State *L)
 Deregisters file handlers and menus in Wireshark's Lua environment.
 
void wslua_deregister_menus (void)
 Deregisters all menus registered by Wireshark Lua.
 
void wslua_init_wtap_filetypes (lua_State *L)
 Initialize Wireshark Lua file types.
 
const wslua_conv_types_twslua_inspect_convtype_enum (void)
 Retrieves the enumeration of conversation types for Lua inspection.
 

Variables

packet_infolua_pinfo
 
TreeItem lua_tree
 
tvbuff_tlua_tvb
 
bool lua_initialized
 
int lua_dissectors_table_ref
 
int lua_heur_dissectors_table_ref
 
const char * lua_app_env_var_prefix
 
GPtrArray * lua_outstanding_FuncSavers
 
const char * wslua_typeof_unknown
 

Macro Definition Documentation

◆ CLEAR_OUTSTANDING

#define CLEAR_OUTSTANDING (   C,
  marker,
  marker_val 
)
Value:
void clear_outstanding_##C(void) { \
while (outstanding_##C->len) { \
C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
if (p) { \
if (p->marker != marker_val) \
p->marker = marker_val; \
else \
g_free(p); \
} \
} \
}

◆ FAIL_ON_NULL_OR_EXPIRED

#define FAIL_ON_NULL_OR_EXPIRED (   s)
Value:
if (!*p) { \
luaL_argerror(L,idx,"null " s); \
} else if ((*p)->expired) { \
luaL_argerror(L,idx,"expired " s); \
}

◆ WRAP_NON_LUA_EXCEPTIONS

#define WRAP_NON_LUA_EXCEPTIONS (   code)
Value:
{ \
volatile bool has_error = false; \
TRY { \
code \
show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
} CATCH_ALL { \
show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
has_error = true; \
} ENDTRY; \
if (has_error) { lua_error(L); } \
}
#define BoundsError
Definition exceptions.h:25
#define ScsiBoundsError
Definition exceptions.h:84
#define FragmentBoundsError
Definition exceptions.h:57

◆ WSLUA_ATTRIBUTE_FUNC_SETTER

#define WSLUA_ATTRIBUTE_FUNC_SETTER (   C,
  field 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
if (! lua_isfunction(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
if (obj->field##_ref != LUA_NOREF) \
/* there was one registered before, remove it */ \
luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_GET

#define WSLUA_ATTRIBUTE_GET (   C,
  name,
  block 
)
Value:
static int C##_get_##name (lua_State* L) { \
C obj = check##C (L,1); \
block \
return 1; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_get_##name

◆ WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER

#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER (   C,
  name,
  member 
)
Value:
WSLUA_ATTRIBUTE_SET(C,name, { \
if (! lua_isboolean(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
obj->member = lua_toboolean(L,-1); \
})

◆ WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER

#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER (   C,
  name,
  member,
  cast 
)
Value:
WSLUA_ATTRIBUTE_SET(C,name, { \
if (! lua_isinteger(L,-1) ) \
return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
obj->member = (cast) wslua_toint32(L,-1); \
})

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER (   C,
  name,
  member,
  option 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); \
} \
} \
})
Definition wtap_opttypes.h:272

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER (   C,
  field,
  member,
  option 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
} \
g_free(s); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER (   C,
  name,
  member,
  option 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
char* str; \
if ((obj->member) && (obj->member->len > 0)) { \
if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
lua_pushstring(L,str); \
} \
} \
})

◆ WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER (   C,
  field,
  member,
  option 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if ((obj->member) && (obj->member->len > 0)) { \
wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
} \
g_free(s); \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_NAMED_STRING_GETTER

#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER (   C,
  name,
  member 
)
Value:
WSLUA_ATTRIBUTE_GET(C,name, { \
lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
})

◆ WSLUA_ATTRIBUTE_NAMED_STRING_SETTER

#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER (   C,
  field,
  member,
  need_free 
)
Value:
static int C##_set_##field (lua_State* L) { \
C obj = check##C (L,1); \
char* s = NULL; \
if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
s = g_strdup(lua_tostring(L,-1)); \
} else { \
return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
} \
if (obj->member != NULL && need_free) \
g_free((void*) obj->member); \
obj->member = s; \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##field

◆ WSLUA_ATTRIBUTE_SET

#define WSLUA_ATTRIBUTE_SET (   C,
  name,
  block 
)
Value:
static int C##_set_##name (lua_State* L) { \
C obj = check##C (L,1); \
block; \
return 0; \
} \
/* silly little trick so we can add a semicolon after this macro */ \
typedef void __dummy##C##_set_##name

◆ WSLUA_CLASS_DECLARE

#define WSLUA_CLASS_DECLARE (   C)
Value:
extern C to##C(lua_State* L, int idx); \
extern C check##C(lua_State* L, int idx); \
extern C* push##C(lua_State* L, C v); \
extern int C##_register(lua_State* L); \
extern bool is##C(lua_State* L,int i); \
extern C shift##C(lua_State* L,int i)

◆ WSLUA_STATELESS_PAIRS_BODY

#define WSLUA_STATELESS_PAIRS_BODY (   C)
Value:
check##C(L, 1); \
lua_pushcfunction(L, C##_pairs_iter); \
lua_pushvalue(L, 1); \
lua_pushnil(L); \
return 3

◆ wslua_touint

#define wslua_touint (   L,
 
)    (unsigned) ( lua_tounsigned(L,i) )

On Lua 5.3 and later, the unsigned conversions may not be defined (depending on a compatibility define), and they're just casts if they are.

Typedef Documentation

◆ wslua_class

typedef struct _wslua_class wslua_class

Type for defining new classes.

A new class is defined as a Lua table type. Instances of this class are created through pushXxx which sets the appropriate metatable.

Function Documentation

◆ clear_outstanding_FuncSavers()

void clear_outstanding_FuncSavers ( lua_State *  L)
extern

Clears outstanding function savers associated with a Lua state.

Parameters
LThe Lua state to clear function savers for.

◆ clear_outstanding_Tvb()

void clear_outstanding_Tvb ( void  )
extern

Clears all outstanding Tvb objects.

This function removes and frees all Tvb objects from the outstanding_Tvb array.

◆ create_TreeItem()

TreeItem create_TreeItem ( proto_tree tree,
proto_item item 
)
extern

Creates a new TreeItem.

Parameters
treeThe parent proto_tree.
itemThe associated proto_item.
Returns
A newly created TreeItem.

◆ get_current_plugin_version()

const char * get_current_plugin_version ( void  )
extern

Get the current plugin version.

Returns
The current plugin version as a string.

◆ get_hf_wslua_text()

int get_hf_wslua_text ( void  )
extern

Retrieves the value of hf_wslua_text.

Returns
The value of hf_wslua_text.

◆ getUInt64()

uint64_t getUInt64 ( lua_State *  L,
int  i 
)
extern

Retrieves a 64-bit unsigned integer from the Lua stack.

This function checks the type of the value at the specified index on the Lua stack and converts it to a uint64_t. It supports numbers, strings, and Int64 userdata types.

Parameters
LThe Lua state.
iThe index on the Lua stack where the value is located.
Returns
The 64-bit unsigned integer value.

◆ Int64_pack()

void Int64_pack ( lua_State *  L,
luaL_Buffer *  b,
int  idx,
bool  asLittleEndian 
)
extern

Packs a 64-bit integer into a Lua string using the specified endianness.

Parameters
LThe Lua state.
bThe Lua buffer to add the packed data to.
idxThe index of the integer on the Lua stack.
asLittleEndianWhether to pack in little-endian format.

◆ Int64_unpack()

int Int64_unpack ( lua_State *  L,
const char *  buff,
bool  asLittleEndian 
)
extern

Unpacks a 64-bit integer from a buffer with specified endianness and pushes it onto the Lua stack.

Parameters
LThe Lua state.
buffThe buffer containing the packed integer.
asLittleEndianWhether the integer is packed in little-endian format.
Returns
The number of values pushed onto the Lua stack (1).

◆ lua_prime_all_fields()

void lua_prime_all_fields ( proto_tree tree)
extern

Primes all fields in the protocol tree.

This function primes all fields in the given protocol tree, preparing them for use in Lua scripts.

Parameters
treeThe protocol tree to prime.

◆ lua_register_all_taps()

GString * lua_register_all_taps ( void  )
extern

Registers all Lua taps.

This function registers all Lua taps with Wireshark, enabling Lua scripts to create and use custom taps for packet analysis.

Returns
A GString containing the names of all registered taps.

◆ luaopen_rex_pcre2()

int luaopen_rex_pcre2 ( lua_State *  L)
extern

Open the Lua library for PCRE2 regular expressions.

Parameters
LThe Lua state to register the library with.
Returns
The number of values pushed onto the stack.

◆ Proto_commit()

int Proto_commit ( lua_State *  L)
extern

Commits protocol changes.

This function commits any pending protocol changes made during the current Lua script execution.

Parameters
LThe Lua state.
Returns
0 on success, non-zero on failure.

◆ proto_register_lua()

void proto_register_lua ( void  )
extern

Registers the Lua protocol.

This function registers the Lua protocol with Wireshark, allowing Lua scripts to define and use custom protocols.

◆ push_FieldInfo()

FieldInfo * push_FieldInfo ( lua_State *  L,
field_info f 
)
extern

Pushes a field information object onto the Lua stack.

Parameters
LThe Lua state.
fThe field information to push.
Returns
A pointer to the pushed field information.

◆ push_Pinfo()

Pinfo * push_Pinfo ( lua_State *  L,
packet_info p 
)
extern

Pushes a packet information structure onto the Lua stack.

Parameters
LThe Lua state.
pThe Wireshark packet information structure.
Returns
A pointer to the pushed packet information structure.

◆ push_TreeItem()

TreeItem push_TreeItem ( lua_State *  L,
proto_tree tree,
proto_item item 
)
extern

Pushes a TreeItem onto the Lua stack.

Parameters
LThe Lua state.
treeThe protocol tree associated with the item.
itemThe protocol item to push.
Returns
A pointer to the pushed TreeItem on the Lua stack.

◆ push_Tvb()

Tvb * push_Tvb ( lua_State *  L,
tvbuff_t tvb 
)
extern

Pushes a tvbuff_t to the Lua stack as a Tvb object.

Parameters
LThe Lua state.
tvbThe tvbuff_t to push.
Returns
A pointer to the pushed Tvb object.

◆ push_TvbRange()

bool push_TvbRange ( lua_State *  L,
tvbuff_t tvb,
int  offset,
int  len 
)
extern

Pushes a TvbRange object onto the Lua stack.

Parameters
LThe Lua state.
tvbThe tvbuff_t object.
offsetThe offset within the tvbuff_t.
lenThe length of the range to push.
Returns
true If successful, false otherwise.

◆ push_wsluaTvb()

int push_wsluaTvb ( lua_State *  L,
Tvb  t 
)
extern

Pushes a Tvb object onto the Lua stack.

Parameters
LThe Lua state.
tThe Tvb object to push.
Returns
An integer indicating success or failure of the push operation.

◆ UInt64_pack()

void UInt64_pack ( lua_State *  L,
luaL_Buffer *  b,
int  idx,
bool  asLittleEndian 
)
extern

Packs a 64-bit unsigned integer into a Lua string buffer with specified endianness.

Parameters
LThe Lua state.
bThe Lua buffer to pack the integer into.
idxThe index of the integer in the Lua stack.
asLittleEndianWhether to pack the integer in little-endian format.

◆ UInt64_unpack()

int UInt64_unpack ( lua_State *  L,
const char *  buff,
bool  asLittleEndian 
)
extern

Unpacks a 64-bit unsigned integer from a buffer with specified endianness and pushes it onto the Lua stack.

Parameters
LThe Lua state.
buffThe buffer containing the packed unsigned integer.
asLittleEndianWhether the unsigned integer is packed in little-endian format.
Returns
The number of values pushed onto the Lua stack (1).

◆ wslua__concat()

int wslua__concat ( lua_State *  L)
extern

Concatenates two objects to a string.

This function attempts to convert the first and second arguments to strings using the __tostring metamethod, and then concatenates them. If the metamethod is not available, it pushes the value as is.

Parameters
LThe Lua state.
Returns
Number of values on the stack (1).

◆ wslua_bin2hex()

int wslua_bin2hex ( lua_State *  L,
const uint8_t *  data,
const unsigned  len,
const bool  lowercase,
const char *  sep 
)
extern

Convert binary data to hexadecimal string.

Converts a given binary data buffer into a hexadecimal string representation.

Parameters
LLua state.
dataPointer to the binary data.
lenLength of the binary data.
lowercaseIf true, use lowercase letters in the output; otherwise, use uppercase.
sepSeparator between bytes in the output string.
Returns
Number of values pushed onto the Lua stack.

◆ wslua_checkboolean()

bool wslua_checkboolean ( lua_State *  L,
int  n 
)
extern

Checks if a Lua value at a given index is a boolean.

This function checks if the value at the specified index is a boolean or nil.

Parameters
LThe Lua state.
nThe index of the value to check.
Returns
bool True if the value is a boolean or nil, false otherwise.

◆ wslua_checklstring_only()

const char * wslua_checklstring_only ( lua_State *  L,
int  n,
size_t *  l 
)
extern

Checks if the value at the given index is a Lua string and returns it.

Parameters
LThe Lua state.
nThe index of the value to check.
lA pointer to store the length of the string.
Returns
The checked Lua string, or throws an error if not a string.

◆ wslua_checkstring_only()

const char * wslua_checkstring_only ( lua_State *  L,
int  n 
)
extern

Checks if a Lua value at a given index is a string.

Parameters
LThe Lua state.
nThe index of the value to check.
Returns
const char* The string value, or NULL if not a string.

◆ wslua_cleanup()

void wslua_cleanup ( void  )
extern

Cleans up Lua resources.

This function closes the Lua state if it exists and resets initialization flags.

◆ wslua_deregister_dissector_tables()

int wslua_deregister_dissector_tables ( lua_State *  L)
extern

Deregisters all registered dissector tables.

This function iterates through all registered dissector tables and deregisters them.

Parameters
LThe Lua state.
Returns
0 on success.

◆ wslua_deregister_fields()

int wslua_deregister_fields ( lua_State *  L)
extern

Deregisters Lua fields.

Parameters
LThe Lua state.
Returns
Number of values on the stack.

◆ wslua_deregister_filehandlers()

int wslua_deregister_filehandlers ( lua_State *  L)
extern

Deregisters file handlers and menus in Wireshark's Lua environment.

This function is responsible for cleaning up resources associated with file handlers and menus registered by Lua scripts.

Parameters
LThe Lua state from which to deregister the file handlers.

◆ wslua_deregister_heur_dissectors()

int wslua_deregister_heur_dissectors ( lua_State *  L)
extern

Deregisters all Lua-based heuristics dissectors.

This function iterates through all registered heuristic dissectors and removes them from the system.

Parameters
LThe Lua state.
Returns
0 on success, non-zero on failure.

◆ wslua_deregister_menus()

void wslua_deregister_menus ( void  )
extern

Deregisters all menus registered by Wireshark Lua.

This function is responsible for removing all menu items that were previously registered by Wireshark's Lua scripting interface.

◆ wslua_deregister_protocols()

int wslua_deregister_protocols ( lua_State *  L)
extern

Deregisters all Lua-based protocol dissectors.

This function iterates through all registered protocol dissectors and removes them from the system.

Parameters
LThe Lua state.
Returns
0 on success, non-zero on failure.

◆ wslua_get_actual_filename()

char * wslua_get_actual_filename ( const char *  fname)
extern

Retrieves the actual filename with normalized path separators.

Parameters
fnameThe original filename to process.
Returns
A new string containing the cleaned and normalized filename, or NULL if the file does not exist.

◆ wslua_get_expert_field()

expert_field * wslua_get_expert_field ( const int  group,
const int  severity 
)
extern

Retrieves an expert field based on group and severity.

Parameters
groupThe group of the expert field.
severityThe severity level of the expert field.
Returns
A pointer to the expert field if found, otherwise a pointer to an error field.

◆ wslua_get_tap_extractor()

tap_extractor_t wslua_get_tap_extractor ( const char *  name)
extern

Retrieves a tap extractor by name.

Parameters
nameThe name of the tap extractor to retrieve.
Returns
A pointer to the tap extractor, or NULL if not found.

◆ wslua_has_field_extractors()

bool wslua_has_field_extractors ( void  )
extern

Checks if there are any registered field extractors.

Returns
true if there are registered field extractors, false otherwise.

◆ wslua_hex2bin()

int wslua_hex2bin ( lua_State *  L,
const char *  data,
const unsigned  len,
const char *  sep 
)
extern

Convert hexadecimal string to binary data.

Parameters
LLua state.
dataHexadecimal string to convert.
lenLength of the hexadecimal string.
sepSeparator between bytes (optional).
Returns
Number of bytes written to the buffer or -1 on error.

◆ wslua_init()

void wslua_init ( register_cb  cb,
void *  client_data,
const char *  app_env_var_prefix 
)
extern

Initialize Wireshark Lua support.

Registers a callback function and initializes various components for Wireshark Lua.

Parameters
cbCallback function to be registered.
client_dataData to be passed to the callback function.
app_env_var_prefixPrefix for application environment variables.

◆ wslua_init_wtap_filetypes()

void wslua_init_wtap_filetypes ( lua_State *  L)
extern

Initialize Wireshark Lua file types.

This function initializes the Wireshark Lua file types by creating a table indexed by strings, where each entry contains a name and a corresponding file type.

Parameters
LThe Lua state to initialize.

◆ wslua_inspect_convtype_enum()

const wslua_conv_types_t * wslua_inspect_convtype_enum ( void  )
extern

Retrieves the enumeration of conversation types for Lua inspection.

Returns
const wslua_conv_types_t* A pointer to the conversation type enumeration.

◆ wslua_is_field_available()

ProtoField wslua_is_field_available ( lua_State *  L,
const char *  field_abbr 
)
extern

Query field abbr that is defined and bound to a Proto in lua. They are not registered until the end of the initialization.

◆ wslua_optbool()

bool wslua_optbool ( lua_State *  L,
int  n,
bool  def 
)
extern

Checks if a Lua value at a given index is a boolean and returns its value, or a default value if not.

Parameters
LThe Lua state.
nThe index of the value to check.
defThe default value to return if the value is not a boolean.
Returns
The boolean value from the Lua stack, or the default value.

◆ wslua_optboolint()

int wslua_optboolint ( lua_State *  L,
int  n,
int  def 
)
extern

Retrieves an optional boolean or integer value from the Lua stack.

Parameters
LThe Lua state.
nThe index of the value on the stack.
defThe default value if the value is not a boolean or integer.
Returns
The retrieved value, either from the stack or the default.

◆ wslua_prefs_changed()

void wslua_prefs_changed ( void  )
extern

Notify Lua scripts that preferences have changed.

This function is called when Wireshark's preferences are modified, and it notifies any registered Lua scripts about this change.

◆ wslua_prime_dfilter()

void wslua_prime_dfilter ( epan_dissect_t edt)
extern

Prime the dissector filter with a protocol tree.

This function primes the dissector filter with the protocol tree from an epan_dissect_t structure.

Parameters
edtThe epan_dissect_t structure containing the protocol tree to prime the filter with.

◆ wslua_print_stack()

void wslua_print_stack ( char *  s,
lua_State *  L 
)
extern

Prints the stack of a Lua state with a given prefix.

Parameters
sThe prefix string to prepend to each stack entry.
LThe Lua state whose stack is to be printed.

◆ wslua_reg_attributes()

int wslua_reg_attributes ( lua_State *  L,
const wslua_attribute_table t,
bool  is_getter 
)
extern

Registers attributes for a Lua table.

This function registers getter and setter functions for fields in a Lua table.

Parameters
LThe Lua state.
tA pointer to the attribute table containing field names and their corresponding getter and setter functions.
is_getterIf true, registers only the getter functions; if false, registers both getter and setter functions.
Returns
An integer indicating success or failure of the registration process.

◆ wslua_register_class()

void wslua_register_class ( lua_State *  L,
const wslua_class cls_def 
)

Registers a new class for use in Lua with the specified properties. The metatable for the class instance is internally registered with the given name.

This functions basically creates a class (type table) with this structure:

Class = { class_methods } Class.__typeof = "Class" – NOTE: Might be removed in future Class.__metatable = { class_meta } Class.__metatable.__typeof = "Class" – NOTE: Might be removed in future Class.__metatable.__index = function_that_errors_out Class.__metatable.__newindex = function_that_errors_out

It also registers another metatable for class instances (type userdata):

mt = { instance_meta } mt.__typeof = "Class" – will be passed upvalues (see wslua_instancemeta_index_impl). mt.__index = function_that_finds_right_property_or_method_getter mt.__newindex = function_thaon_that_finds_right_property_or_method_setter

For backwards compatibility, introspection is still possible (this detail might be removed in the future though, do not rely on this!):

Class.__metatable.__methods = Class Class.__metatable.__getters = { __typeof = "getter", getter_attrs } Class.__metatable.__setters = { __typeof = "setter", setter_attrs }

◆ wslua_register_classinstance_meta()

void wslua_register_classinstance_meta ( lua_State *  L,
const wslua_class cls_def 
)

Registers the metatable for class instances. See the documentation of wslua_register_class for the exact metatable.

◆ wslua_set_tap_enums()

int wslua_set_tap_enums ( lua_State *  L)
extern

Set tap enumerations in Lua.

Parameters
LThe Lua state.
Returns
Number of values pushed to the stack.

◆ wslua_setfuncs()

void wslua_setfuncs ( lua_State *  L,
const luaL_Reg *  l,
int  nup 
)
extern

Set functions in a Lua table.

Parameters
LThe Lua state.
lArray of function definitions.
nupNumber of upvalues to pass to each function.

◆ wslua_state()

lua_State * wslua_state ( void  )
extern

Retrieves the Lua state associated with Wireshark.

This function returns a pointer to the Lua state used by Wireshark for scripting and extensions.

Returns
A pointer to the lua_State structure representing the Lua state.

◆ wslua_toboolean()

bool wslua_toboolean ( lua_State *  L,
int  n 
)
extern

Converts a Lua value to a boolean.

This function checks if the given Lua value is a boolean or nil, and returns its boolean value. If the value is a number, it converts 0 to false and any other number to true. If the value is neither a boolean nor a number, it raises an error.

Parameters
LThe Lua state.
nThe index of the value on the stack.
Returns
The boolean value.

◆ wslua_tointeger()

lua_Integer wslua_tointeger ( lua_State *  L,
int  n 
)
extern

Converts a Lua value to an integer.

Parameters
LThe Lua state.
nThe index of the value on the stack.
Returns
The integer value.