| Wireshark 4.7.3 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
33#include <wsutil/report_message.h>
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
137 struct _wslua_tvb {
138 tvbuff_t* ws_tvb;
139 bool expired;
140 bool need_free;
141};
142
146 struct _wslua_pinfo {
147 packet_info* ws_pinfo;
148 bool expired;
149};
150
151
155 struct _wslua_tvbrange {
156 struct _wslua_tvb* tvb;
157 unsigned offset;
158 unsigned len;
159};
160
164 struct _wslua_tw {
165 funnel_text_window_t* ws_tw;
166 bool expired;
167 void* close_cb_data;
168 char* title;
169};
170
174 typedef struct _wslua_field_t {
175 int hfid;
176 int ett;
177 char* name;
178 char* abbrev;
179 char* blob;
180 enum ftenum type;
181 unsigned base;
182 const void* vs;
183 int valuestring_ref;
184 uint64_t mask;
185} wslua_field_t;
186
190 typedef struct _wslua_expert_field_t {
191 expert_field ids;
192 const char* abbrev;
193 const char* text;
194 int group;
195 int severity;
196} wslua_expert_field_t;
197
201 typedef struct _wslua_pref_t {
202 char* name;
203 char* label;
204 char* desc;
205 pref_type_e type;
206
208 union {
209 bool b;
210 unsigned u;
211 char* s;
212 int e;
213 range_t* r;
214 void* p;
215 } value;
216
218 union {
219 uint32_t max_value;
220
222 struct {
223 const enum_val_t* enumvals;
224 bool radio_buttons;
225 } enum_info;
226
228 struct {
229 uat_field_t* uat_field_list;
230 } uat_field_list_info;
231
232 char* default_s;
233 } info;
234
235 struct _wslua_pref_t* next;
236 struct _wslua_proto_t* proto;
237 int ref;
238} wslua_pref_t;
239
243 typedef struct _wslua_proto_t {
244 char* name;
245 char* loname;
246 char* desc;
247 int hfid;
248 int ett;
249 wslua_pref_t prefs;
250 int fields;
251 int expert_info_table_ref;
252 expert_module_t* expert_module;
253 module_t* prefs_module;
254 dissector_handle_t handle;
255 GArray* hfa;
256 GArray* etta;
257 GArray* eia;
258 bool is_postdissector;
259 bool expired;
260} wslua_proto_t;
261
265 typedef struct _wslua_conv_data_t {
266 conversation_t* conv;
267 int data_ref;
268} wslua_conv_data_t;
269
273 struct _wslua_distbl_t {
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
285 struct _wslua_col_info {
286 column_info* cinfo;
287 int col;
288 bool expired;
289};
290
294 struct _wslua_cols {
295 column_info* cinfo;
296 bool expired;
297};
298
302 struct _wslua_private_table {
303 GHashTable* table;
304 bool is_allocated;
305 bool expired;
306};
307
311 struct _wslua_treeitem {
312 proto_item* item;
313 proto_tree* tree;
314 bool expired;
315};
316
320 struct _wslua_header_field_info {
321 char* name;
322 header_field_info* hfi;
323};
324
328 struct _wslua_field_info {
329 field_info* ws_fi;
330 bool expired;
331};
332
336 struct _wslua_func_saver {
337 lua_State* state;
338 int get_len_ref;
339 int dissect_ref;
340};
341
347 typedef void (*tap_extractor_t)(lua_State* L, const void* data);
348
352 struct _wslua_tap {
353 char* name;
354 char* filter;
355 tap_extractor_t extractor;
356 lua_State* L;
357 int packet_ref;
358 int draw_ref;
359 int reset_ref;
360 bool all_fields;
361};
362
369 struct _wslua_file {
370 FILE_T file;
371 wtap_dumper* wdh;
372 bool expired;
373};
374
381 struct _wslua_captureinfo {
382 wtap* wth;
383 wtap_dumper* wdh;
384 bool expired;
385};
386
390 struct _wslua_rec {
391 wtap_rec* rec;
392 bool expired;
393};
394
398 struct _wslua_const_rec {
399 const wtap_rec* rec;
400 const uint8_t* pd;
401 bool expired;
402};
403
407 struct _wslua_filehandler {
408 struct file_type_subtype_info finfo;
409 bool is_reader;
410 bool is_writer;
411 char* internal_description;
412 char* type;
413 char* extensions;
414 lua_State* L;
415 int read_open_ref;
416 int read_ref;
417 int seek_read_ref;
418 int read_close_ref;
419 int seq_read_close_ref;
420 int can_write_encap_ref;
421 int write_open_ref;
422 int write_ref;
423 int write_close_ref;
424 int file_type;
425 bool registered;
426 bool removed;
427};
428
432 struct _wslua_dir {
433 GDir* dir;
434 char* ext;
435 char* path;
436};
437
441 struct _wslua_progdlg {
442 struct progdlg* pw;
443 char* title;
444 char* task;
445 bool stopped;
446};
447
451 typedef struct {
452 const char* name;
453 tap_extractor_t extractor;
454} tappable_t;
455
459 typedef struct {
460 const char* str;
461 enum ftenum id;
462} wslua_ft_types_t;
463
467 typedef struct {
468 const char* str;
469 conversation_type id;
470} wslua_conv_types_t;
471
472 typedef wslua_pref_t* Pref;
473 typedef wslua_pref_t* Prefs;
474 typedef struct _wslua_field_t* ProtoField;
475 typedef struct _wslua_expert_field_t* ProtoExpert;
476 typedef struct _wslua_proto_t* Proto;
477 typedef struct _wslua_distbl_t* DissectorTable;
478 typedef dissector_handle_t Dissector;
479 typedef GByteArray* ByteArray;
480 typedef gcry_cipher_hd_t* GcryptCipher;
481 typedef struct _wslua_tvb* Tvb;
482 typedef struct _wslua_tvbrange* TvbRange;
483 typedef struct _wslua_col_info* Column;
484 typedef struct _wslua_cols* Columns;
485 typedef struct _wslua_pinfo* Pinfo;
486 typedef struct _wslua_treeitem* TreeItem;
487 typedef address* Address;
488 typedef nstime_t* NSTime;
489 typedef int64_t Int64;
490 typedef uint64_t UInt64;
491 typedef struct _wslua_header_field_info* Field;
492 typedef struct _wslua_field_info* FieldInfo;
493 typedef struct _wslua_tap* Listener;
494 typedef struct _wslua_tw* TextWindow;
495 typedef struct _wslua_progdlg* ProgDlg;
496 typedef struct _wslua_file* File;
497 typedef struct _wslua_captureinfo* CaptureInfo;
498 typedef struct _wslua_captureinfo* CaptureInfoConst;
499 typedef struct _wslua_rec* FrameInfo;
500 typedef struct _wslua_const_rec* FrameInfoConst;
501 typedef struct _wslua_filehandler* FileHandler;
502 typedef wtap_dumper* Dumper;
503 typedef struct lua_pseudo_header* PseudoHeader;
504 typedef tvbparse_t* Parser;
505 typedef tvbparse_wanted_t* Rule;
506 typedef tvbparse_elem_t* Node;
507 typedef tvbparse_action_t* Shortcut;
508 typedef struct _wslua_dir* Dir;
509 typedef struct _wslua_private_table* PrivateTable;
510 typedef conversation_t* Conversation;
511 typedef 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) \
526 C 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} \
531 C 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} \
538 C* 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}\
545 bool 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} \
554 C 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} \
564 typedef int dummy##C
565
569 typedef struct _wslua_attribute_table {
570 const char* fieldname;
571 lua_CFunction getfunc;
572 lua_CFunction setfunc;
573} wslua_attribute_table;
574
585 extern 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) \
865 extern C to##C(lua_State* L, int idx); \
866 extern C check##C(lua_State* L, int idx); \
867 extern C* push##C(lua_State* L, C v); \
868 extern int C##_register(lua_State* L); \
869 extern bool is##C(lua_State* L,int i); \
870 extern 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
912 extern packet_info* lua_pinfo;
913 extern TreeItem lua_tree;
914 extern tvbuff_t* lua_tvb;
915 extern bool lua_initialized;
916 extern int lua_dissectors_table_ref;
917 extern int lua_heur_dissectors_table_ref;
918 extern const char* lua_app_env_var_prefix;
919 extern 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;
947 const wslua_attribute_table *attrs;
948} wslua_class;
949
958 void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def);
959
966 void wslua_register_class(lua_State *L, const wslua_class *cls_def);
967
977 extern int wslua__concat(lua_State* L);
978
990 extern bool wslua_toboolean(lua_State* L, int n);
991
1001 extern bool wslua_checkboolean(lua_State* L, int n);
1002
1011 extern bool wslua_optbool(lua_State* L, int n, bool def);
1012
1020 extern lua_Integer wslua_tointeger(lua_State* L, int n);
1021
1030 extern int wslua_optboolint(lua_State* L, int n, int def);
1031
1040 extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l);
1041
1049 extern const char* wslua_checkstring_only(lua_State* L, int n);
1050
1058 extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
1059
1060 extern const char* wslua_typeof_unknown;
1061
1071 extern const char *wslua_typeof(lua_State *L, int idx);
1072
1083 extern bool wslua_get_table(lua_State *L, int idx, const char *name);
1084
1094 extern bool wslua_get_field(lua_State *L, int idx, const char *name);
1095
1107 extern int dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1108 proto_tree *tree, void *data);
1109
1122 extern bool heur_dissect_lua(tvbuff_t *tvb, packet_info *pinfo,
1123 proto_tree *tree, void *data);
1124
1132 extern expert_field* wslua_get_expert_field(const int group, const int severity);
1133
1140 extern void wslua_prefs_changed(void);
1141
1147 extern void proto_register_lua(void);
1148
1156 extern GString* lua_register_all_taps(void);
1157
1165 extern void wslua_prime_dfilter(epan_dissect_t *edt);
1166
1172 extern bool wslua_has_field_extractors(void);
1173
1181 extern void lua_prime_all_fields(proto_tree* tree);
1182
1191 extern int Proto_commit(lua_State* L);
1192
1200 extern TreeItem create_TreeItem(proto_tree* tree, proto_item* item);
1201
1207 extern void clear_outstanding_FuncSavers(lua_State* L);
1208
1217 extern void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1218
1227 extern int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1228
1237 extern void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1238
1247 extern int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1248
1259 extern uint64_t getUInt64(lua_State *L, int i);
1260
1268 extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb);
1269
1277 extern int push_wsluaTvb(lua_State* L, Tvb t);
1278
1288 extern bool push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len);
1289
1295 extern void clear_outstanding_Tvb(void);
1296
1300 extern void clear_outstanding_TvbRange(void);
1301
1309 extern Pinfo* push_Pinfo(lua_State* L, packet_info* p);
1310
1314 extern void clear_outstanding_Pinfo(void);
1315
1319 extern void clear_outstanding_Column(void);
1320
1324 extern void clear_outstanding_Columns(void);
1325
1329 extern void clear_outstanding_PrivateTable(void);
1330
1336 extern int get_hf_wslua_text(void);
1337
1346 extern TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item);
1347
1351 extern void clear_outstanding_TreeItem(void);
1352
1360 extern FieldInfo* push_FieldInfo(lua_State *L, field_info* f);
1361
1365 extern void clear_outstanding_FieldInfo(void);
1366
1373 extern void wslua_print_stack(char* s, lua_State* L);
1374
1384 extern void wslua_init(register_cb cb, void *client_data, const char* app_env_var_prefix);
1385
1389 extern void wslua_early_cleanup(void);
1390
1396 extern void wslua_cleanup(void);
1397
1404 extern tap_extractor_t wslua_get_tap_extractor(const char* name);
1405
1412 extern int wslua_set_tap_enums(lua_State* L);
1413
1414 extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr);
1415
1422 extern char* wslua_get_actual_filename(const char* fname);
1423
1436 extern int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep);
1437
1447 extern int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep);
1448
1455 extern int luaopen_rex_pcre2(lua_State *L);
1456
1462 extern const char* get_current_plugin_version(void);
1463
1467 extern void clear_current_plugin_version(void);
1468
1477 extern int wslua_deregister_heur_dissectors(lua_State* L);
1478
1487 extern int wslua_deregister_protocols(lua_State* L);
1488
1497 extern int wslua_deregister_dissector_tables(lua_State* L);
1498
1507 extern int wslua_deregister_listeners(lua_State* L);
1508
1515 extern int wslua_deregister_fields(lua_State* L);
1516
1524 extern int wslua_deregister_filehandlers(lua_State* L);
1525
1532 extern void wslua_deregister_menus(void);
1533
1542 extern void wslua_init_wtap_filetypes(lua_State* L);
1543
1549 extern const wslua_conv_types_t* wslua_inspect_convtype_enum(void);
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 */
address
struct _address address
Holds a network or link-layer address of any supported type.
column-utils.h
conversation.h
conversation_t
struct conversation conversation_t
conversation_type
conversation_type
Conversation key types recognized by Wireshark dissectors.
Definition conversation.h:115
to_str.h
epan.h
epan_dissect_t
struct epan_dissect epan_dissect_t
Opaque type representing a single packet dissection context.
Definition epan.h:62
epan_dissect.h
exceptions.h
expert.h
filesystem.h
ftenum
ftenum
Fundamental field value types used throughout the Wireshark dissector framework.
Definition ftypes.h:26
funnel.h
packet_info
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
proto_item
proto_node proto_item
Definition proto.h:927
header_field_info
struct _header_field_info header_field_info
Definition proto.h:770
nstime.h
packet.h
prefs-int.h
pref_type_e
pref_type_e
Discriminator tag identifying the type and UI representation of a preference entry.
Definition prefs-int.h:138
prefs.h
proto.h
range_t
struct epan_range range_t
report_message.h
show_exception.h
_wslua_attribute_table
Defines a single attribute entry in a Lua class attribute dispatch table, binding a field name to its...
Definition wslua.h:569
_wslua_attribute_table::getfunc
lua_CFunction getfunc
Definition wslua.h:571
_wslua_attribute_table::setfunc
lua_CFunction setfunc
Definition wslua.h:572
_wslua_attribute_table::fieldname
const char * fieldname
Definition wslua.h:570
_wslua_captureinfo
Wraps capture file metadata for access from the Lua scripting environment.
Definition wslua.h:381
_wslua_captureinfo::expired
bool expired
Definition wslua.h:384
_wslua_captureinfo::wdh
wtap_dumper * wdh
Definition wslua.h:383
_wslua_captureinfo::wth
wtap * wth
Definition wslua.h:382
_wslua_class
Type for defining new classes.
Definition wslua.h:941
_wslua_class::attrs
const wslua_attribute_table * attrs
Definition wslua.h:947
_wslua_class::class_meta
const luaL_Reg * class_meta
Definition wslua.h:944
_wslua_class::name
const char * name
Definition wslua.h:942
_wslua_class::class_methods
const luaL_Reg * class_methods
Definition wslua.h:943
_wslua_class::instance_methods
const luaL_Reg * instance_methods
Definition wslua.h:945
_wslua_class::instance_meta
const luaL_Reg * instance_meta
Definition wslua.h:946
_wslua_col_info
Wraps a single column within a column_info for access from the Lua scripting environment.
Definition wslua.h:285
_wslua_col_info::cinfo
column_info * cinfo
Definition wslua.h:286
_wslua_col_info::col
int col
Definition wslua.h:287
_wslua_col_info::expired
bool expired
Definition wslua.h:288
_wslua_cols
Wraps a column_info for bulk column access from the Lua scripting environment.
Definition wslua.h:294
_wslua_cols::cinfo
column_info * cinfo
Definition wslua.h:295
_wslua_cols::expired
bool expired
Definition wslua.h:296
_wslua_const_rec
Wraps a read-only wtap_rec and its associated raw packet data for access from the Lua scripting envir...
Definition wslua.h:398
_wslua_const_rec::rec
const wtap_rec * rec
Definition wslua.h:399
_wslua_const_rec::pd
const uint8_t * pd
Definition wslua.h:400
_wslua_const_rec::expired
bool expired
Definition wslua.h:401
_wslua_conv_data_t
Associates a conversation with a Lua registry reference holding per-conversation dissector data.
Definition wslua.h:265
_wslua_conv_data_t::conv
conversation_t * conv
Definition wslua.h:266
_wslua_conv_data_t::data_ref
int data_ref
Definition wslua.h:267
_wslua_dir
Wraps a GDir iterator with extension filtering and path tracking for directory traversal from Lua.
Definition wslua.h:432
_wslua_dir::dir
GDir * dir
Definition wslua.h:433
_wslua_dir::ext
char * ext
Definition wslua.h:434
_wslua_dir::path
char * path
Definition wslua.h:435
_wslua_distbl_t
Represents a Lua DissectorTable, which may back either a standard dissector_table_t or a heuristic di...
Definition wslua.h:273
_wslua_distbl_t::table
dissector_table_t table
Definition wslua.h:274
_wslua_distbl_t::name
const char * name
Definition wslua.h:276
_wslua_distbl_t::expired
bool expired
Definition wslua.h:279
_wslua_distbl_t::created
bool created
Definition wslua.h:278
_wslua_distbl_t::heur_list
heur_dissector_list_t heur_list
Definition wslua.h:275
_wslua_distbl_t::ui_name
const char * ui_name
Definition wslua.h:277
_wslua_expert_field_t
Describes an expert info field registered from a Lua dissector script.
Definition wslua.h:190
_wslua_expert_field_t::abbrev
const char * abbrev
Definition wslua.h:192
_wslua_expert_field_t::ids
expert_field ids
Definition wslua.h:191
_wslua_expert_field_t::text
const char * text
Definition wslua.h:193
_wslua_expert_field_t::severity
int severity
Definition wslua.h:195
_wslua_expert_field_t::group
int group
Definition wslua.h:194
_wslua_field_info
Wraps a field_info for access from the Lua scripting environment, tracking validity.
Definition wslua.h:328
_wslua_field_info::expired
bool expired
Definition wslua.h:330
_wslua_field_info::ws_fi
field_info * ws_fi
Definition wslua.h:329
_wslua_field_t
Describes a protocol header field registered from a Lua dissector script.
Definition wslua.h:174
_wslua_field_t::base
unsigned base
Definition wslua.h:181
_wslua_field_t::hfid
int hfid
Definition wslua.h:175
_wslua_field_t::name
char * name
Definition wslua.h:177
_wslua_field_t::blob
char * blob
Definition wslua.h:179
_wslua_field_t::abbrev
char * abbrev
Definition wslua.h:178
_wslua_field_t::vs
const void * vs
Definition wslua.h:182
_wslua_field_t::mask
uint64_t mask
Definition wslua.h:184
_wslua_field_t::ett
int ett
Definition wslua.h:176
_wslua_field_t::valuestring_ref
int valuestring_ref
Definition wslua.h:183
_wslua_field_t::type
enum ftenum type
Definition wslua.h:180
_wslua_file
Wraps a wtap file handle or wtap_dumper for read/write access from the Lua scripting environment.
Definition wslua.h:369
_wslua_file::file
FILE_T file
Definition wslua.h:370
_wslua_file::wdh
wtap_dumper * wdh
Definition wslua.h:371
_wslua_file::expired
bool expired
Definition wslua.h:372
_wslua_filehandler
Describes a Lua-registered file format handler for reading and/or writing capture files.
Definition wslua.h:407
_wslua_filehandler::seek_read_ref
int seek_read_ref
Definition wslua.h:417
_wslua_filehandler::read_open_ref
int read_open_ref
Definition wslua.h:415
_wslua_filehandler::write_ref
int write_ref
Definition wslua.h:422
_wslua_filehandler::write_close_ref
int write_close_ref
Definition wslua.h:423
_wslua_filehandler::file_type
int file_type
Definition wslua.h:424
_wslua_filehandler::type
char * type
Definition wslua.h:412
_wslua_filehandler::internal_description
char * internal_description
Definition wslua.h:411
_wslua_filehandler::write_open_ref
int write_open_ref
Definition wslua.h:421
_wslua_filehandler::is_writer
bool is_writer
Definition wslua.h:410
_wslua_filehandler::registered
bool registered
Definition wslua.h:425
_wslua_filehandler::extensions
char * extensions
Definition wslua.h:413
_wslua_filehandler::read_ref
int read_ref
Definition wslua.h:416
_wslua_filehandler::can_write_encap_ref
int can_write_encap_ref
Definition wslua.h:420
_wslua_filehandler::L
lua_State * L
Definition wslua.h:414
_wslua_filehandler::seq_read_close_ref
int seq_read_close_ref
Definition wslua.h:419
_wslua_filehandler::read_close_ref
int read_close_ref
Definition wslua.h:418
_wslua_filehandler::finfo
struct file_type_subtype_info finfo
Definition wslua.h:408
_wslua_filehandler::removed
bool removed
Definition wslua.h:426
_wslua_filehandler::is_reader
bool is_reader
Definition wslua.h:409
_wslua_func_saver
Stores Lua function references to prevent garbage collection for functions used by tcp_dissect_pdus()...
Definition wslua.h:336
_wslua_func_saver::get_len_ref
int get_len_ref
Definition wslua.h:338
_wslua_func_saver::state
lua_State * state
Definition wslua.h:337
_wslua_func_saver::dissect_ref
int dissect_ref
Definition wslua.h:339
_wslua_header_field_info
Tracks a registered header field and its associated info for internal use by the Lua field registrati...
Definition wslua.h:320
_wslua_header_field_info::hfi
header_field_info * hfi
Definition wslua.h:322
_wslua_header_field_info::name
char * name
Definition wslua.h:321
_wslua_pinfo
Wraps a packet_info pointer with expiry tracking for use in the Lua scripting environment.
Definition wslua.h:146
_wslua_pinfo::ws_pinfo
packet_info * ws_pinfo
Definition wslua.h:147
_wslua_pinfo::expired
bool expired
Definition wslua.h:148
_wslua_pref_t
Represents a single Wireshark preference registered from a Lua dissector script.
Definition wslua.h:201
_wslua_pref_t::p
void * p
Definition wslua.h:214
_wslua_pref_t::uat_field_list
uat_field_t * uat_field_list
Definition wslua.h:229
_wslua_pref_t::enum_info
struct _wslua_pref_t::@217040237106063345351274302246224144004201267160::@020354106077367206330115123310115110030014002216 enum_info
_wslua_pref_t::u
unsigned u
Definition wslua.h:210
_wslua_pref_t::uat_field_list_info
struct _wslua_pref_t::@217040237106063345351274302246224144004201267160::@302242053311026123101057072277315265131022170020 uat_field_list_info
_wslua_pref_t::radio_buttons
bool radio_buttons
Definition wslua.h:224
_wslua_pref_t::desc
char * desc
Definition wslua.h:204
_wslua_pref_t::proto
struct _wslua_proto_t * proto
Definition wslua.h:236
_wslua_pref_t::s
char * s
Definition wslua.h:211
_wslua_pref_t::default_s
char * default_s
Definition wslua.h:232
_wslua_pref_t::b
bool b
Definition wslua.h:209
_wslua_pref_t::max_value
uint32_t max_value
Definition wslua.h:219
_wslua_pref_t::name
char * name
Definition wslua.h:202
_wslua_pref_t::r
range_t * r
Definition wslua.h:213
_wslua_pref_t::ref
int ref
Definition wslua.h:237
_wslua_pref_t::next
struct _wslua_pref_t * next
Definition wslua.h:235
_wslua_pref_t::enumvals
const enum_val_t * enumvals
Definition wslua.h:223
_wslua_pref_t::label
char * label
Definition wslua.h:203
_wslua_pref_t::e
int e
Definition wslua.h:212
_wslua_pref_t::type
pref_type_e type
Definition wslua.h:205
_wslua_pref_t::value
union _wslua_pref_t::@265022225263267215273077122115002146144266147256 value
_wslua_private_table
Wraps a GHashTable for use as a Lua private data table, tracking ownership and expiry.
Definition wslua.h:302
_wslua_private_table::expired
bool expired
Definition wslua.h:305
_wslua_private_table::is_allocated
bool is_allocated
Definition wslua.h:304
_wslua_private_table::table
GHashTable * table
Definition wslua.h:303
_wslua_progdlg
Wraps a GUI progress dialog for control from the Lua scripting environment.
Definition wslua.h:441
_wslua_progdlg::title
char * title
Definition wslua.h:443
_wslua_progdlg::pw
struct progdlg * pw
Definition wslua.h:442
_wslua_progdlg::stopped
bool stopped
Definition wslua.h:445
_wslua_progdlg::task
char * task
Definition wslua.h:444
_wslua_proto_t
Represents a Wireshark protocol registered from a Lua dissector script.
Definition wslua.h:243
_wslua_proto_t::expired
bool expired
Definition wslua.h:259
_wslua_proto_t::ett
int ett
Definition wslua.h:248
_wslua_proto_t::eia
GArray * eia
Definition wslua.h:257
_wslua_proto_t::handle
dissector_handle_t handle
Definition wslua.h:254
_wslua_proto_t::fields
int fields
Definition wslua.h:250
_wslua_proto_t::is_postdissector
bool is_postdissector
Definition wslua.h:258
_wslua_proto_t::expert_module
expert_module_t * expert_module
Definition wslua.h:252
_wslua_proto_t::expert_info_table_ref
int expert_info_table_ref
Definition wslua.h:251
_wslua_proto_t::desc
char * desc
Definition wslua.h:246
_wslua_proto_t::prefs_module
module_t * prefs_module
Definition wslua.h:253
_wslua_proto_t::hfa
GArray * hfa
Definition wslua.h:255
_wslua_proto_t::hfid
int hfid
Definition wslua.h:247
_wslua_proto_t::etta
GArray * etta
Definition wslua.h:256
_wslua_proto_t::name
char * name
Definition wslua.h:244
_wslua_proto_t::loname
char * loname
Definition wslua.h:245
_wslua_proto_t::prefs
wslua_pref_t prefs
Definition wslua.h:249
_wslua_rec
Wraps a wtap_rec for access from the Lua scripting environment, tracking validity.
Definition wslua.h:390
_wslua_rec::rec
wtap_rec * rec
Definition wslua.h:391
_wslua_rec::expired
bool expired
Definition wslua.h:392
_wslua_tap
Represents a Lua tap listener, binding a tap name and filter to Lua callback functions.
Definition wslua.h:352
_wslua_tap::draw_ref
int draw_ref
Definition wslua.h:358
_wslua_tap::all_fields
bool all_fields
Definition wslua.h:360
_wslua_tap::L
lua_State * L
Definition wslua.h:356
_wslua_tap::packet_ref
int packet_ref
Definition wslua.h:357
_wslua_tap::filter
char * filter
Definition wslua.h:354
_wslua_tap::reset_ref
int reset_ref
Definition wslua.h:359
_wslua_tap::name
char * name
Definition wslua.h:353
_wslua_tap::extractor
tap_extractor_t extractor
Definition wslua.h:355
_wslua_treeitem
Wraps a proto_item and its associated proto_tree for manipulation from the Lua scripting environment.
Definition wslua.h:311
_wslua_treeitem::tree
proto_tree * tree
Definition wslua.h:313
_wslua_treeitem::expired
bool expired
Definition wslua.h:314
_wslua_treeitem::item
proto_item * item
Definition wslua.h:312
_wslua_tvb
Wraps a tvbuff_t with ownership and expiry tracking for use in the Lua scripting environment.
Definition wslua.h:137
_wslua_tvb::ws_tvb
tvbuff_t * ws_tvb
Definition wslua.h:138
_wslua_tvb::expired
bool expired
Definition wslua.h:139
_wslua_tvb::need_free
bool need_free
Definition wslua.h:140
_wslua_tvbrange
Represents a sub-range of a Lua tvbuff, defined by an offset and length within the parent tvb.
Definition wslua.h:155
_wslua_tvbrange::offset
unsigned offset
Definition wslua.h:157
_wslua_tvbrange::len
unsigned len
Definition wslua.h:158
_wslua_tvbrange::tvb
struct _wslua_tvb * tvb
Definition wslua.h:156
_wslua_tw
Wraps a funnel text window for use in the Lua scripting environment, tracking expiry and close callba...
Definition wslua.h:164
_wslua_tw::ws_tw
funnel_text_window_t * ws_tw
Definition wslua.h:165
_wslua_tw::expired
bool expired
Definition wslua.h:166
_wslua_tw::close_cb_data
void * close_cb_data
Definition wslua.h:167
_wslua_tw::title
char * title
Definition wslua.h:168
client_data
Definition packet-bt-dht.c:97
enum_val_t
Defines a single named value within an enumerated preference or option type.
Definition params.h:16
expert_field
Pairs an expert info index with its associated header field index for registration and display.
Definition expert.h:41
field_info
Definition proto.h:822
file_type_subtype_info
Describes a single capture file type/subtype, including its metadata, capability flags,...
Definition wtap.h:2037
info
Definition file-pcapng.h:57
lua_pseudo_header
Definition wslua_dumper.c:58
nstime_t
Definition nstime.h:26
progdlg
Define the structure describing a progress dialog.
Definition progress_frame.h:28
tappable_t
Maps a tap name to its Lua data extractor callback for use in the tappable protocol registry.
Definition wslua.h:451
tappable_t::extractor
tap_extractor_t extractor
Definition wslua.h:453
tappable_t::name
const char * name
Definition wslua.h:452
wslua_conv_types_t
Maps a conversation type name string to its conversation_type identifier for use in Lua conversation ...
Definition wslua.h:467
wslua_conv_types_t::str
const char * str
Definition wslua.h:468
wslua_conv_types_t::id
conversation_type id
Definition wslua.h:469
wslua_ft_types_t
Maps a field type name string to its ftenum identifier for use in Lua field type lookups.
Definition wslua.h:459
wslua_ft_types_t::str
const char * str
Definition wslua.h:460
wslua_ft_types_t::id
enum ftenum id
Definition wslua.h:461
wtap_dumper
Wiretap dumper handle and associated state.
Definition wtap_module.h:163
wtap_rec
Represents a single capture record read from or written to a capture file, regardless of record type.
Definition wtap.h:1600
wtap
Definition wtap_module.h:58
strutil.h
tap.h
tvbparse.h
uat-int.h
uat.h
uat_field_t
struct _uat_field_t uat_field_t
Describes a single editable field within a UAT (User Accessible Table).
ws_assert.h
wsgcrypt.h
wslog.h
clear_outstanding_TvbRange
void clear_outstanding_TvbRange(void)
Clears all outstanding TvbRange objects.
Definition wslua_tvb.c:396
wslua_init
void wslua_init(register_cb cb, void *client_data, const char *app_env_var_prefix)
Initialize Wireshark Lua support.
Definition init_wslua.c:1655
dissect_lua
int dissect_lua(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
C-side entry point for all Lua-based protocol dissectors.
wslua_get_table
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
wslua_get_tap_extractor
tap_extractor_t wslua_get_tap_extractor(const char *name)
Retrieves a tap extractor by name.
wslua_field_t
struct _wslua_field_t wslua_field_t
Describes a protocol header field registered from a Lua dissector script.
wslua_print_stack
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
push_wsluaTvb
int push_wsluaTvb(lua_State *L, Tvb t)
Pushes a Tvb object onto the Lua stack.
Definition wslua_tvb.c:77
wslua_checklstring_only
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
wslua_checkstring_only
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
heur_dissect_lua
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.
lua_prime_all_fields
void lua_prime_all_fields(proto_tree *tree)
Primes all fields in the protocol tree.
wslua_early_cleanup
void wslua_early_cleanup(void)
Performs early cleanup of Lua resources.
Definition init_wslua.c:2046
clear_outstanding_Column
void clear_outstanding_Column(void)
Clears all outstanding Column objects.
Definition wslua_column.c:28
UInt64_unpack
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
wslua_cleanup
void wslua_cleanup(void)
Cleans up Lua resources.
Definition init_wslua.c:2093
wslua_deregister_protocols
int wslua_deregister_protocols(lua_State *L)
Deregisters all Lua-based protocol dissectors.
Definition wslua_proto.c:791
create_TreeItem
TreeItem create_TreeItem(proto_tree *tree, proto_item *item)
Creates a new TreeItem.
Definition wslua_tree.c:43
push_FieldInfo
FieldInfo * push_FieldInfo(lua_State *L, field_info *f)
Pushes a field information object onto the Lua stack.
Definition wslua_field.c:36
wslua_register_class
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
get_current_plugin_version
const char * get_current_plugin_version(void)
Get the current plugin version.
Definition wslua_utility.c:39
wslua_deregister_dissector_tables
int wslua_deregister_dissector_tables(lua_State *L)
Deregisters all registered dissector tables.
Definition wslua_dissector.c:1111
wslua_deregister_filehandlers
int wslua_deregister_filehandlers(lua_State *L)
Deregisters file handlers and menus in Wireshark's Lua environment.
luaopen_rex_pcre2
int luaopen_rex_pcre2(lua_State *L)
Open the Lua library for PCRE2 regular expressions.
Definition lpcre2.c:481
wslua_prefs_changed
void wslua_prefs_changed(void)
Notify Lua scripts that preferences have changed.
Definition init_wslua.c:668
push_Pinfo
Pinfo * push_Pinfo(lua_State *L, packet_info *p)
Pushes a packet information structure onto the Lua stack.
Definition wslua_pinfo.c:39
clear_outstanding_Pinfo
void clear_outstanding_Pinfo(void)
Clears all outstanding Pinfo objects.
Definition wslua_pinfo.c:36
wslua_has_field_extractors
bool wslua_has_field_extractors(void)
Checks if there are any registered field extractors.
Definition wslua_field.c:521
wslua_deregister_fields
int wslua_deregister_fields(lua_State *L)
Deregisters Lua fields.
wslua_optboolint
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
get_hf_wslua_text
int get_hf_wslua_text(void)
Retrieves the value of hf_wslua_text.
Definition init_wslua.c:187
wslua_get_field
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
wslua_optbool
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
wslua_deregister_heur_dissectors
int wslua_deregister_heur_dissectors(lua_State *L)
Deregisters all Lua-based heuristics dissectors.
Definition wslua_proto.c:775
wslua_reg_attributes
int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter)
Registers attributes for a Lua table.
UInt64_pack
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
wslua_deregister_menus
void wslua_deregister_menus(void)
Deregisters all menus registered by Wireshark Lua.
Definition wslua_gui.c:110
clear_current_plugin_version
void clear_current_plugin_version(void)
Clear the current plugin version.
Definition wslua_utility.c:43
wslua_proto_t
struct _wslua_proto_t wslua_proto_t
Represents a Wireshark protocol registered from a Lua dissector script.
clear_outstanding_Columns
void clear_outstanding_Columns(void)
Clears all outstanding Column objects.
Definition wslua_column.c:29
clear_outstanding_FieldInfo
void clear_outstanding_FieldInfo(void)
Clears any outstanding FieldInfo structures.
Definition wslua_field.c:44
wslua__concat
int wslua__concat(lua_State *L)
Concatenates two objects to a string.
Definition wslua_internals.c:27
push_TvbRange
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
wslua_get_expert_field
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
wslua_toboolean
bool wslua_toboolean(lua_State *L, int n)
Converts a Lua value to a boolean.
Definition wslua_internals.c:44
wslua_is_field_available
ProtoField wslua_is_field_available(lua_State *L, const char *field_abbr)
Definition wslua_proto.c:744
Proto_commit
int Proto_commit(lua_State *L)
Commits protocol changes.
Definition wslua_proto.c:875
Int64_unpack
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
wslua_typeof
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
wslua_bin2hex
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
clear_outstanding_Tvb
void clear_outstanding_Tvb(void)
Clears all outstanding Tvb objects.
Definition wslua_tvb.c:98
wslua_register_classinstance_meta
void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def)
Registers a class instance meta table.
Definition wslua_internals.c:470
wslua_expert_field_t
struct _wslua_expert_field_t wslua_expert_field_t
Describes an expert info field registered from a Lua dissector script.
wslua_init_wtap_filetypes
void wslua_init_wtap_filetypes(lua_State *L)
Initialize Wireshark Lua file types.
Definition wslua_wtap.c:111
wslua_class
struct _wslua_class wslua_class
Type for defining new classes.
wslua_deregister_listeners
int wslua_deregister_listeners(lua_State *L)
Deregisters all registered listeners.
Definition wslua_listener.c:444
push_Tvb
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
proto_register_lua
void proto_register_lua(void)
Registers the Lua protocol.
wslua_conv_data_t
struct _wslua_conv_data_t wslua_conv_data_t
Associates a conversation with a Lua registry reference holding per-conversation dissector data.
wslua_pref_t
struct _wslua_pref_t wslua_pref_t
Represents a single Wireshark preference registered from a Lua dissector script.
wslua_get_actual_filename
char * wslua_get_actual_filename(const char *fname)
Retrieves the actual filename with normalized path separators.
Definition wslua_utility.c:380
wslua_inspect_convtype_enum
const wslua_conv_types_t * wslua_inspect_convtype_enum(void)
Retrieves the enumeration of conversation types for Lua inspection.
Definition wslua_conversation.c:77
wslua_checkboolean
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
wslua_set_tap_enums
int wslua_set_tap_enums(lua_State *L)
Set tap enumerations in Lua.
clear_outstanding_FuncSavers
void clear_outstanding_FuncSavers(lua_State *L)
Clears outstanding function savers associated with a Lua state.
Definition wslua_proto.c:49
clear_outstanding_PrivateTable
void clear_outstanding_PrivateTable(void)
Clears any outstanding PrivateTable entries.
Definition wslua_pinfo.c:37
tap_extractor_t
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
lua_register_all_taps
GString * lua_register_all_taps(void)
Registers all Lua taps.
wslua_attribute_table
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...
getUInt64
uint64_t getUInt64(lua_State *L, int i)
Retrieves a 64-bit unsigned integer from the Lua stack.
Definition wslua_int64.c:599
wslua_tointeger
lua_Integer wslua_tointeger(lua_State *L, int n)
Converts a Lua value to an integer.
Definition wslua_internals.c:85
clear_outstanding_TreeItem
void clear_outstanding_TreeItem(void)
Clears all outstanding TreeItem objects.
Definition wslua_tree.c:53
wslua_prime_dfilter
void wslua_prime_dfilter(epan_dissect_t *edt)
Prime the dissector filter with a protocol tree.
Definition wslua_field.c:514
push_TreeItem
TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item)
Pushes a TreeItem onto the Lua stack.
Definition wslua_tree.c:30
wslua_hex2bin
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
Int64_pack
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
wslua_setfuncs
void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
Set functions in a Lua table.
Definition wslua_internals.c:134
wtap.h