Wireshark 5.1.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
64
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
138 tvbuff_t* ws_tvb;
139 uint64_t generation;
140};
141
149
150
156 unsigned offset;
157 unsigned len;
158};
159
163struct _wslua_tw {
164 funnel_text_window_t* ws_tw;
165 bool expired;
167 char* title;
168};
169
173typedef struct _wslua_field_t {
174 int hfid;
175 int ett;
176 char* name;
177 char* abbrev;
178 char* blob;
180 unsigned base;
181 const void* vs;
183 uint64_t mask;
185
196
200typedef struct _wslua_pref_t {
201 char* name;
202 char* label;
203 char* desc;
205
207 union {
208 bool b;
209 unsigned u;
210 char* s;
211 int e;
213 void* p;
215
217 union {
218 uint32_t max_value;
219
221 struct {
225
227 struct {
230
231 char* default_s;
233
236 int ref;
238
242typedef struct _wslua_proto_t {
243 char* name;
244 char* loname;
245 char* desc;
246 int hfid;
247 int ett;
249 int fields;
251 expert_module_t* expert_module;
252 module_t* prefs_module;
253 dissector_handle_t handle;
254 GArray* hfa;
255 GArray* etta;
256 GArray* eia;
258 bool expired;
260
269
274 dissector_table_t table;
275 heur_dissector_list_t heur_list;
276 const char* name;
277 const char* ui_name;
278 bool created;
279 bool expired;
280};
281
286 column_info* cinfo;
287 int col;
288 uint64_t generation;
289};
290
295 column_info* cinfo;
296 uint64_t generation;
297};
298
303 GHashTable* table;
304 uint64_t generation;
305};
306
314
320 proto_tree* tree;
321 uint64_t generation;
322};
323
331
339
344 lua_State* state;
347};
348
354typedef void (*tap_extractor_t)(lua_State* L, const void* data);
355
369
377 FILE_T file;
379 bool expired;
380};
381
393
399 bool expired;
400};
401
406 const wtap_rec* rec;
407 const uint8_t* pd;
408 bool expired;
409};
410
435
440 GDir* dir;
441 char* ext;
442 char* path;
443};
444
449 struct progdlg* pw;
450 char* title;
451 char* task;
452 bool stopped;
453};
454
458typedef struct {
459 const char* name;
461} tappable_t;
462
466typedef struct {
467 const char* str;
468 enum ftenum id;
470
474typedef struct {
475 const char* str;
478
479typedef wslua_pref_t* Pref;
480typedef wslua_pref_t* Prefs;
481typedef struct _wslua_field_t* ProtoField;
482typedef struct _wslua_expert_field_t* ProtoExpert;
483typedef struct _wslua_proto_t* Proto;
484typedef struct _wslua_distbl_t* DissectorTable;
485typedef dissector_handle_t Dissector;
486typedef GByteArray* ByteArray;
487typedef gcry_cipher_hd_t* GcryptCipher;
488typedef struct _wslua_tvb* Tvb;
489typedef struct _wslua_tvbrange* TvbRange;
490typedef struct _wslua_col_info* Column;
491typedef struct _wslua_cols* Columns;
492typedef struct _wslua_pinfo* Pinfo;
493typedef struct _wslua_treeitem* TreeItem;
494typedef address* Address;
495typedef nstime_t* NSTime;
496typedef int64_t Int64;
497typedef uint64_t UInt64;
498typedef struct _wslua_header_field_info* Field;
499typedef struct _wslua_field_info* FieldInfo;
500typedef struct _wslua_tap* Listener;
501typedef struct _wslua_tw* TextWindow;
502typedef struct _wslua_progdlg* ProgDlg;
503typedef struct _wslua_file* File;
504typedef struct _wslua_captureinfo* CaptureInfo;
505typedef struct _wslua_captureinfo* CaptureInfoConst;
506typedef struct _wslua_rec* FrameInfo;
507typedef struct _wslua_const_rec* FrameInfoConst;
508typedef struct _wslua_filehandler* FileHandler;
509typedef wtap_dumper* Dumper;
510typedef struct lua_pseudo_header* PseudoHeader;
511typedef tvbparse_t* Parser;
512typedef tvbparse_wanted_t* Rule;
513typedef tvbparse_elem_t* Node;
514typedef tvbparse_action_t* Shortcut;
515typedef struct _wslua_dir* Dir;
516typedef struct _wslua_private_table* PrivateTable;
517typedef struct _wslua_conversation* Conversation;
518typedef char* Struct;
519
520/*
521 * toXxx(L,idx) gets a Xxx from an index (Lua Error if fails)
522 * checkXxx(L,idx) gets a Xxx from an index after calling check_code (No Lua Error if it fails)
523 * pushXxx(L,xxx) pushes an Xxx into the stack
524 * isXxx(L,idx) tests whether we have an Xxx at idx
525 * shiftXxx(L,idx) removes and returns an Xxx from idx only if it has a type of Xxx, returns NULL otherwise
526 * WSLUA_CLASS_DEFINE must be used with a trailing ';'
527 * (a dummy typedef is used to be syntactically correct)
528 */
529#define WSLUA_CLASS_DEFINE(C,check_code) \
530 WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
531
532#define WSLUA_CLASS_DEFINE_BASE(C,check_code,retval) \
533 WSLUA_CLASS_DEFINE_BASE_PUSH(C,check_code,retval,)
534
535/*
536 * push_code is run in push##C after the new userdata is created,
537 * with the pushed value in v.
538 */
539#define WSLUA_CLASS_DEFINE_BASE_PUSH(C,check_code,retval,push_code) \
540C to##C(lua_State* L, int idx) { \
541 C* v = (C*)lua_touserdata (L, idx); \
542 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
543 return v ? *v : retval; \
544} \
545C check##C(lua_State* L, int idx) { \
546 C* p; \
547 luaL_checktype(L,idx,LUA_TUSERDATA); \
548 p = (C*)luaL_checkudata(L, idx, #C); \
549 check_code; \
550 return p ? *p : retval; \
551} \
552C* push##C(lua_State* L, C v) { \
553 C* p; \
554 luaL_checkstack(L,2,"Unable to grow stack\n"); \
555 p = (C*)lua_newuserdata(L,sizeof(C)); *p = v; \
556 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
557 push_code; \
558 return p; \
559}\
560bool is##C(lua_State* L,int i) { \
561 void *p; \
562 if(!lua_isuserdata(L,i)) return false; \
563 p = lua_touserdata(L, i); \
564 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
565 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
566 lua_pop(L, 2); \
567 return p ? true : false; \
568} \
569C shift##C(lua_State* L,int i) { \
570 C* p; \
571 if(!lua_isuserdata(L,i)) return retval; \
572 p = (C*)lua_touserdata(L, i); \
573 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
574 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
575 lua_pop(L, 2); \
576 if (p) { lua_remove(L,i); return *p; }\
577 else return retval;\
578} \
579typedef int dummy##C
580
581/*
582 * Classes whose objects are created per packet (Tvb, TvbRange, Pinfo,
583 * TreeItem, etc.) are defined with WSLUA_CLASS_DEFINE_INLINE instead.
584 * C is a pointer to a struct (or other object type), and that object is
585 * stored in the full userdata itself instead of separately allocated.
586 * Such classes have no __gc metamethod, so that the Lua garbage collector
587 * can free them in a single cycle, and knows their size.
588 *
589 * Objects that refer to Wireshark structures which are only valid during
590 * the dissection of a packet record the wslua_packet_generation in which
591 * they were created and are expired once it changes, which is checked
592 * with WSLUA_EXPIRED() before each access.
593 *
594 * toXxx and checkXxx return a pointer into the userdata, which is valid
595 * only as long as the userdata is reachable, e.g. on the stack.
596 * pushXxx(L,v) copies the object pointed to by v into a new userdata and
597 * returns a pointer to the copy.
598 * shiftXxx(L,i,buf) copies the object into buf before removing it from
599 * the stack (after which it may be collected), and returns buf.
600 *
601 * WSLUA_CLASS_DEFINE_INLINE_BASE does not define pushXxx, so that a class
602 * whose objects have variable size (such as Address) can define its own.
603 */
604#define WSLUA_CLASS_DEFINE_INLINE_BASE(C,check_code) \
605C to##C(lua_State* L, int idx) { \
606 C v = (C)lua_touserdata (L, idx); \
607 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
608 return v; \
609} \
610C check##C(lua_State* L, int idx) { \
611 C p; \
612 luaL_checktype(L,idx,LUA_TUSERDATA); \
613 p = (C)luaL_checkudata(L, idx, #C); \
614 check_code; \
615 return p; \
616} \
617bool is##C(lua_State* L,int i) { \
618 void *p; \
619 if(!lua_isuserdata(L,i)) return false; \
620 p = lua_touserdata(L, i); \
621 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
622 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
623 lua_pop(L, 2); \
624 return p ? true : false; \
625} \
626C shift##C(lua_State* L,int i,C buf) { \
627 C p; \
628 if(!lua_isuserdata(L,i)) return NULL; \
629 p = (C)lua_touserdata(L, i); \
630 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
631 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
632 lua_pop(L, 2); \
633 if (p) { *buf = *p; lua_remove(L,i); return buf; }\
634 else return NULL;\
635} \
636typedef int dummy##C
637
638#define WSLUA_CLASS_DEFINE_INLINE(C,check_code) \
639C push##C(lua_State* L, C v) { \
640 C p; \
641 luaL_checkstack(L,2,"Unable to grow stack\n"); \
642 p = (C)lua_newuserdata(L,sizeof(*v)); *p = *v; \
643 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
644 return p; \
645}\
646WSLUA_CLASS_DEFINE_INLINE_BASE(C,check_code)
647
652extern uint64_t wslua_packet_generation;
653
655#define WSLUA_EXPIRED(obj) ((obj)->generation != wslua_packet_generation)
656
663extern void wslua_expire_packet_objects(void);
664
669extern uint64_t wslua_file_generation;
670
672#define WSLUA_FILE_EXPIRED(obj) ((obj)->generation != wslua_file_generation)
673
679extern uint64_t wslua_state_generation;
680
689extern void wslua_gc_report_external(lua_State* L, size_t bytes);
690
695 const char* fieldname;
696 lua_CFunction getfunc;
697 lua_CFunction setfunc;
699
710extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter);
711
712#define WSLUA_TYPEOF_FIELD "__typeof"
713
714#ifdef HAVE_LUA
715
716/* temporary transition macro to reduce duplication in WSLUA_REGISTER_xxx. */
717#define WSLUA_REGISTER_GC(C) \
718 luaL_getmetatable(L, #C); \
719 /* add the '__gc' metamethod with a C-function named Class__gc */ \
720 /* this will force ALL wslua classes to have a Class__gc function defined, which is good */ \
721 lua_pushcfunction(L, C ## __gc); \
722 lua_setfield(L, -2, "__gc"); \
723 /* pop the metatable */ \
724 lua_pop(L, 1)
725
726#define __WSLUA_REGISTER_META(C, ATTRS) { \
727 const wslua_class C ## _class = { \
728 .name = #C, \
729 .instance_meta = C ## _meta, \
730 .attrs = ATTRS \
731 }; \
732 wslua_register_classinstance_meta(L, &C ## _class); \
733}
734
735#define WSLUA_REGISTER_META(C) { __WSLUA_REGISTER_META(C, NULL) WSLUA_REGISTER_GC(C); }
736#define WSLUA_REGISTER_META_WITH_ATTRS(C) \
737 { __WSLUA_REGISTER_META(C, C ## _attributes) WSLUA_REGISTER_GC(C); }
738
739#define __WSLUA_REGISTER_CLASS(C, ATTRS) { \
740 const wslua_class C ## _class = { \
741 .name = #C, \
742 .class_methods = C ## _methods, \
743 .class_meta = C ## _meta, \
744 .instance_methods = C ## _methods, \
745 .instance_meta = C ## _meta, \
746 .attrs = ATTRS \
747 }; \
748 wslua_register_class(L, &C ## _class); \
749}
750
751#define WSLUA_REGISTER_CLASS(C) { __WSLUA_REGISTER_CLASS(C, NULL) WSLUA_REGISTER_GC(C); }
752#define WSLUA_REGISTER_CLASS_WITH_ATTRS(C) \
753 { __WSLUA_REGISTER_CLASS(C, C ## _attributes) WSLUA_REGISTER_GC(C); }
754
755/* For classes without a __gc metamethod, such as those defined with
756 * WSLUA_CLASS_DEFINE_INLINE, and other classes whose objects need no
757 * finalization and might be created frequently. (Objects whose metatable
758 * has a __gc field take an extra garbage collection cycle to be freed.) */
759#define WSLUA_REGISTER_META_NOGC(C) __WSLUA_REGISTER_META(C, NULL)
760#define WSLUA_REGISTER_META_WITH_ATTRS_NOGC(C) \
761 __WSLUA_REGISTER_META(C, C ## _attributes)
762#define WSLUA_REGISTER_CLASS_NOGC(C) __WSLUA_REGISTER_CLASS(C, NULL)
763#define WSLUA_REGISTER_CLASS_WITH_ATTRS_NOGC(C) \
764 __WSLUA_REGISTER_CLASS(C, C ## _attributes)
765
766#define WSLUA_INIT(L) \
767 luaL_openlibs(L); \
768 wslua_register_classes(L); \
769 wslua_register_functions(L);
770
771#endif
772
773#define WSLUA_FUNCTION extern int
774/* This is for functions intended only to be used in init.lua */
775#define WSLUA_INTERNAL_FUNCTION extern int
776
777#define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
778
779#define WSLUA_REGISTER extern int
780
781#define WSLUA_METHOD static int
782#define WSLUA_CONSTRUCTOR static int
783#define WSLUA_ATTR_SET static int
784#define WSLUA_ATTR_GET static int
785#define WSLUA_METAMETHOD static int
786
787#define WSLUA_METHODS static const luaL_Reg
788#define WSLUA_META static const luaL_Reg
789#define WSLUA_CLASS_FNREG(class,name) { #name, class##_##name }
790#define WSLUA_CLASS_FNREG_ALIAS(class,aliasname,name) { #aliasname, class##_##name }
791#define WSLUA_CLASS_MTREG(class,name) { "__" #name, class##__##name }
792
793#define WSLUA_ATTRIBUTES static const wslua_attribute_table
794/* following are useful macros for the rows in the array created by above */
795#define WSLUA_ATTRIBUTE_RWREG(class,name) { #name, class##_get_##name, class##_set_##name }
796#define WSLUA_ATTRIBUTE_ROREG(class,name) { #name, class##_get_##name, NULL }
797#define WSLUA_ATTRIBUTE_WOREG(class,name) { #name, NULL, class##_set_##name }
798
799/* Body of a __pairs metamethod that hands the generic-for protocol
800 * a stateless iterator `C##_pairs_iter`. The iterator must accept
801 * (self, prev_key_or_nil) and return the next (key, value) pair or a
802 * single nil when done. Use inside a WSLUA_METAMETHOD body so the
803 * caller retains control of any doc comments shown in the manual. */
804#define WSLUA_STATELESS_PAIRS_BODY(C) \
805 check##C(L, 1); \
806 lua_pushcfunction(L, C##_pairs_iter); \
807 lua_pushvalue(L, 1); \
808 lua_pushnil(L); \
809 return 3
810
811#define WSLUA_ATTRIBUTE_FUNC_SETTER(C,field) \
812 static int C##_set_##field (lua_State* L) { \
813 C obj = check##C (L,1); \
814 if (! lua_isfunction(L,-1) ) \
815 return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
816 if (obj->field##_ref != LUA_NOREF) \
817 /* there was one registered before, remove it */ \
818 luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
819 obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
820 return 0; \
821 } \
822 /* silly little trick so we can add a semicolon after this macro */ \
823 typedef void __dummy##C##_set_##field
824
825#define WSLUA_ATTRIBUTE_GET(C,name,block) \
826 static int C##_get_##name (lua_State* L) { \
827 C obj = check##C (L,1); \
828 block \
829 return 1; \
830 } \
831 /* silly little trick so we can add a semicolon after this macro */ \
832 typedef void __dummy##C##_get_##name
833
834#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
835 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
836
837#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,name,member) \
838 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
839
840#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C,member) \
841 WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
842
843#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \
844 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
845
846#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,name,member) \
847 WSLUA_ATTRIBUTE_GET(C,name, { \
848 lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
849 })
850
851#define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
852 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
853
854#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
855 WSLUA_ATTRIBUTE_GET(C,name, { \
856 char* str; \
857 if ((obj->member) && (obj->member->len > 0)) { \
858 if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
859 lua_pushstring(L,str); \
860 } \
861 } \
862 })
863
864/*
865 * XXX - we need to support Lua programs getting instances of a "multiple
866 * allowed" option other than the first option.
867 */
868#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
869 WSLUA_ATTRIBUTE_GET(C,name, { \
870 char* str; \
871 if ((obj->member) && (obj->member->len > 0)) { \
872 if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
873 lua_pushstring(L,str); \
874 } \
875 } \
876 })
877
878#define WSLUA_ATTRIBUTE_SET(C,name,block) \
879 static int C##_set_##name (lua_State* L) { \
880 C obj = check##C (L,1); \
881 block; \
882 return 0; \
883 } \
884 /* silly little trick so we can add a semicolon after this macro */ \
885 typedef void __dummy##C##_set_##name
886
887#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C,name,member) \
888 WSLUA_ATTRIBUTE_SET(C,name, { \
889 if (! lua_isboolean(L,-1) ) \
890 return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
891 obj->member = lua_toboolean(L,-1); \
892 })
893
894/* to make this integral-safe, we treat it as int32 and then cast
895 Note: This will truncate 64-bit integers (but then Lua itself only has doubles */
896#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,name,member,cast) \
897 WSLUA_ATTRIBUTE_SET(C,name, { \
898 if (! lua_isinteger(L,-1) ) \
899 return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
900 obj->member = (cast) wslua_toint32(L,-1); \
901 })
902
903#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C,member,cast) \
904 WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
905
906#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \
907 static int C##_set_##field (lua_State* L) { \
908 C obj = check##C (L,1); \
909 char* s = NULL; \
910 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
911 s = g_strdup(lua_tostring(L,-1)); \
912 } else { \
913 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
914 } \
915 if (obj->member != NULL && need_free) \
916 g_free((void*) obj->member); \
917 obj->member = s; \
918 return 0; \
919 } \
920 /* silly little trick so we can add a semicolon after this macro */ \
921 typedef void __dummy##C##_set_##field
922
923#define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
924 WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
925
926#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \
927 static int C##_set_##field (lua_State* L) { \
928 C obj = check##C (L,1); \
929 char* s = NULL; \
930 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
931 s = g_strdup(lua_tostring(L,-1)); \
932 } else { \
933 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
934 } \
935 if ((obj->member) && (obj->member->len > 0)) { \
936 wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
937 } \
938 g_free(s); \
939 return 0; \
940 } \
941 /* silly little trick so we can add a semicolon after this macro */ \
942 typedef void __dummy##C##_set_##field
943
944#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
945 static int C##_set_##field (lua_State* L) { \
946 C obj = check##C (L,1); \
947 char* s = NULL; \
948 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
949 s = g_strdup(lua_tostring(L,-1)); \
950 } else { \
951 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
952 } \
953 if ((obj->member) && (obj->member->len > 0)) { \
954 wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
955 } \
956 g_free(s); \
957 return 0; \
958 } \
959 /* silly little trick so we can add a semicolon after this macro */ \
960 typedef void __dummy##C##_set_##field
961
962#define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": ", error); }
963#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
964#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
965
966#define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
967#define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
968#define WSLUA_REG_GLOBAL_INTEGER(L,n,v) { lua_pushinteger(L,v); lua_setglobal(L,n); }
969
970#define WSLUA_RETURN(i) return (i)
971
972#define WSLUA_API extern
973
974/* empty macro arguments trigger ISO C90 warnings, so do this */
975#define NOP (void)p
976
977#define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
978
979#define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
980 luaL_argerror(L,idx,"null " s); \
981 } else if ((*p)->expired) { \
982 luaL_argerror(L,idx,"expired " s); \
983 }
984
985/* For classes defined with WSLUA_CLASS_DEFINE_INLINE */
986#define FAIL_ON_EXPIRED(s) if (WSLUA_EXPIRED(p)) luaL_argerror(L,idx,"expired " s)
987
988#define WSLUA_CLASS_DECLARE(C) \
989extern C to##C(lua_State* L, int idx); \
990extern C check##C(lua_State* L, int idx); \
991extern C* push##C(lua_State* L, C v); \
992extern int C##_register(lua_State* L); \
993extern bool is##C(lua_State* L,int i); \
994extern C shift##C(lua_State* L,int i)
995
996#define WSLUA_CLASS_DECLARE_INLINE(C) \
997extern C to##C(lua_State* L, int idx); \
998extern C check##C(lua_State* L, int idx); \
999extern C push##C(lua_State* L, C v); \
1000extern int C##_register(lua_State* L); \
1001extern bool is##C(lua_State* L,int i); \
1002extern C shift##C(lua_State* L,int i,C buf)
1003
1004
1005/* Throws a Wireshark exception, catchable via normal exceptions.h routines. */
1006#define THROW_LUA_ERROR(...) \
1007 THROW_FORMATTED(DissectorError, __VA_ARGS__)
1008
1009/* Catches any Wireshark exceptions in code and convert it into a Lua error.
1010 * Normal restrictions for TRY/CATCH apply, in particular, do not return!
1011 *
1012 * This means do not call lua[L]_error() inside code, as that longjmps out
1013 * of the TRY block to the Lua pcall! Use THROW_LUA_ERROR, which is caught
1014 * and then converted into a Lua error.
1015 *
1016 * XXX: We CATCH_ALL here, although there's little point in catching
1017 * OutOfMemoryError here. (Is CATCH_BOUNDS_AND_DISSECTOR_ERRORS sufficient?)
1018 * There are some Exceptions that we catch and show but don't want to add
1019 * the Lua error malformed expert info to the tree: BoundsError,
1020 * FragmentBoundsError, and ScsiBoundsError (show_exception doesn't consider
1021 * those malformed). The traceback might (or might not) be useful for those.
1022 * Putting an extra malformed expert info in the tree in the cases that are
1023 * malformed seems not so bad, but we might want to reduce that. Perhaps
1024 * at least we could have a separate LuaError type and not call show_exception
1025 * for that (we still need to handle some Lua errors that don't use this in
1026 * dissector_error_handler.)
1027 */
1028#define WRAP_NON_LUA_EXCEPTIONS(code) \
1029{ \
1030 volatile bool has_error = false; \
1031 TRY { \
1032 code \
1033 } CATCH3(BoundsError, FragmentBoundsError, ScsiBoundsError) { \
1034 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
1035 } CATCH_ALL { \
1036 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
1037 lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
1038 has_error = true; \
1039 } ENDTRY; \
1040 if (has_error) { lua_error(L); } \
1041}
1042
1043
1044extern packet_info* lua_pinfo;
1045extern TreeItem lua_tree;
1046extern tvbuff_t* lua_tvb;
1047extern bool lua_initialized;
1048extern int lua_dissectors_table_ref;
1049extern int lua_heur_dissectors_table_ref;
1050extern const char* lua_app_env_var_prefix;
1051extern GPtrArray* lua_outstanding_FuncSavers;
1052
1053WSLUA_DECLARE_CLASSES()
1054WSLUA_DECLARE_FUNCTIONS()
1055
1063extern lua_State* wslua_state(void);
1064
1065
1066/* wslua_internals.c */
1073typedef struct _wslua_class {
1074 const char *name;
1075 const luaL_Reg *class_methods;
1076 const luaL_Reg *class_meta;
1077 const luaL_Reg *instance_methods;
1078 const luaL_Reg *instance_meta;
1081
1090void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def);
1091
1098void wslua_register_class(lua_State *L, const wslua_class *cls_def);
1099
1109extern int wslua__concat(lua_State* L);
1110
1122extern bool wslua_toboolean(lua_State* L, int n);
1123
1133extern bool wslua_checkboolean(lua_State* L, int n);
1134
1143extern bool wslua_optbool(lua_State* L, int n, bool def);
1144
1152extern lua_Integer wslua_tointeger(lua_State* L, int n);
1153
1162extern int wslua_optboolint(lua_State* L, int n, int def);
1163
1172extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l);
1173
1181extern const char* wslua_checkstring_only(lua_State* L, int n);
1182
1190extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
1191
1192extern const char* wslua_typeof_unknown;
1193
1203extern const char *wslua_typeof(lua_State *L, int idx);
1204
1215extern bool wslua_get_table(lua_State *L, int idx, const char *name);
1216
1226extern bool wslua_get_field(lua_State *L, int idx, const char *name);
1227
1239extern int dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1240 proto_tree *tree, void *data);
1241
1254extern bool heur_dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1255 proto_tree *tree, void *data);
1256
1264extern expert_field* wslua_get_expert_field(const int group, const int severity);
1265
1272extern void wslua_prefs_changed(void);
1273
1279extern void proto_register_lua(void);
1280
1288extern GString* lua_register_all_taps(void);
1289
1297extern void wslua_prime_dfilter(epan_dissect_t *edt);
1298
1304extern bool wslua_has_field_extractors(void);
1305
1313extern void lua_prime_all_fields(proto_tree* tree);
1314
1324extern void wslua_set_postdissector_wanted_hfids(const GArray* hfids);
1325
1334extern int Proto_commit(lua_State* L);
1335
1341extern void clear_outstanding_FuncSavers(lua_State* L);
1342
1351extern void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1352
1361extern int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1362
1371extern void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1372
1381extern int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1382
1393extern uint64_t getUInt64(lua_State *L, int i);
1394
1402extern Tvb push_Tvb(lua_State* L, tvbuff_t* tvb);
1403
1413extern bool push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len);
1414
1422extern Pinfo push_Pinfo(lua_State* L, packet_info* p);
1423
1431extern Conversation push_Conversation(lua_State* L, conversation_t* conv);
1432
1438extern int get_hf_wslua_text(void);
1439
1448extern TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item);
1449
1457extern FieldInfo push_FieldInfo(lua_State *L, field_info* f);
1458
1465extern void wslua_print_stack(char* s, lua_State* L);
1466
1476extern void wslua_init(register_cb cb, void *client_data, const char* app_env_var_prefix);
1477
1481extern void wslua_early_cleanup(void);
1482
1488extern void wslua_cleanup(void);
1489
1497
1504extern int wslua_set_tap_enums(lua_State* L);
1505
1506extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr);
1507
1514extern char* wslua_get_actual_filename(const char* fname);
1515
1528extern int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep);
1529
1539extern int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep);
1540
1547extern int luaopen_rex_pcre2(lua_State *L);
1548
1554extern const char* get_current_plugin_version(void);
1555
1559extern void clear_current_plugin_version(void);
1560
1569extern int wslua_deregister_heur_dissectors(lua_State* L);
1570
1579extern int wslua_deregister_protocols(lua_State* L);
1580
1589extern int wslua_deregister_dissector_tables(lua_State* L);
1590
1599extern int wslua_deregister_listeners(lua_State* L);
1600
1607extern int wslua_deregister_fields(lua_State* L);
1608
1616extern int wslua_deregister_filehandlers(lua_State* L);
1617
1624extern void wslua_deregister_menus(void);
1625
1634extern void wslua_init_wtap_filetypes(lua_State* L);
1635
1642
1643#endif
1644
1645/*
1646 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1647 *
1648 * Local variables:
1649 * c-basic-offset: 4
1650 * tab-width: 8
1651 * indent-tabs-mode: nil
1652 * End:
1653 *
1654 * vi: set shiftwidth=4 tabstop=8 expandtab:
1655 * :indentSize=4:tabSize=8:noTabs=true:
1656 */
struct _address address
Holds a network or link-layer address of any supported type.
struct conversation conversation_t
conversation_type
Conversation key types recognized by Wireshark dissectors.
Definition conversation.h:115
struct epan_dissect epan_dissect_t
Opaque type representing a single packet dissection context.
Definition epan.h:62
ftenum
Fundamental field value types used throughout the Wireshark dissector framework.
Definition ftypes.h:26
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
proto_node proto_item
Definition proto.h:952
struct _header_field_info header_field_info
Definition proto.h:795
pref_type_e
Discriminator tag identifying the type and UI representation of a preference entry.
Definition prefs-int.h:138
struct epan_range range_t
Defines a single attribute entry in a Lua class attribute dispatch table, binding a field name to its...
Definition wslua.h:694
lua_CFunction getfunc
Definition wslua.h:696
lua_CFunction setfunc
Definition wslua.h:697
const char * fieldname
Definition wslua.h:695
Wraps capture file metadata for access from the Lua scripting environment.
Definition wslua.h:388
bool expired
Definition wslua.h:391
wtap_dumper * wdh
Definition wslua.h:390
wtap * wth
Definition wslua.h:389
Type for defining new classes.
Definition wslua.h:1073
const wslua_attribute_table * attrs
Definition wslua.h:1079
const luaL_Reg * class_meta
Definition wslua.h:1076
const char * name
Definition wslua.h:1074
const luaL_Reg * class_methods
Definition wslua.h:1075
const luaL_Reg * instance_methods
Definition wslua.h:1077
const luaL_Reg * instance_meta
Definition wslua.h:1078
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
uint64_t generation
Definition wslua.h:288
int col
Definition wslua.h:287
Wraps a column_info for bulk column access from the Lua scripting environment.
Definition wslua.h:294
column_info * cinfo
Definition wslua.h:295
uint64_t generation
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:405
const wtap_rec * rec
Definition wslua.h:406
const uint8_t * pd
Definition wslua.h:407
bool expired
Definition wslua.h:408
Associates a conversation with a Lua registry reference holding per-conversation dissector data.
Definition wslua.h:264
uint64_t state_generation
Definition wslua.h:267
conversation_t * conv
Definition wslua.h:265
int data_ref
Definition wslua.h:266
Wraps a conversation_t, which is allocated in file scope, tracking expiry.
Definition wslua.h:310
uint64_t generation
Definition wslua.h:312
conversation_t * conv
Definition wslua.h:311
Wraps a GDir iterator with extension filtering and path tracking for directory traversal from Lua.
Definition wslua.h:439
GDir * dir
Definition wslua.h:440
char * ext
Definition wslua.h:441
char * path
Definition wslua.h:442
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:189
const char * abbrev
Definition wslua.h:191
expert_field ids
Definition wslua.h:190
const char * text
Definition wslua.h:192
int severity
Definition wslua.h:194
int group
Definition wslua.h:193
Wraps a field_info for access from the Lua scripting environment, tracking validity.
Definition wslua.h:335
uint64_t generation
Definition wslua.h:337
field_info * ws_fi
Definition wslua.h:336
Describes a protocol header field registered from a Lua dissector script.
Definition wslua.h:173
unsigned base
Definition wslua.h:180
int hfid
Definition wslua.h:174
char * name
Definition wslua.h:176
char * blob
Definition wslua.h:178
char * abbrev
Definition wslua.h:177
const void * vs
Definition wslua.h:181
uint64_t mask
Definition wslua.h:183
int ett
Definition wslua.h:175
int valuestring_ref
Definition wslua.h:182
enum ftenum type
Definition wslua.h:179
Wraps a wtap file handle or wtap_dumper for read/write access from the Lua scripting environment.
Definition wslua.h:376
FILE_T file
Definition wslua.h:377
wtap_dumper * wdh
Definition wslua.h:378
bool expired
Definition wslua.h:379
Describes a Lua-registered file format handler for reading and/or writing capture files.
Definition wslua.h:414
int seek_read_ref
Definition wslua.h:424
int read_open_ref
Definition wslua.h:422
int write_ref
Definition wslua.h:429
int write_close_ref
Definition wslua.h:430
int file_type
Definition wslua.h:431
char * type
Definition wslua.h:419
char * internal_description
Definition wslua.h:418
int write_open_ref
Definition wslua.h:428
bool is_writer
Definition wslua.h:417
bool registered
Definition wslua.h:432
char * extensions
Definition wslua.h:420
int read_ref
Definition wslua.h:423
int can_write_encap_ref
Definition wslua.h:427
lua_State * L
Definition wslua.h:421
int seq_read_close_ref
Definition wslua.h:426
int read_close_ref
Definition wslua.h:425
struct file_type_subtype_info finfo
Definition wslua.h:415
bool removed
Definition wslua.h:433
bool is_reader
Definition wslua.h:416
Stores Lua function references to prevent garbage collection for functions used by tcp_dissect_pdus()...
Definition wslua.h:343
int get_len_ref
Definition wslua.h:345
lua_State * state
Definition wslua.h:344
int dissect_ref
Definition wslua.h:346
Tracks a registered header field and its associated info for internal use by the Lua field registrati...
Definition wslua.h:327
header_field_info * hfi
Definition wslua.h:329
char * name
Definition wslua.h:328
Wraps a packet_info pointer with expiry tracking for use in the Lua scripting environment.
Definition wslua.h:145
packet_info * ws_pinfo
Definition wslua.h:146
uint64_t generation
Definition wslua.h:147
Represents a single Wireshark preference registered from a Lua dissector script.
Definition wslua.h:200
void * p
Definition wslua.h:213
uat_field_t * uat_field_list
Definition wslua.h:228
struct _wslua_pref_t::@217040237106063345351274302246224144004201267160::@020354106077367206330115123310115110030014002216 enum_info
unsigned u
Definition wslua.h:209
struct _wslua_pref_t::@217040237106063345351274302246224144004201267160::@302242053311026123101057072277315265131022170020 uat_field_list_info
bool radio_buttons
Definition wslua.h:223
char * desc
Definition wslua.h:203
struct _wslua_proto_t * proto
Definition wslua.h:235
char * s
Definition wslua.h:210
char * default_s
Definition wslua.h:231
bool b
Definition wslua.h:208
uint32_t max_value
Definition wslua.h:218
char * name
Definition wslua.h:201
range_t * r
Definition wslua.h:212
int ref
Definition wslua.h:236
struct _wslua_pref_t * next
Definition wslua.h:234
const enum_val_t * enumvals
Definition wslua.h:222
char * label
Definition wslua.h:202
int e
Definition wslua.h:211
pref_type_e type
Definition wslua.h:204
union _wslua_pref_t::@265022225263267215273077122115002146144266147256 value
Wraps a GHashTable for use as a Lua private data table, tracking expiry.
Definition wslua.h:302
GHashTable * table
Definition wslua.h:303
uint64_t generation
Definition wslua.h:304
Wraps a GUI progress dialog for control from the Lua scripting environment.
Definition wslua.h:448
char * title
Definition wslua.h:450
struct progdlg * pw
Definition wslua.h:449
bool stopped
Definition wslua.h:452
char * task
Definition wslua.h:451
Represents a Wireshark protocol registered from a Lua dissector script.
Definition wslua.h:242
bool expired
Definition wslua.h:258
int ett
Definition wslua.h:247
GArray * eia
Definition wslua.h:256
dissector_handle_t handle
Definition wslua.h:253
int fields
Definition wslua.h:249
bool is_postdissector
Definition wslua.h:257
expert_module_t * expert_module
Definition wslua.h:251
int expert_info_table_ref
Definition wslua.h:250
char * desc
Definition wslua.h:245
module_t * prefs_module
Definition wslua.h:252
GArray * hfa
Definition wslua.h:254
int hfid
Definition wslua.h:246
GArray * etta
Definition wslua.h:255
char * name
Definition wslua.h:243
char * loname
Definition wslua.h:244
wslua_pref_t prefs
Definition wslua.h:248
Wraps a wtap_rec for access from the Lua scripting environment, tracking validity.
Definition wslua.h:397
wtap_rec * rec
Definition wslua.h:398
bool expired
Definition wslua.h:399
Represents a Lua tap listener, binding a tap name and filter to Lua callback functions.
Definition wslua.h:359
int draw_ref
Definition wslua.h:365
bool all_fields
Definition wslua.h:367
lua_State * L
Definition wslua.h:363
int packet_ref
Definition wslua.h:364
char * filter
Definition wslua.h:361
int reset_ref
Definition wslua.h:366
char * name
Definition wslua.h:360
tap_extractor_t extractor
Definition wslua.h:362
Wraps a proto_item and its associated proto_tree for manipulation from the Lua scripting environment.
Definition wslua.h:318
proto_tree * tree
Definition wslua.h:320
proto_item * item
Definition wslua.h:319
uint64_t generation
Definition wslua.h:321
Wraps a tvbuff_t with expiry tracking for use in the Lua scripting environment.
Definition wslua.h:137
tvbuff_t * ws_tvb
Definition wslua.h:138
uint64_t generation
Definition wslua.h:139
Represents a sub-range of a Lua tvbuff, defined by an offset and length within the parent tvb.
Definition wslua.h:154
unsigned offset
Definition wslua.h:156
struct _wslua_tvb tvb
Definition wslua.h:155
unsigned len
Definition wslua.h:157
Wraps a funnel text window for use in the Lua scripting environment, tracking expiry and close callba...
Definition wslua.h:163
funnel_text_window_t * ws_tw
Definition wslua.h:164
bool expired
Definition wslua.h:165
void * close_cb_data
Definition wslua.h:166
char * title
Definition wslua.h:167
Definition packet-bt-dht.c:98
Defines a single named value within an enumerated preference or option type.
Definition params.h:16
Pairs an expert info index with its associated header field index for registration and display.
Definition expert.h:41
Definition proto.h:847
Describes a single capture file type/subtype, including its metadata, capability flags,...
Definition wtap.h:2051
Definition file-pcapng.h:57
Definition wslua_dumper.c:53
Definition nstime.h:26
Define the structure describing a progress dialog.
Definition progress_frame.h:28
Maps a tap name to its Lua data extractor callback for use in the tappable protocol registry.
Definition wslua.h:458
tap_extractor_t extractor
Definition wslua.h:460
const char * name
Definition wslua.h:459
Maps a conversation type name string to its conversation_type identifier for use in Lua conversation ...
Definition wslua.h:474
const char * str
Definition wslua.h:475
conversation_type id
Definition wslua.h:476
Maps a field type name string to its ftenum identifier for use in Lua field type lookups.
Definition wslua.h:466
const char * str
Definition wslua.h:467
enum ftenum id
Definition wslua.h:468
Wiretap dumper handle and associated state.
Definition wtap_module.h:166
Represents a single capture record read from or written to a capture file, regardless of record type.
Definition wtap.h:1613
Definition wtap_module.h:58
struct _uat_field_t uat_field_t
Describes a single editable field within a UAT (User Accessible Table).
void wslua_init(register_cb cb, void *client_data, const char *app_env_var_prefix)
Initialize Wireshark Lua support.
Definition init_wslua.c:1747
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
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
Conversation push_Conversation(lua_State *L, conversation_t *conv)
Pushes a Conversation onto the Lua stack.
Definition wslua_conversation.c:110
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:2174
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:656
void wslua_cleanup(void)
Cleans up Lua resources.
Definition init_wslua.c:2221
int wslua_deregister_protocols(lua_State *L)
Deregisters all Lua-based protocol dissectors.
Definition wslua_proto.c:799
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:1106
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:760
bool wslua_has_field_extractors(void)
Checks if there are any registered field extractors.
Definition wslua_field.c:501
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:215
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:783
int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter)
Registers attributes for a Lua table.
Pinfo push_Pinfo(lua_State *L, packet_info *p)
Pushes a packet information structure onto the Lua stack.
Definition wslua_pinfo.c:33
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:615
FieldInfo push_FieldInfo(lua_State *L, field_info *f)
Pushes a field information object onto the Lua stack.
Definition wslua_field.c:34
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:74
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.
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:338
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:1277
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:752
int Proto_commit(lua_State *L)
Commits protocol changes.
Definition wslua_proto.c:901
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 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:451
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:78
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:52
void wslua_expire_packet_objects(void)
Expires all existing per-packet Lua objects (Tvb, TvbRange, Pinfo, etc.).
Definition init_wslua.c:165
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:354
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...
void wslua_gc_report_external(lua_State *L, size_t bytes)
Reports memory allocated outside of Lua for a Lua object (such as the contents of a ByteArray) to the...
Definition init_wslua.c:700
uint64_t getUInt64(lua_State *L, int i)
Retrieves a 64-bit unsigned integer from the Lua stack.
Definition wslua_int64.c:594
lua_Integer wslua_tointeger(lua_State *L, int n)
Converts a Lua value to an integer.
Definition wslua_internals.c:85
void wslua_prime_dfilter(epan_dissect_t *edt)
Prime the dissector filter with a protocol tree.
Definition wslua_field.c:494
void wslua_set_postdissector_wanted_hfids(const GArray *hfids)
Sets the fields wanted by every Lua postdissector.
Definition wslua_proto.c:888
TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item)
Pushes a TreeItem onto the Lua stack.
Definition wslua_tree.c:27
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