Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
wslua.h
Go to the documentation of this file.
1/*
2 * wslua.h
3 *
4 * Wireshark's interface to the Lua Programming Language
5 *
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2007, Tamas Regos <tamas.regos@ericsson.com>
8 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
9 * (c) 2025, Bartis Csaba <bracsek@bracsek.eu>
10 *
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
14 *
15 * SPDX-License-Identifier: GPL-2.0-or-later
16 */
17
18#ifndef _PACKET_LUA_H
19#define _PACKET_LUA_H
20
21#include <glib.h>
22#include <stdlib.h>
23#include <string.h>
24#include <math.h>
25#include <lua.h>
26#include <lualib.h>
27#include <lauxlib.h>
28
29#include <ws_log_defs.h>
30
31#include <wiretap/wtap.h>
32
34#include <wsutil/nstime.h>
35#include <wsutil/ws_assert.h>
36#include <wsutil/wslog.h>
37
38#include <epan/packet.h>
39#include <epan/strutil.h>
40#include <epan/to_str.h>
41#include <epan/uat-int.h>
42#include <epan/uat.h>
43#include <epan/prefs.h>
44#include <epan/prefs-int.h>
45#include <epan/proto.h>
46#include <epan/epan_dissect.h>
47#include <epan/tap.h>
48#include <epan/column-utils.h>
49#include <wsutil/filesystem.h>
50#include <wsutil/wsgcrypt.h>
51#include <epan/funnel.h>
52#include <epan/tvbparse.h>
53#include <epan/epan.h>
54#include <epan/expert.h>
55#include <epan/exceptions.h>
56#include <epan/show_exception.h>
57#include <epan/conversation.h>
58
59#include <epan/wslua/declare_wslua.h>
60
65#define WSLUA_INIT_ROUTINES "init_routines"
66#define WSLUA_PREFS_CHANGED "prefs_changed"
67
68#ifdef HAVE_LUA_UNICODE
69 #define ABOUT_LUA_RELEASE LUA_RELEASE" (UfW patched)"
70#else /* HAVE_LUA_UNICODE */
71 #define ABOUT_LUA_RELEASE LUA_RELEASE
72#endif /* HAVE_LUA_UNICODE */
73
74/* type conversion macros - lua_Number is a double, so casting isn't kosher; and
75 using Lua's already-available lua_tointeger() and luaL_checkinteger() might be
76 different on different machines; so use these instead please!
77
78 It can be important to choose the correct version of signed or unsigned
79 conversion macros; don't assume that you can freely convert to the signed
80 or unsigned integer of the same size later:
81
82 On 32-bit Windows x86, Lua 5.2 and earlier must use lua_tounsigned() and
83 luaL_checkunsigned() due to the use of float to integer inlined assembly.
84 (#18367)
85 On ARM, casting from a negative floating point number to an unsigned integer
86 type doesn't perform wraparound conversion in the same way as casting from
87 float to the same size signed integer then to unsigned does, unlike x86[-64].
88 (Commit 15392c324d5eaefcaa298cdee09cd5b40b12e09c)
89
90 On Lua 5.3 and later, numbers are stored as a kind of union between
91 Lua_Number and Lua_Integer. On 5.2 and earlier. all numbers are stored
92 as Lua_Number internally.
93
94 Be careful about using the 64-bit functions, as they convert from double
95 and lose precision at high values. See wslua_int64.c and the types there.
96 TODO: Check if Lua_Integer is 64 bit on Lua 5.3 and later.
97*/
98#define wslua_toint(L,i) (int) ( lua_tointeger(L,i) )
99#define wslua_toint32(L,i) (int32_t) ( lua_tointeger(L,i) )
100#define wslua_toint64(L,i) (int64_t) ( lua_tonumber(L,i) )
101#define wslua_touint64(L,i) (uint64_t) ( lua_tonumber(L,i) )
102
103#define wslua_checkint(L,i) (int) ( luaL_checkinteger(L,i) )
104#define wslua_checkint32(L,i) (int32_t) ( luaL_checkinteger(L,i) )
105#define wslua_checkint64(L,i) (int64_t) ( luaL_checknumber(L,i) )
106#define wslua_checkuint64(L,i) (uint64_t) ( luaL_checknumber(L,i) )
107
108#define wslua_optint(L,i,d) (int) ( luaL_optinteger(L,i,d) )
109#define wslua_optint32(L,i,d) (int32_t) ( luaL_optinteger(L,i,d) )
110#define wslua_optint64(L,i,d) (int64_t) ( luaL_optnumber(L,i,d) )
111#define wslua_optuint64(L,i,d) (uint64_t) ( luaL_optnumber(L,i,d) )
112
118#if LUA_VERSION_NUM < 503
119#define wslua_touint(L,i) (unsigned) ( lua_tounsigned(L,i) )
120#define wslua_touint32(L,i) (uint32_t) ( lua_tounsigned(L,i) )
121#define wslua_checkuint(L,i) (unsigned) ( luaL_checkunsigned(L,i) )
122#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkunsigned(L,i) )
123#define wslua_optuint(L,i,d) (unsigned) ( luaL_optunsigned(L,i,d) )
124#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optunsigned(L,i,d) )
125#else
126#define wslua_touint(L,i) (unsigned) ( lua_tointeger(L,i) )
127#define wslua_touint32(L,i) (uint32_t) ( lua_tointeger(L,i) )
128#define wslua_checkuint(L,i) (unsigned) ( luaL_checkinteger(L,i) )
129#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkinteger(L,i) )
130#define wslua_optuint(L,i,d) (unsigned) ( luaL_optinteger(L,i,d) )
131#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optinteger(L,i,d) )
132#endif
133
142
150
151
156 struct _wslua_tvb* tvb;
157 unsigned offset;
158 unsigned len;
159};
160
170
174typedef struct _wslua_field_t {
175 int hfid;
176 int ett;
177 char* name;
178 char* abbrev;
179 char* blob;
181 unsigned base;
182 const void* vs;
184 uint64_t mask;
186
197
201typedef struct _wslua_pref_t {
202 char* name;
203 char* label;
204 char* desc;
208 union {
209 bool b;
210 unsigned u;
211 char* s;
212 int e;
214 void* p;
216
218 union {
219 uint32_t max_value;
222 struct {
226
228 struct {
231
232 char* default_s;
234
237 int ref;
239
261
269
281
290
298
303 GHashTable* table;
305 bool expired;
306};
307
316
324
332
337 lua_State* state;
340};
341
347typedef void (*tap_extractor_t)(lua_State* L, const void* data);
348
362
374
386
392 bool expired;
393};
394
399 const wtap_rec* rec;
400 const uint8_t* pd;
401 bool expired;
402};
403
428
433 GDir* dir;
434 char* ext;
435 char* path;
436};
437
442 struct progdlg* pw;
443 char* title;
444 char* task;
445 bool stopped;
446};
447
451typedef struct {
452 const char* name;
454} tappable_t;
455
459typedef struct {
460 const char* str;
461 enum ftenum id;
463
467typedef struct {
468 const char* str;
471
472typedef wslua_pref_t* Pref;
473typedef wslua_pref_t* Prefs;
474typedef struct _wslua_field_t* ProtoField;
475typedef struct _wslua_expert_field_t* ProtoExpert;
476typedef struct _wslua_proto_t* Proto;
477typedef struct _wslua_distbl_t* DissectorTable;
479typedef GByteArray* ByteArray;
480typedef gcry_cipher_hd_t* GcryptCipher;
481typedef struct _wslua_tvb* Tvb;
482typedef struct _wslua_tvbrange* TvbRange;
483typedef struct _wslua_col_info* Column;
484typedef struct _wslua_cols* Columns;
485typedef struct _wslua_pinfo* Pinfo;
486typedef struct _wslua_treeitem* TreeItem;
487typedef address* Address;
488typedef nstime_t* NSTime;
489typedef int64_t Int64;
490typedef uint64_t UInt64;
491typedef struct _wslua_header_field_info* Field;
492typedef struct _wslua_field_info* FieldInfo;
493typedef struct _wslua_tap* Listener;
494typedef struct _wslua_tw* TextWindow;
495typedef struct _wslua_progdlg* ProgDlg;
496typedef struct _wslua_file* File;
497typedef struct _wslua_captureinfo* CaptureInfo;
499typedef struct _wslua_rec* FrameInfo;
500typedef struct _wslua_const_rec* FrameInfoConst;
501typedef struct _wslua_filehandler* FileHandler;
502typedef wtap_dumper* Dumper;
503typedef struct lua_pseudo_header* PseudoHeader;
504typedef tvbparse_t* Parser;
505typedef tvbparse_wanted_t* Rule;
506typedef tvbparse_elem_t* Node;
507typedef tvbparse_action_t* Shortcut;
508typedef struct _wslua_dir* Dir;
509typedef struct _wslua_private_table* PrivateTable;
511typedef char* Struct;
512
513/*
514 * toXxx(L,idx) gets a Xxx from an index (Lua Error if fails)
515 * checkXxx(L,idx) gets a Xxx from an index after calling check_code (No Lua Error if it fails)
516 * pushXxx(L,xxx) pushes an Xxx into the stack
517 * isXxx(L,idx) tests whether we have an Xxx at idx
518 * shiftXxx(L,idx) removes and returns an Xxx from idx only if it has a type of Xxx, returns NULL otherwise
519 * WSLUA_CLASS_DEFINE must be used with a trailing ';'
520 * (a dummy typedef is used to be syntactically correct)
521 */
522#define WSLUA_CLASS_DEFINE(C,check_code) \
523 WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
524
525#define WSLUA_CLASS_DEFINE_BASE(C,check_code,retval) \
526C to##C(lua_State* L, int idx) { \
527 C* v = (C*)lua_touserdata (L, idx); \
528 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
529 return v ? *v : retval; \
530} \
531C check##C(lua_State* L, int idx) { \
532 C* p; \
533 luaL_checktype(L,idx,LUA_TUSERDATA); \
534 p = (C*)luaL_checkudata(L, idx, #C); \
535 check_code; \
536 return p ? *p : retval; \
537} \
538C* push##C(lua_State* L, C v) { \
539 C* p; \
540 luaL_checkstack(L,2,"Unable to grow stack\n"); \
541 p = (C*)lua_newuserdata(L,sizeof(C)); *p = v; \
542 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
543 return p; \
544}\
545bool is##C(lua_State* L,int i) { \
546 void *p; \
547 if(!lua_isuserdata(L,i)) return false; \
548 p = lua_touserdata(L, i); \
549 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
550 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
551 lua_pop(L, 2); \
552 return p ? true : false; \
553} \
554C shift##C(lua_State* L,int i) { \
555 C* p; \
556 if(!lua_isuserdata(L,i)) return retval; \
557 p = (C*)lua_touserdata(L, i); \
558 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
559 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
560 lua_pop(L, 2); \
561 if (p) { lua_remove(L,i); return *p; }\
562 else return retval;\
563} \
564typedef int dummy##C
565
570 const char* fieldname;
571 lua_CFunction getfunc;
572 lua_CFunction setfunc;
574
585extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter);
586
587#define WSLUA_TYPEOF_FIELD "__typeof"
588
589#ifdef HAVE_LUA
590
591/* temporary transition macro to reduce duplication in WSLUA_REGISTER_xxx. */
592#define WSLUA_REGISTER_GC(C) \
593 luaL_getmetatable(L, #C); \
594 /* add the '__gc' metamethod with a C-function named Class__gc */ \
595 /* this will force ALL wslua classes to have a Class__gc function defined, which is good */ \
596 lua_pushcfunction(L, C ## __gc); \
597 lua_setfield(L, -2, "__gc"); \
598 /* pop the metatable */ \
599 lua_pop(L, 1)
600
601#define __WSLUA_REGISTER_META(C, ATTRS) { \
602 const wslua_class C ## _class = { \
603 .name = #C, \
604 .instance_meta = C ## _meta, \
605 .attrs = ATTRS \
606 }; \
607 wslua_register_classinstance_meta(L, &C ## _class); \
608 WSLUA_REGISTER_GC(C); \
609}
610
611#define WSLUA_REGISTER_META(C) __WSLUA_REGISTER_META(C, NULL)
612#define WSLUA_REGISTER_META_WITH_ATTRS(C) \
613 __WSLUA_REGISTER_META(C, C ## _attributes)
614
615#define __WSLUA_REGISTER_CLASS(C, ATTRS) { \
616 const wslua_class C ## _class = { \
617 .name = #C, \
618 .class_methods = C ## _methods, \
619 .class_meta = C ## _meta, \
620 .instance_methods = C ## _methods, \
621 .instance_meta = C ## _meta, \
622 .attrs = ATTRS \
623 }; \
624 wslua_register_class(L, &C ## _class); \
625 WSLUA_REGISTER_GC(C); \
626}
627
628#define WSLUA_REGISTER_CLASS(C) __WSLUA_REGISTER_CLASS(C, NULL)
629#define WSLUA_REGISTER_CLASS_WITH_ATTRS(C) \
630 __WSLUA_REGISTER_CLASS(C, C ## _attributes)
631
632#define WSLUA_INIT(L) \
633 luaL_openlibs(L); \
634 wslua_register_classes(L); \
635 wslua_register_functions(L);
636
637#endif
638
639#define WSLUA_FUNCTION extern int
640/* This is for functions intended only to be used in init.lua */
641#define WSLUA_INTERNAL_FUNCTION extern int
642
643#define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
644
645#define WSLUA_REGISTER extern int
646
647#define WSLUA_METHOD static int
648#define WSLUA_CONSTRUCTOR static int
649#define WSLUA_ATTR_SET static int
650#define WSLUA_ATTR_GET static int
651#define WSLUA_METAMETHOD static int
652
653#define WSLUA_METHODS static const luaL_Reg
654#define WSLUA_META static const luaL_Reg
655#define WSLUA_CLASS_FNREG(class,name) { #name, class##_##name }
656#define WSLUA_CLASS_FNREG_ALIAS(class,aliasname,name) { #aliasname, class##_##name }
657#define WSLUA_CLASS_MTREG(class,name) { "__" #name, class##__##name }
658
659#define WSLUA_ATTRIBUTES static const wslua_attribute_table
660/* following are useful macros for the rows in the array created by above */
661#define WSLUA_ATTRIBUTE_RWREG(class,name) { #name, class##_get_##name, class##_set_##name }
662#define WSLUA_ATTRIBUTE_ROREG(class,name) { #name, class##_get_##name, NULL }
663#define WSLUA_ATTRIBUTE_WOREG(class,name) { #name, NULL, class##_set_##name }
664
665/* Body of a __pairs metamethod that hands the generic-for protocol
666 * a stateless iterator `C##_pairs_iter`. The iterator must accept
667 * (self, prev_key_or_nil) and return the next (key, value) pair or a
668 * single nil when done. Use inside a WSLUA_METAMETHOD body so the
669 * caller retains control of any doc comments shown in the manual. */
670#define WSLUA_STATELESS_PAIRS_BODY(C) \
671 check##C(L, 1); \
672 lua_pushcfunction(L, C##_pairs_iter); \
673 lua_pushvalue(L, 1); \
674 lua_pushnil(L); \
675 return 3
676
677#define WSLUA_ATTRIBUTE_FUNC_SETTER(C,field) \
678 static int C##_set_##field (lua_State* L) { \
679 C obj = check##C (L,1); \
680 if (! lua_isfunction(L,-1) ) \
681 return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
682 if (obj->field##_ref != LUA_NOREF) \
683 /* there was one registered before, remove it */ \
684 luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
685 obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
686 return 0; \
687 } \
688 /* silly little trick so we can add a semicolon after this macro */ \
689 typedef void __dummy##C##_set_##field
690
691#define WSLUA_ATTRIBUTE_GET(C,name,block) \
692 static int C##_get_##name (lua_State* L) { \
693 C obj = check##C (L,1); \
694 block \
695 return 1; \
696 } \
697 /* silly little trick so we can add a semicolon after this macro */ \
698 typedef void __dummy##C##_get_##name
699
700#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
701 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
702
703#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,name,member) \
704 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
705
706#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C,member) \
707 WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
708
709#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \
710 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
711
712#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,name,member) \
713 WSLUA_ATTRIBUTE_GET(C,name, { \
714 lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
715 })
716
717#define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
718 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
719
720#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
721 WSLUA_ATTRIBUTE_GET(C,name, { \
722 char* str; \
723 if ((obj->member) && (obj->member->len > 0)) { \
724 if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
725 lua_pushstring(L,str); \
726 } \
727 } \
728 })
729
730/*
731 * XXX - we need to support Lua programs getting instances of a "multiple
732 * allowed" option other than the first option.
733 */
734#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
735 WSLUA_ATTRIBUTE_GET(C,name, { \
736 char* str; \
737 if ((obj->member) && (obj->member->len > 0)) { \
738 if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
739 lua_pushstring(L,str); \
740 } \
741 } \
742 })
743
744#define WSLUA_ATTRIBUTE_SET(C,name,block) \
745 static int C##_set_##name (lua_State* L) { \
746 C obj = check##C (L,1); \
747 block; \
748 return 0; \
749 } \
750 /* silly little trick so we can add a semicolon after this macro */ \
751 typedef void __dummy##C##_set_##name
752
753#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C,name,member) \
754 WSLUA_ATTRIBUTE_SET(C,name, { \
755 if (! lua_isboolean(L,-1) ) \
756 return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
757 obj->member = lua_toboolean(L,-1); \
758 })
759
760/* to make this integral-safe, we treat it as int32 and then cast
761 Note: This will truncate 64-bit integers (but then Lua itself only has doubles */
762#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,name,member,cast) \
763 WSLUA_ATTRIBUTE_SET(C,name, { \
764 if (! lua_isinteger(L,-1) ) \
765 return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
766 obj->member = (cast) wslua_toint32(L,-1); \
767 })
768
769#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C,member,cast) \
770 WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
771
772#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \
773 static int C##_set_##field (lua_State* L) { \
774 C obj = check##C (L,1); \
775 char* s = NULL; \
776 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
777 s = g_strdup(lua_tostring(L,-1)); \
778 } else { \
779 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
780 } \
781 if (obj->member != NULL && need_free) \
782 g_free((void*) obj->member); \
783 obj->member = s; \
784 return 0; \
785 } \
786 /* silly little trick so we can add a semicolon after this macro */ \
787 typedef void __dummy##C##_set_##field
788
789#define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
790 WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
791
792#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \
793 static int C##_set_##field (lua_State* L) { \
794 C obj = check##C (L,1); \
795 char* s = NULL; \
796 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
797 s = g_strdup(lua_tostring(L,-1)); \
798 } else { \
799 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
800 } \
801 if ((obj->member) && (obj->member->len > 0)) { \
802 wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
803 } \
804 g_free(s); \
805 return 0; \
806 } \
807 /* silly little trick so we can add a semicolon after this macro */ \
808 typedef void __dummy##C##_set_##field
809
810#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
811 static int C##_set_##field (lua_State* L) { \
812 C obj = check##C (L,1); \
813 char* s = NULL; \
814 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
815 s = g_strdup(lua_tostring(L,-1)); \
816 } else { \
817 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
818 } \
819 if ((obj->member) && (obj->member->len > 0)) { \
820 wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
821 } \
822 g_free(s); \
823 return 0; \
824 } \
825 /* silly little trick so we can add a semicolon after this macro */ \
826 typedef void __dummy##C##_set_##field
827
828#define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": ", error); }
829#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
830#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
831
832#define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
833#define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
834#define WSLUA_REG_GLOBAL_INTEGER(L,n,v) { lua_pushinteger(L,v); lua_setglobal(L,n); }
835
836#define WSLUA_RETURN(i) return (i)
837
838#define WSLUA_API extern
839
840/* empty macro arguments trigger ISO C90 warnings, so do this */
841#define NOP (void)p
842
843#define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
844
845#define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
846 luaL_argerror(L,idx,"null " s); \
847 } else if ((*p)->expired) { \
848 luaL_argerror(L,idx,"expired " s); \
849 }
850
851/* Clears or marks references that connects Lua to Wireshark structures */
852#define CLEAR_OUTSTANDING(C, marker, marker_val) void clear_outstanding_##C(void) { \
853 while (outstanding_##C->len) { \
854 C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
855 if (p) { \
856 if (p->marker != marker_val) \
857 p->marker = marker_val; \
858 else \
859 g_free(p); \
860 } \
861 } \
862}
863
864#define WSLUA_CLASS_DECLARE(C) \
865extern C to##C(lua_State* L, int idx); \
866extern C check##C(lua_State* L, int idx); \
867extern C* push##C(lua_State* L, C v); \
868extern int C##_register(lua_State* L); \
869extern bool is##C(lua_State* L,int i); \
870extern C shift##C(lua_State* L,int i)
871
872
873/* Throws a Wireshark exception, catchable via normal exceptions.h routines. */
874#define THROW_LUA_ERROR(...) \
875 THROW_FORMATTED(DissectorError, __VA_ARGS__)
876
877/* Catches any Wireshark exceptions in code and convert it into a Lua error.
878 * Normal restrictions for TRY/CATCH apply, in particular, do not return!
879 *
880 * This means do not call lua[L]_error() inside code, as that longjmps out
881 * of the TRY block to the Lua pcall! Use THROW_LUA_ERROR, which is caught
882 * and then converted into a Lua error.
883 *
884 * XXX: We CATCH_ALL here, although there's little point in catching
885 * OutOfMemoryError here. (Is CATCH_BOUNDS_AND_DISSECTOR_ERRORS sufficient?)
886 * There are some Exceptions that we catch and show but don't want to add
887 * the Lua error malformed expert info to the tree: BoundsError,
888 * FragmentBoundsError, and ScsiBoundsError (show_exception doesn't consider
889 * those malformed). The traceback might (or might not) be useful for those.
890 * Putting an extra malformed expert info in the tree in the cases that are
891 * malformed seems not so bad, but we might want to reduce that. Perhaps
892 * at least we could have a separate LuaError type and not call show_exception
893 * for that (we still need to handle some Lua errors that don't use this in
894 * dissector_error_handler.)
895 */
896#define WRAP_NON_LUA_EXCEPTIONS(code) \
897{ \
898 volatile bool has_error = false; \
899 TRY { \
900 code \
901 } CATCH3(BoundsError, FragmentBoundsError, ScsiBoundsError) { \
902 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
903 } CATCH_ALL { \
904 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
905 lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
906 has_error = true; \
907 } ENDTRY; \
908 if (has_error) { lua_error(L); } \
909}
910
911
912extern packet_info* lua_pinfo;
913extern TreeItem lua_tree;
914extern tvbuff_t* lua_tvb;
915extern bool lua_initialized;
916extern int lua_dissectors_table_ref;
917extern int lua_heur_dissectors_table_ref;
918extern const char* lua_app_env_var_prefix;
919extern GPtrArray* lua_outstanding_FuncSavers;
920
921WSLUA_DECLARE_CLASSES()
922WSLUA_DECLARE_FUNCTIONS()
923
931extern lua_State* wslua_state(void);
932
933
934/* wslua_internals.c */
941typedef struct _wslua_class {
942 const char *name;
943 const luaL_Reg *class_methods;
944 const luaL_Reg *class_meta;
945 const luaL_Reg *instance_methods;
946 const luaL_Reg *instance_meta;
949
958void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def);
959
966void wslua_register_class(lua_State *L, const wslua_class *cls_def);
967
977extern int wslua__concat(lua_State* L);
978
990extern bool wslua_toboolean(lua_State* L, int n);
991
1001extern bool wslua_checkboolean(lua_State* L, int n);
1002
1011extern bool wslua_optbool(lua_State* L, int n, bool def);
1012
1020extern lua_Integer wslua_tointeger(lua_State* L, int n);
1021
1030extern int wslua_optboolint(lua_State* L, int n, int def);
1031
1040extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l);
1041
1049extern const char* wslua_checkstring_only(lua_State* L, int n);
1050
1058extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
1059
1060extern const char* wslua_typeof_unknown;
1061
1071extern const char *wslua_typeof(lua_State *L, int idx);
1072
1083extern bool wslua_get_table(lua_State *L, int idx, const char *name);
1084
1094extern bool wslua_get_field(lua_State *L, int idx, const char *name);
1095
1107extern int dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1108 proto_tree *tree, void *data);
1109
1122extern bool heur_dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1123 proto_tree *tree, void *data);
1124
1132extern expert_field* wslua_get_expert_field(const int group, const int severity);
1133
1140extern void wslua_prefs_changed(void);
1141
1147extern void proto_register_lua(void);
1148
1156extern GString* lua_register_all_taps(void);
1157
1165extern void wslua_prime_dfilter(epan_dissect_t *edt);
1166
1172extern bool wslua_has_field_extractors(void);
1173
1182
1191extern int Proto_commit(lua_State* L);
1192
1200extern TreeItem create_TreeItem(proto_tree* tree, proto_item* item);
1201
1207extern void clear_outstanding_FuncSavers(lua_State* L);
1208
1217extern void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1218
1227extern int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1228
1237extern void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1238
1247extern int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1248
1259extern uint64_t getUInt64(lua_State *L, int i);
1260
1268extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb);
1269
1277extern int push_wsluaTvb(lua_State* L, Tvb t);
1278
1288extern bool push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len);
1289
1295extern void clear_outstanding_Tvb(void);
1296
1300extern void clear_outstanding_TvbRange(void);
1301
1309extern Pinfo* push_Pinfo(lua_State* L, packet_info* p);
1310
1314extern void clear_outstanding_Pinfo(void);
1315
1319extern void clear_outstanding_Column(void);
1320
1324extern void clear_outstanding_Columns(void);
1325
1329extern void clear_outstanding_PrivateTable(void);
1330
1336extern int get_hf_wslua_text(void);
1337
1346extern TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item);
1347
1351extern void clear_outstanding_TreeItem(void);
1352
1360extern FieldInfo* push_FieldInfo(lua_State *L, field_info* f);
1361
1365extern void clear_outstanding_FieldInfo(void);
1366
1373extern void wslua_print_stack(char* s, lua_State* L);
1374
1384extern void wslua_init(register_cb cb, void *client_data, const char* app_env_var_prefix);
1385
1389extern void wslua_early_cleanup(void);
1390
1396extern void wslua_cleanup(void);
1397
1405
1412extern int wslua_set_tap_enums(lua_State* L);
1413
1414extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr);
1415
1422extern char* wslua_get_actual_filename(const char* fname);
1423
1436extern int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep);
1437
1447extern int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep);
1448
1455extern int luaopen_rex_pcre2(lua_State *L);
1456
1462extern const char* get_current_plugin_version(void);
1463
1467extern void clear_current_plugin_version(void);
1468
1477extern int wslua_deregister_heur_dissectors(lua_State* L);
1478
1487extern int wslua_deregister_protocols(lua_State* L);
1488
1497extern int wslua_deregister_dissector_tables(lua_State* L);
1498
1507extern int wslua_deregister_listeners(lua_State* L);
1508
1515extern int wslua_deregister_fields(lua_State* L);
1516
1524extern int wslua_deregister_filehandlers(lua_State* L);
1525
1532extern void wslua_deregister_menus(void);
1533
1542extern void wslua_init_wtap_filetypes(lua_State* L);
1543
1550
1551#endif
1552
1553/*
1554 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1555 *
1556 * Local variables:
1557 * c-basic-offset: 4
1558 * tab-width: 8
1559 * indent-tabs-mode: nil
1560 * End:
1561 *
1562 * vi: set shiftwidth=4 tabstop=8 expandtab:
1563 * :indentSize=4:tabSize=8:noTabs=true:
1564 */
conversation_type
Conversation key types recognized by Wireshark dissectors.
Definition conversation.h:65
ftenum
Fundamental field value types used throughout the Wireshark dissector framework.
Definition ftypes.h:26
pref_type_e
Discriminator tag identifying the type and UI representation of a preference entry.
Definition prefs-int.h:138
Holds a network or link-layer address of any supported type.
Definition address.h:62
Definition tap-funnel.c:21
Definition proto.h:768
Represents the metadata and indexing information for a single captured frame.
Definition packet_info.h:43
Definition proto.h:909
Represents a single token matched by the tvbuff parser, forming part of a linked tree of parse result...
Definition tvbparse.h:165
Represents an instance of a per-packet parser for tvbuff data.
Definition tvbparse.h:151
Describes a parsing rule or expectation for a tvbuff parser.
Definition tvbparse.h:96
Describes a single editable field within a UAT (User Accessible Table).
Definition uat.h:234
Defines a single attribute entry in a Lua class attribute dispatch table, binding a field name to its...
Definition wslua.h:569
lua_CFunction getfunc
Definition wslua.h:571
lua_CFunction setfunc
Definition wslua.h:572
const char * fieldname
Definition wslua.h:570
Wraps capture file metadata for access from the Lua scripting environment.
Definition wslua.h:381
bool expired
Definition wslua.h:384
wtap_dumper * wdh
Definition wslua.h:383
wtap * wth
Definition wslua.h:382
Type for defining new classes.
Definition wslua.h:941
const wslua_attribute_table * attrs
Definition wslua.h:947
const luaL_Reg * class_meta
Definition wslua.h:944
const char * name
Definition wslua.h:942
const luaL_Reg * class_methods
Definition wslua.h:943
const luaL_Reg * instance_methods
Definition wslua.h:945
const luaL_Reg * instance_meta
Definition wslua.h:946
Wraps a single column within a column_info for access from the Lua scripting environment.
Definition wslua.h:285
column_info * cinfo
Definition wslua.h:286
int col
Definition wslua.h:287
bool expired
Definition wslua.h:288
Wraps a column_info for bulk column access from the Lua scripting environment.
Definition wslua.h:294
column_info * cinfo
Definition wslua.h:295
bool expired
Definition wslua.h:296
Wraps a read-only wtap_rec and its associated raw packet data for access from the Lua scripting envir...
Definition wslua.h:398
const wtap_rec * rec
Definition wslua.h:399
const uint8_t * pd
Definition wslua.h:400
bool expired
Definition wslua.h:401
Associates a conversation with a Lua registry reference holding per-conversation dissector data.
Definition wslua.h:265
conversation_t * conv
Definition wslua.h:266
int data_ref
Definition wslua.h:267
Wraps a GDir iterator with extension filtering and path tracking for directory traversal from Lua.
Definition wslua.h:432
GDir * dir
Definition wslua.h:433
char * ext
Definition wslua.h:434
char * path
Definition wslua.h:435
Represents a Lua DissectorTable, which may back either a standard dissector_table_t or a heuristic di...
Definition wslua.h:273
dissector_table_t table
Definition wslua.h:274
const char * name
Definition wslua.h:276
bool expired
Definition wslua.h:279
bool created
Definition wslua.h:278
heur_dissector_list_t heur_list
Definition wslua.h:275
const char * ui_name
Definition wslua.h:277
Describes an expert info field registered from a Lua dissector script.
Definition wslua.h:190
const char * abbrev
Definition wslua.h:192
expert_field ids
Definition wslua.h:191
const char * text
Definition wslua.h:193
int severity
Definition wslua.h:195
int group
Definition wslua.h:194
Wraps a field_info for access from the Lua scripting environment, tracking validity.
Definition wslua.h:328
bool expired
Definition wslua.h:330
field_info * ws_fi
Definition wslua.h:329
Describes a protocol header field registered from a Lua dissector script.
Definition wslua.h:174
unsigned base
Definition wslua.h:181
int hfid
Definition wslua.h:175
char * name
Definition wslua.h:177
char * blob
Definition wslua.h:179
char * abbrev
Definition wslua.h:178
const void * vs
Definition wslua.h:182
uint64_t mask
Definition wslua.h:184
int ett
Definition wslua.h:176
int valuestring_ref
Definition wslua.h:183
enum ftenum type
Definition wslua.h:180
Wraps a wtap file handle or wtap_dumper for read/write access from the Lua scripting environment.
Definition wslua.h:369
FILE_T file
Definition wslua.h:370
wtap_dumper * wdh
Definition wslua.h:371
bool expired
Definition wslua.h:372
Describes a Lua-registered file format handler for reading and/or writing capture files.
Definition wslua.h:407
int seek_read_ref
Definition wslua.h:417
int read_open_ref
Definition wslua.h:415
int write_ref
Definition wslua.h:422
int write_close_ref
Definition wslua.h:423
int file_type
Definition wslua.h:424
char * type
Definition wslua.h:412
char * internal_description
Definition wslua.h:411
int write_open_ref
Definition wslua.h:421
bool is_writer
Definition wslua.h:410
bool registered
Definition wslua.h:425
char * extensions
Definition wslua.h:413
int read_ref
Definition wslua.h:416
int can_write_encap_ref
Definition wslua.h:420
lua_State * L
Definition wslua.h:414
int seq_read_close_ref
Definition wslua.h:419
int read_close_ref
Definition wslua.h:418
struct file_type_subtype_info finfo
Definition wslua.h:408
bool removed
Definition wslua.h:426
bool is_reader
Definition wslua.h:409
Stores Lua function references to prevent garbage collection for functions used by tcp_dissect_pdus()...
Definition wslua.h:336
int get_len_ref
Definition wslua.h:338
lua_State * state
Definition wslua.h:337
int dissect_ref
Definition wslua.h:339
Tracks a registered header field and its associated info for internal use by the Lua field registrati...
Definition wslua.h:320
header_field_info * hfi
Definition wslua.h:322
char * name
Definition wslua.h:321
Wraps a packet_info pointer with expiry tracking for use in the Lua scripting environment.
Definition wslua.h:146
packet_info * ws_pinfo
Definition wslua.h:147
bool expired
Definition wslua.h:148
Represents a single Wireshark preference registered from a Lua dissector script.
Definition wslua.h:201
void * p
Definition wslua.h:214
uat_field_t * uat_field_list
Definition wslua.h:229
unsigned u
Definition wslua.h:210
bool radio_buttons
Definition wslua.h:224
char * desc
Definition wslua.h:204
struct _wslua_proto_t * proto
Definition wslua.h:236
char * s
Definition wslua.h:211
char * default_s
Definition wslua.h:232
bool b
Definition wslua.h:209
uint32_t max_value
Definition wslua.h:219
char * name
Definition wslua.h:202
range_t * r
Definition wslua.h:213
int ref
Definition wslua.h:237
struct _wslua_pref_t::@510::@512 uat_field_list_info
struct _wslua_pref_t * next
Definition wslua.h:235
const enum_val_t * enumvals
Definition wslua.h:223
char * label
Definition wslua.h:203
int e
Definition wslua.h:212
struct _wslua_pref_t::@510::@511 enum_info
pref_type_e type
Definition wslua.h:205
union _wslua_pref_t::@509 value
union _wslua_pref_t::@510 info
Wraps a GHashTable for use as a Lua private data table, tracking ownership and expiry.
Definition wslua.h:302
bool expired
Definition wslua.h:305
bool is_allocated
Definition wslua.h:304
GHashTable * table
Definition wslua.h:303
Wraps a GUI progress dialog for control from the Lua scripting environment.
Definition wslua.h:441
char * title
Definition wslua.h:443
struct progdlg * pw
Definition wslua.h:442
bool stopped
Definition wslua.h:445
char * task
Definition wslua.h:444
Represents a Wireshark protocol registered from a Lua dissector script.
Definition wslua.h:243
bool expired
Definition wslua.h:259
int ett
Definition wslua.h:248
GArray * eia
Definition wslua.h:257
dissector_handle_t handle
Definition wslua.h:254
int fields
Definition wslua.h:250
bool is_postdissector
Definition wslua.h:258
expert_module_t * expert_module
Definition wslua.h:252
int expert_info_table_ref
Definition wslua.h:251
char * desc
Definition wslua.h:246
module_t * prefs_module
Definition wslua.h:253
GArray * hfa
Definition wslua.h:255
int hfid
Definition wslua.h:247
GArray * etta
Definition wslua.h:256
char * name
Definition wslua.h:244
char * loname
Definition wslua.h:245
wslua_pref_t prefs
Definition wslua.h:249
Wraps a wtap_rec for access from the Lua scripting environment, tracking validity.
Definition wslua.h:390
wtap_rec * rec
Definition wslua.h:391
bool expired
Definition wslua.h:392
Represents a Lua tap listener, binding a tap name and filter to Lua callback functions.
Definition wslua.h:352
int draw_ref
Definition wslua.h:358
bool all_fields
Definition wslua.h:360
lua_State * L
Definition wslua.h:356
int packet_ref
Definition wslua.h:357
char * filter
Definition wslua.h:354
int reset_ref
Definition wslua.h:359
char * name
Definition wslua.h:353
tap_extractor_t extractor
Definition wslua.h:355
Wraps a proto_item and its associated proto_tree for manipulation from the Lua scripting environment.
Definition wslua.h:311
proto_tree * tree
Definition wslua.h:313
bool expired
Definition wslua.h:314
proto_item * item
Definition wslua.h:312
Wraps a tvbuff_t with ownership and expiry tracking for use in the Lua scripting environment.
Definition wslua.h:137
tvbuff_t * ws_tvb
Definition wslua.h:138
bool expired
Definition wslua.h:139
bool need_free
Definition wslua.h:140
Represents a sub-range of a Lua tvbuff, defined by an offset and length within the parent tvb.
Definition wslua.h:155
unsigned offset
Definition wslua.h:157
unsigned len
Definition wslua.h:158
struct _wslua_tvb * tvb
Definition wslua.h:156
Wraps a funnel text window for use in the Lua scripting environment, tracking expiry and close callba...
Definition wslua.h:164
funnel_text_window_t * ws_tw
Definition wslua.h:165
bool expired
Definition wslua.h:166
void * close_cb_data
Definition wslua.h:167
char * title
Definition wslua.h:168
Definition packet-bt-dht.c:97
Definition conversation.h:229
Definition packet.c:852
Definition packet.c:97
Defines a single named value within an enumerated preference or option type.
Definition params.h:16
Definition column-info.h:59
Holds all state for the dissection of a single byte array, including session, buffer,...
Definition epan_dissect.h:28
Definition range.h:42
Pairs an expert info index with its associated header field index for registration and display.
Definition expert.h:41
Definition expert.c:48
Definition proto.h:817
Definition wtap.h:1961
Definition packet.c:188
Definition wslua_dumper.c:58
Definition nstime.h:26
Represents a preference module grouping related preferences under a named, hierarchical entry in the ...
Definition prefs-int.h:27
Define the structure describing a progress dialog.
Definition progress_frame.h:33
Maps a tap name to its Lua data extractor callback for use in the tappable protocol registry.
Definition wslua.h:451
tap_extractor_t extractor
Definition wslua.h:453
const char * name
Definition wslua.h:452
Core tvbuff (testy virtual buffer) structure representing a region of packet data,...
Definition tvbuff-int.h:95
Maps a conversation type name string to its conversation_type identifier for use in Lua conversation ...
Definition wslua.h:467
const char * str
Definition wslua.h:468
conversation_type id
Definition wslua.h:469
Maps a field type name string to its ftenum identifier for use in Lua field type lookups.
Definition wslua.h:459
const char * str
Definition wslua.h:460
enum ftenum id
Definition wslua.h:461
Wiretap dumper handle and associated state.
Definition wtap_module.h:163
Definition file_wrappers.c:96
Definition wtap.h:1540
Definition wtap_module.h:58
void clear_outstanding_TvbRange(void)
Clears all outstanding TvbRange objects.
Definition wslua_tvb.c:396
void wslua_init(register_cb cb, void *client_data, const char *app_env_var_prefix)
Initialize Wireshark Lua support.
Definition init_wslua.c:1655
int dissect_lua(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
C-side entry point for all Lua-based protocol dissectors.
bool wslua_get_table(lua_State *L, int idx, const char *name)
Push a named field from a Lua table onto the stack.
Definition wslua_internals.c:199
tap_extractor_t wslua_get_tap_extractor(const char *name)
Retrieves a tap extractor by name.
struct _wslua_field_t wslua_field_t
Describes a protocol header field registered from a Lua dissector script.
void wslua_print_stack(char *s, lua_State *L)
Prints the stack of a Lua state with a given prefix.
Definition wslua_internals.c:167
int push_wsluaTvb(lua_State *L, Tvb t)
Pushes a Tvb object onto the Lua stack.
Definition wslua_tvb.c:77
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.
Definition wslua_internals.c:119
const char * wslua_checkstring_only(lua_State *L, int n)
Checks if a Lua value at a given index is a string.
Definition wslua_internals.c:129
bool heur_dissect_lua(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
C-side entry point for all Lua-based heuristic dissectors.
void lua_prime_all_fields(proto_tree *tree)
Primes all fields in the protocol tree.
void wslua_early_cleanup(void)
Performs early cleanup of Lua resources.
Definition init_wslua.c:2046
void clear_outstanding_Column(void)
Clears all outstanding Column objects.
Definition wslua_column.c:28
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 ...
Definition wslua_int64.c:661
void wslua_cleanup(void)
Cleans up Lua resources.
Definition init_wslua.c:2093
int wslua_deregister_protocols(lua_State *L)
Deregisters all Lua-based protocol dissectors.
Definition wslua_proto.c:791
TreeItem create_TreeItem(proto_tree *tree, proto_item *item)
Creates a new TreeItem.
Definition wslua_tree.c:43
FieldInfo * push_FieldInfo(lua_State *L, field_info *f)
Pushes a field information object onto the Lua stack.
Definition wslua_field.c:36
void wslua_register_class(lua_State *L, const wslua_class *cls_def)
Registers a new Lua class in the global table.
Definition wslua_internals.c:547
const char * get_current_plugin_version(void)
Get the current plugin version.
Definition wslua_utility.c:39
int wslua_deregister_dissector_tables(lua_State *L)
Deregisters all registered dissector tables.
Definition wslua_dissector.c:1111
int wslua_deregister_filehandlers(lua_State *L)
Deregisters file handlers and menus in Wireshark's Lua environment.
int luaopen_rex_pcre2(lua_State *L)
Open the Lua library for PCRE2 regular expressions.
Definition lpcre2.c:481
void wslua_prefs_changed(void)
Notify Lua scripts that preferences have changed.
Definition init_wslua.c:668
lua_State * wslua_state(void)
Retrieves the Lua state associated with Wireshark.
Definition init_wslua.c:2102
Pinfo * push_Pinfo(lua_State *L, packet_info *p)
Pushes a packet information structure onto the Lua stack.
Definition wslua_pinfo.c:39
void clear_outstanding_Pinfo(void)
Clears all outstanding Pinfo objects.
Definition wslua_pinfo.c:36
bool wslua_has_field_extractors(void)
Checks if there are any registered field extractors.
Definition wslua_field.c:521
int wslua_deregister_fields(lua_State *L)
Deregisters Lua fields.
int wslua_optboolint(lua_State *L, int n, int def)
Retrieves an optional boolean or integer value from the Lua stack.
Definition wslua_internals.c:102
int get_hf_wslua_text(void)
Retrieves the value of hf_wslua_text.
Definition init_wslua.c:187
bool wslua_get_field(lua_State *L, int idx, const char *name)
Push a named field from a Lua value's metatable or environment.
Definition wslua_internals.c:213
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.
Definition wslua_internals.c:69
int wslua_deregister_heur_dissectors(lua_State *L)
Deregisters all Lua-based heuristics dissectors.
Definition wslua_proto.c:775
int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter)
Registers attributes for a Lua table.
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.
Definition wslua_int64.c:620
void wslua_deregister_menus(void)
Deregisters all menus registered by Wireshark Lua.
Definition wslua_gui.c:110
void clear_current_plugin_version(void)
Clear the current plugin version.
Definition wslua_utility.c:43
struct _wslua_proto_t wslua_proto_t
Represents a Wireshark protocol registered from a Lua dissector script.
void clear_outstanding_Columns(void)
Clears all outstanding Column objects.
Definition wslua_column.c:29
void clear_outstanding_FieldInfo(void)
Clears any outstanding FieldInfo structures.
Definition wslua_field.c:44
int wslua__concat(lua_State *L)
Concatenates two objects to a string.
Definition wslua_internals.c:27
bool push_TvbRange(lua_State *L, tvbuff_t *tvb, int offset, int len)
Pushes a TvbRange object onto the Lua stack.
Definition wslua_tvb.c:404
expert_field * wslua_get_expert_field(const int group, const int severity)
Retrieves an expert field based on group and severity.
Definition init_wslua.c:1185
bool wslua_toboolean(lua_State *L, int n)
Converts a Lua value to a boolean.
Definition wslua_internals.c:44
ProtoField wslua_is_field_available(lua_State *L, const char *field_abbr)
Definition wslua_proto.c:744
int Proto_commit(lua_State *L)
Commits protocol changes.
Definition wslua_proto.c:875
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.
Definition wslua_int64.c:169
const char * wslua_typeof(lua_State *L, int idx)
Return a human-readable type name for the Lua value at a stack index.
Definition wslua_internals.c:180
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.
Definition wslua_internals.c:318
void clear_outstanding_Tvb(void)
Clears all outstanding Tvb objects.
Definition wslua_tvb.c:98
void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def)
Registers a class instance meta table.
Definition wslua_internals.c:470
struct _wslua_expert_field_t wslua_expert_field_t
Describes an expert info field registered from a Lua dissector script.
void wslua_init_wtap_filetypes(lua_State *L)
Initialize Wireshark Lua file types.
Definition wslua_wtap.c:111
struct _wslua_class wslua_class
Type for defining new classes.
int wslua_deregister_listeners(lua_State *L)
Deregisters all registered listeners.
Definition wslua_listener.c:444
Tvb * push_Tvb(lua_State *L, tvbuff_t *tvb)
Pushes a tvbuff_t to the Lua stack as a Tvb object.
Definition wslua_tvb.c:106
void proto_register_lua(void)
Registers the Lua protocol.
struct _wslua_conv_data_t wslua_conv_data_t
Associates a conversation with a Lua registry reference holding per-conversation dissector data.
struct _wslua_pref_t wslua_pref_t
Represents a single Wireshark preference registered from a Lua dissector script.
char * wslua_get_actual_filename(const char *fname)
Retrieves the actual filename with normalized path separators.
Definition wslua_utility.c:380
const wslua_conv_types_t * wslua_inspect_convtype_enum(void)
Retrieves the enumeration of conversation types for Lua inspection.
Definition wslua_conversation.c:77
bool wslua_checkboolean(lua_State *L, int n)
Checks if a Lua value at a given index is a boolean.
Definition wslua_internals.c:60
int wslua_set_tap_enums(lua_State *L)
Set tap enumerations in Lua.
void clear_outstanding_FuncSavers(lua_State *L)
Clears outstanding function savers associated with a Lua state.
Definition wslua_proto.c:49
void clear_outstanding_PrivateTable(void)
Clears any outstanding PrivateTable entries.
Definition wslua_pinfo.c:37
void(* tap_extractor_t)(lua_State *L, const void *data)
Callback type for extracting tap data from a C tap structure into a Lua state.
Definition wslua.h:347
GString * lua_register_all_taps(void)
Registers all Lua taps.
struct _wslua_attribute_table wslua_attribute_table
Defines a single attribute entry in a Lua class attribute dispatch table, binding a field name to its...
uint64_t getUInt64(lua_State *L, int i)
Retrieves a 64-bit unsigned integer from the Lua stack.
Definition wslua_int64.c:599
lua_Integer wslua_tointeger(lua_State *L, int n)
Converts a Lua value to an integer.
Definition wslua_internals.c:85
void clear_outstanding_TreeItem(void)
Clears all outstanding TreeItem objects.
Definition wslua_tree.c:53
void wslua_prime_dfilter(epan_dissect_t *edt)
Prime the dissector filter with a protocol tree.
Definition wslua_field.c:514
TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item)
Pushes a TreeItem onto the Lua stack.
Definition wslua_tree.c:30
int wslua_hex2bin(lua_State *L, const char *data, const unsigned len, const char *sep)
Convert hexadecimal string to binary data.
Definition wslua_internals.c:375
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.
Definition wslua_int64.c:128
void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Set functions in a Lua table.
Definition wslua_internals.c:134