| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
wslua.h
Go to the documentation of this file.
1/*
2 * wslua.h
3 *
4 * Wireshark's interface to the Lua Programming Language
5 *
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2007, Tamas Regos <tamas.regos@ericsson.com>
8 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
9 * (c) 2025, Bartis Csaba <bracsek@bracsek.eu>
10 *
11 * Wireshark - Network traffic analyzer
12 * By Gerald Combs <gerald@wireshark.org>
13 * Copyright 1998 Gerald Combs
14 *
15 * SPDX-License-Identifier: GPL-2.0-or-later
16 */
17
18#ifndef _PACKET_LUA_H
19#define _PACKET_LUA_H
20
21#include <glib.h>
22#include <stdlib.h>
23#include <string.h>
24#include <math.h>
25#include <lua.h>
26#include <lualib.h>
27#include <lauxlib.h>
28
29#include <ws_log_defs.h>
30
31#include <wiretap/wtap.h>
32
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
65#define WSLUA_INIT_ROUTINES "init_routines"
66#define WSLUA_PREFS_CHANGED "prefs_changed"
67
68/* type conversion macros - lua_Number is a double, so casting isn't kosher; and
69 using Lua's already-available lua_tointeger() and luaL_checkinteger() might be
70 different on different machines; so use these instead please!
71
72 It can be important to choose the correct version of signed or unsigned
73 conversion macros; don't assume that you can freely convert to the signed
74 or unsigned integer of the same size later:
75
76 On 32-bit Windows x86, Lua 5.2 and earlier must use lua_tounsigned() and
77 luaL_checkunsigned() due to the use of float to integer inlined assembly.
78 (#18367)
79 On ARM, casting from a negative floating point number to an unsigned integer
80 type doesn't perform wraparound conversion in the same way as casting from
81 float to the same size signed integer then to unsigned does, unlike x86[-64].
82 (Commit 15392c324d5eaefcaa298cdee09cd5b40b12e09c)
83
84 On Lua 5.3 and later, numbers are stored as a kind of union between
85 Lua_Number and Lua_Integer. On 5.2 and earlier. all numbers are stored
86 as Lua_Number internally.
87
88 Be careful about using the 64-bit functions, as they convert from double
89 and lose precision at high values. See wslua_int64.c and the types there.
90 TODO: Check if Lua_Integer is 64 bit on Lua 5.3 and later.
91*/
92#define wslua_toint(L,i) (int) ( lua_tointeger(L,i) )
93#define wslua_toint32(L,i) (int32_t) ( lua_tointeger(L,i) )
94#define wslua_toint64(L,i) (int64_t) ( lua_tonumber(L,i) )
95#define wslua_touint64(L,i) (uint64_t) ( lua_tonumber(L,i) )
96
97#define wslua_checkint(L,i) (int) ( luaL_checkinteger(L,i) )
98#define wslua_checkint32(L,i) (int32_t) ( luaL_checkinteger(L,i) )
99#define wslua_checkint64(L,i) (int64_t) ( luaL_checknumber(L,i) )
100#define wslua_checkuint64(L,i) (uint64_t) ( luaL_checknumber(L,i) )
101
102#define wslua_optint(L,i,d) (int) ( luaL_optinteger(L,i,d) )
103#define wslua_optint32(L,i,d) (int32_t) ( luaL_optinteger(L,i,d) )
104#define wslua_optint64(L,i,d) (int64_t) ( luaL_optnumber(L,i,d) )
105#define wslua_optuint64(L,i,d) (uint64_t) ( luaL_optnumber(L,i,d) )
106
112#if LUA_VERSION_NUM < 503
113#define wslua_touint(L,i) (unsigned) ( lua_tounsigned(L,i) )
114#define wslua_touint32(L,i) (uint32_t) ( lua_tounsigned(L,i) )
115#define wslua_checkuint(L,i) (unsigned) ( luaL_checkunsigned(L,i) )
116#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkunsigned(L,i) )
117#define wslua_optuint(L,i,d) (unsigned) ( luaL_optunsigned(L,i,d) )
118#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optunsigned(L,i,d) )
119#else
120#define wslua_touint(L,i) (unsigned) ( lua_tointeger(L,i) )
121#define wslua_touint32(L,i) (uint32_t) ( lua_tointeger(L,i) )
122#define wslua_checkuint(L,i) (unsigned) ( luaL_checkinteger(L,i) )
123#define wslua_checkuint32(L,i) (uint32_t) ( luaL_checkinteger(L,i) )
124#define wslua_optuint(L,i,d) (unsigned) ( luaL_optinteger(L,i,d) )
125#define wslua_optuint32(L,i,d) (uint32_t) ( luaL_optinteger(L,i,d) )
126#endif
127
128 struct _wslua_tvb {
129 tvbuff_t* ws_tvb;
130 bool expired;
131 bool need_free;
132};
133
134 struct _wslua_pinfo {
135 packet_info* ws_pinfo;
136 bool expired;
137};
138
139 struct _wslua_tvbrange {
140 struct _wslua_tvb* tvb;
141 unsigned offset;
142 unsigned len;
143};
144
145 struct _wslua_tw {
146 funnel_text_window_t* ws_tw;
147 bool expired;
148 void* close_cb_data;
149 char* title;
150};
151
152 typedef struct _wslua_field_t {
153 int hfid;
154 int ett;
155 char* name;
156 char* abbrev;
157 char* blob;
158 enum ftenum type;
159 unsigned base;
160 const void* vs;
161 int valuestring_ref;
162 uint64_t mask;
163} wslua_field_t;
164
165 typedef struct _wslua_expert_field_t {
166 expert_field ids;
167 const char *abbrev;
168 const char *text;
169 int group;
170 int severity;
171} wslua_expert_field_t;
172
173 typedef struct _wslua_pref_t {
174 char* name;
175 char* label;
176 char* desc;
177 pref_type_e type;
178 union {
179 bool b;
180 unsigned u;
181 char* s;
182 int e;
183 range_t *r;
184 void* p;
185 } value;
186 union {
187 uint32_t max_value;
188 struct {
189 const enum_val_t *enumvals;
190 bool radio_buttons;
194 } enum_info;
195 struct {
196 uat_field_t *uat_field_list;
197 } uat_field_list_info;
198 char* default_s;
199 } info;
201 struct _wslua_pref_t* next;
202 struct _wslua_proto_t* proto;
203 int ref; /* Reference to enable Proto to deregister prefs. */
204} wslua_pref_t;
205
206 typedef struct _wslua_proto_t {
207 char* name;
208 char* loname;
209 char* desc;
210 int hfid;
211 int ett;
212 wslua_pref_t prefs;
213 int fields;
214 int expert_info_table_ref;
215 expert_module_t *expert_module;
216 module_t *prefs_module;
217 dissector_handle_t handle;
218 GArray *hfa;
219 GArray *etta;
220 GArray *eia;
221 bool is_postdissector;
222 bool expired;
223} wslua_proto_t;
224
225 typedef struct _wslua_conv_data_t {
226 conversation_t* conv;
227 int data_ref;
228} wslua_conv_data_t;
229
230/* a "DissectorTable" object can be different things under the hood,
231 * since its heuristic_new() can create a heur_dissector_list_t that
232 * needs to be deregistered. */
233 struct _wslua_distbl_t {
234 dissector_table_t table;
235 heur_dissector_list_t heur_list;
236 const char* name;
237 const char* ui_name;
238 bool created;
239 bool expired;
240};
241
242 struct _wslua_col_info {
243 column_info* cinfo;
244 int col;
245 bool expired;
246};
247
248 struct _wslua_cols {
249 column_info* cinfo;
250 bool expired;
251};
252
253 struct _wslua_private_table {
254 GHashTable *table;
255 bool is_allocated;
256 bool expired;
257};
258
259 struct _wslua_treeitem {
260 proto_item* item;
261 proto_tree* tree;
262 bool expired;
263};
264
265// Internal structure for wslua_field.c to track info about registered fields.
266 struct _wslua_header_field_info {
267 char *name;
268 header_field_info *hfi;
269};
270
271 struct _wslua_field_info {
272 field_info *ws_fi;
273 bool expired;
274};
275
276/*
277 * _func_saver stores function refs so that Lua won't garbage collect them prematurely.
278 * It is only used by tcp_dissect_pdus right now.
279 */
280 struct _wslua_func_saver {
281 lua_State* state;
282 int get_len_ref;
283 int dissect_ref;
284};
285
286 typedef void (*tap_extractor_t)(lua_State*,const void*);
287
288 struct _wslua_tap {
289 char* name;
290 char* filter;
291 tap_extractor_t extractor;
292 lua_State* L;
293 int packet_ref;
294 int draw_ref;
295 int reset_ref;
296 bool all_fields;
297};
298
299/* a "File" object can be different things under the hood. It can either
300 be a FILE_T from wtap struct, which it is during read operations, or it
301 can be a wtap_dumper struct during write operations. A wtap_dumper struct
302 has a FILE_T member, but we can't only store its pointer here because
303 dump operations need the whole thing to write out with. Ugh. */
304 struct _wslua_file {
305 FILE_T file;
306 wtap_dumper *wdh; /* will be NULL during read usage */
307 bool expired;
308};
309
310/* a "CaptureInfo" object can also be different things under the hood. */
311 struct _wslua_captureinfo {
312 wtap *wth; /* will be NULL during write usage */
313 wtap_dumper *wdh; /* will be NULL during read usage */
314 bool expired;
315};
316
317 struct _wslua_rec {
318 wtap_rec *rec;
319 bool expired;
320};
321
322 struct _wslua_const_rec {
323 const wtap_rec *rec;
324 const uint8_t *pd;
325 bool expired;
326};
327
328 struct _wslua_filehandler {
329 struct file_type_subtype_info finfo;
330 bool is_reader;
331 bool is_writer;
332 char* internal_description; /* XXX - this is redundant; finfo.description should suffice */
333 char* type;
334 char* extensions;
335 lua_State* L;
336 int read_open_ref;
337 int read_ref;
338 int seek_read_ref;
339 int read_close_ref;
340 int seq_read_close_ref;
341 int can_write_encap_ref;
342 int write_open_ref;
343 int write_ref;
344 int write_close_ref;
345 int file_type;
346 bool registered;
347 bool removed; /* This is set during reload Lua plugins */
348};
349
350 struct _wslua_dir {
351 GDir* dir;
352 char* ext;
353 char* path;
354};
355
356 struct _wslua_progdlg {
357 struct progdlg* pw;
358 char* title;
359 char* task;
360 bool stopped;
361};
362
363 typedef struct { const char* name; tap_extractor_t extractor; } tappable_t;
364
365 typedef struct {const char* str; enum ftenum id; } wslua_ft_types_t;
366 typedef struct {const char* str; conversation_type id; } wslua_conv_types_t;
367
368 typedef wslua_pref_t* Pref;
369 typedef wslua_pref_t* Prefs;
370 typedef struct _wslua_field_t* ProtoField;
371 typedef struct _wslua_expert_field_t* ProtoExpert;
372 typedef struct _wslua_proto_t* Proto;
373 typedef struct _wslua_distbl_t* DissectorTable;
374 typedef dissector_handle_t Dissector;
375 typedef GByteArray* ByteArray;
376 typedef gcry_cipher_hd_t* GcryptCipher;
377 typedef struct _wslua_tvb* Tvb;
378 typedef struct _wslua_tvbrange* TvbRange;
379 typedef struct _wslua_col_info* Column;
380 typedef struct _wslua_cols* Columns;
381 typedef struct _wslua_pinfo* Pinfo;
382 typedef struct _wslua_treeitem* TreeItem;
383 typedef address* Address;
384 typedef nstime_t* NSTime;
385 typedef int64_t Int64;
386 typedef uint64_t UInt64;
387 typedef struct _wslua_header_field_info* Field;
388 typedef struct _wslua_field_info* FieldInfo;
389 typedef struct _wslua_tap* Listener;
390 typedef struct _wslua_tw* TextWindow;
391 typedef struct _wslua_progdlg* ProgDlg;
392 typedef struct _wslua_file* File;
393 typedef struct _wslua_captureinfo* CaptureInfo;
394 typedef struct _wslua_captureinfo* CaptureInfoConst;
395 typedef struct _wslua_rec* FrameInfo;
396 typedef struct _wslua_const_rec* FrameInfoConst;
397 typedef struct _wslua_filehandler* FileHandler;
398 typedef wtap_dumper* Dumper;
399 typedef struct lua_pseudo_header* PseudoHeader;
400 typedef tvbparse_t* Parser;
401 typedef tvbparse_wanted_t* Rule;
402 typedef tvbparse_elem_t* Node;
403 typedef tvbparse_action_t* Shortcut;
404 typedef struct _wslua_dir* Dir;
405 typedef struct _wslua_private_table* PrivateTable;
406 typedef conversation_t* Conversation;
407 typedef char* Struct;
408
409/*
410 * toXxx(L,idx) gets a Xxx from an index (Lua Error if fails)
411 * checkXxx(L,idx) gets a Xxx from an index after calling check_code (No Lua Error if it fails)
412 * pushXxx(L,xxx) pushes an Xxx into the stack
413 * isXxx(L,idx) tests whether we have an Xxx at idx
414 * shiftXxx(L,idx) removes and returns an Xxx from idx only if it has a type of Xxx, returns NULL otherwise
415 * WSLUA_CLASS_DEFINE must be used with a trailing ';'
416 * (a dummy typedef is used to be syntactically correct)
417 */
418#define WSLUA_CLASS_DEFINE(C,check_code) \
419 WSLUA_CLASS_DEFINE_BASE(C,check_code,NULL)
420
421#define WSLUA_CLASS_DEFINE_BASE(C,check_code,retval) \
422 C to##C(lua_State* L, int idx) { \
423 C* v = (C*)lua_touserdata (L, idx); \
424 if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)", idx, #C, lua_typename(L, lua_type(L, idx))); \
425 return v ? *v : retval; \
426} \
427 C check##C(lua_State* L, int idx) { \
428 C* p; \
429 luaL_checktype(L,idx,LUA_TUSERDATA); \
430 p = (C*)luaL_checkudata(L, idx, #C); \
431 check_code; \
432 return p ? *p : retval; \
433} \
434 C* push##C(lua_State* L, C v) { \
435 C* p; \
436 luaL_checkstack(L,2,"Unable to grow stack\n"); \
437 p = (C*)lua_newuserdata(L,sizeof(C)); *p = v; \
438 luaL_getmetatable(L, #C); lua_setmetatable(L, -2); \
439 return p; \
440}\
441 bool is##C(lua_State* L,int i) { \
442 void *p; \
443 if(!lua_isuserdata(L,i)) return false; \
444 p = lua_touserdata(L, i); \
445 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
446 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
447 lua_pop(L, 2); \
448 return p ? true : false; \
449} \
450 C shift##C(lua_State* L,int i) { \
451 C* p; \
452 if(!lua_isuserdata(L,i)) return retval; \
453 p = (C*)lua_touserdata(L, i); \
454 lua_getfield(L, LUA_REGISTRYINDEX, #C); \
455 if (p == NULL || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p=NULL; \
456 lua_pop(L, 2); \
457 if (p) { lua_remove(L,i); return *p; }\
458 else return retval;\
459} \
460 typedef int dummy##C
461
462 typedef struct _wslua_attribute_table {
463 const char *fieldname;
464 lua_CFunction getfunc;
465 lua_CFunction setfunc;
466} wslua_attribute_table;
467
478 extern int wslua_reg_attributes(lua_State *L, const wslua_attribute_table *t, bool is_getter);
479
480#define WSLUA_TYPEOF_FIELD "__typeof"
481
482#ifdef HAVE_LUA
483
484/* temporary transition macro to reduce duplication in WSLUA_REGISTER_xxx. */
485#define WSLUA_REGISTER_GC(C) \
486 luaL_getmetatable(L, #C); \
487 /* add the '__gc' metamethod with a C-function named Class__gc */ \
488 /* this will force ALL wslua classes to have a Class__gc function defined, which is good */ \
489 lua_pushcfunction(L, C ## __gc); \
490 lua_setfield(L, -2, "__gc"); \
491 /* pop the metatable */ \
492 lua_pop(L, 1)
493
494#define __WSLUA_REGISTER_META(C, ATTRS) { \
495 const wslua_class C ## _class = { \
496 .name = #C, \
497 .instance_meta = C ## _meta, \
498 .attrs = ATTRS \
499 }; \
500 wslua_register_classinstance_meta(L, &C ## _class); \
501 WSLUA_REGISTER_GC(C); \
502}
503
504#define WSLUA_REGISTER_META(C) __WSLUA_REGISTER_META(C, NULL)
505#define WSLUA_REGISTER_META_WITH_ATTRS(C) \
506 __WSLUA_REGISTER_META(C, C ## _attributes)
507
508#define __WSLUA_REGISTER_CLASS(C, ATTRS) { \
509 const wslua_class C ## _class = { \
510 .name = #C, \
511 .class_methods = C ## _methods, \
512 .class_meta = C ## _meta, \
513 .instance_methods = C ## _methods, \
514 .instance_meta = C ## _meta, \
515 .attrs = ATTRS \
516 }; \
517 wslua_register_class(L, &C ## _class); \
518 WSLUA_REGISTER_GC(C); \
519}
520
521#define WSLUA_REGISTER_CLASS(C) __WSLUA_REGISTER_CLASS(C, NULL)
522#define WSLUA_REGISTER_CLASS_WITH_ATTRS(C) \
523 __WSLUA_REGISTER_CLASS(C, C ## _attributes)
524
525#define WSLUA_INIT(L) \
526 luaL_openlibs(L); \
527 wslua_register_classes(L); \
528 wslua_register_functions(L);
529
530#endif
531
532#define WSLUA_FUNCTION extern int
533/* This is for functions intended only to be used in init.lua */
534#define WSLUA_INTERNAL_FUNCTION extern int
535
536#define WSLUA_REGISTER_FUNCTION(name) { lua_pushcfunction(L, wslua_## name); lua_setglobal(L, #name); }
537
538#define WSLUA_REGISTER extern int
539
540#define WSLUA_METHOD static int
541#define WSLUA_CONSTRUCTOR static int
542#define WSLUA_ATTR_SET static int
543#define WSLUA_ATTR_GET static int
544#define WSLUA_METAMETHOD static int
545
546#define WSLUA_METHODS static const luaL_Reg
547#define WSLUA_META static const luaL_Reg
548#define WSLUA_CLASS_FNREG(class,name) { #name, class##_##name }
549#define WSLUA_CLASS_FNREG_ALIAS(class,aliasname,name) { #aliasname, class##_##name }
550#define WSLUA_CLASS_MTREG(class,name) { "__" #name, class##__##name }
551
552#define WSLUA_ATTRIBUTES static const wslua_attribute_table
553/* following are useful macros for the rows in the array created by above */
554#define WSLUA_ATTRIBUTE_RWREG(class,name) { #name, class##_get_##name, class##_set_##name }
555#define WSLUA_ATTRIBUTE_ROREG(class,name) { #name, class##_get_##name, NULL }
556#define WSLUA_ATTRIBUTE_WOREG(class,name) { #name, NULL, class##_set_##name }
557
558/* Body of a __pairs metamethod that hands the generic-for protocol
559 * a stateless iterator `C##_pairs_iter`. The iterator must accept
560 * (self, prev_key_or_nil) and return the next (key, value) pair or a
561 * single nil when done. Use inside a WSLUA_METAMETHOD body so the
562 * caller retains control of any doc comments shown in the manual. */
563#define WSLUA_STATELESS_PAIRS_BODY(C) \
564 check##C(L, 1); \
565 lua_pushcfunction(L, C##_pairs_iter); \
566 lua_pushvalue(L, 1); \
567 lua_pushnil(L); \
568 return 3
569
570#define WSLUA_ATTRIBUTE_FUNC_SETTER(C,field) \
571 static int C##_set_##field (lua_State* L) { \
572 C obj = check##C (L,1); \
573 if (! lua_isfunction(L,-1) ) \
574 return luaL_error(L, "%s's attribute `%s' must be a function", #C , #field ); \
575 if (obj->field##_ref != LUA_NOREF) \
576 /* there was one registered before, remove it */ \
577 luaL_unref(L, LUA_REGISTRYINDEX, obj->field##_ref); \
578 obj->field##_ref = luaL_ref(L, LUA_REGISTRYINDEX); \
579 return 0; \
580 } \
581 /* silly little trick so we can add a semicolon after this macro */ \
582 typedef void __dummy##C##_set_##field
583
584#define WSLUA_ATTRIBUTE_GET(C,name,block) \
585 static int C##_get_##name (lua_State* L) { \
586 C obj = check##C (L,1); \
587 block \
588 return 1; \
589 } \
590 /* silly little trick so we can add a semicolon after this macro */ \
591 typedef void __dummy##C##_get_##name
592
593#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_GETTER(C,name,member) \
594 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushboolean(L, obj->member );})
595
596#define WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,name,member) \
597 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushinteger(L,(lua_Integer)(obj->member));})
598
599#define WSLUA_ATTRIBUTE_INTEGER_GETTER(C,member) \
600 WSLUA_ATTRIBUTE_NAMED_INTEGER_GETTER(C,member,member)
601
602#define WSLUA_ATTRIBUTE_BLOCK_NUMBER_GETTER(C,name,block) \
603 WSLUA_ATTRIBUTE_GET(C,name,{lua_pushnumber(L,(lua_Number)(block));})
604
605#define WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,name,member) \
606 WSLUA_ATTRIBUTE_GET(C,name, { \
607 lua_pushstring(L,obj->member); /* this pushes nil if obj->member is null */ \
608 })
609
610#define WSLUA_ATTRIBUTE_STRING_GETTER(C,member) \
611 WSLUA_ATTRIBUTE_NAMED_STRING_GETTER(C,member,member)
612
613#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_GETTER(C,name,member,option) \
614 WSLUA_ATTRIBUTE_GET(C,name, { \
615 char* str; \
616 if ((obj->member) && (obj->member->len > 0)) { \
617 if (wtap_block_get_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, &str) == WTAP_OPTTYPE_SUCCESS) { \
618 lua_pushstring(L,str); \
619 } \
620 } \
621 })
622
623/*
624 * XXX - we need to support Lua programs getting instances of a "multiple
625 * allowed" option other than the first option.
626 */
627#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_GETTER(C,name,member,option) \
628 WSLUA_ATTRIBUTE_GET(C,name, { \
629 char* str; \
630 if ((obj->member) && (obj->member->len > 0)) { \
631 if (wtap_block_get_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, &str) == WTAP_OPTTYPE_SUCCESS) { \
632 lua_pushstring(L,str); \
633 } \
634 } \
635 })
636
637#define WSLUA_ATTRIBUTE_SET(C,name,block) \
638 static int C##_set_##name (lua_State* L) { \
639 C obj = check##C (L,1); \
640 block; \
641 return 0; \
642 } \
643 /* silly little trick so we can add a semicolon after this macro */ \
644 typedef void __dummy##C##_set_##name
645
646#define WSLUA_ATTRIBUTE_NAMED_BOOLEAN_SETTER(C,name,member) \
647 WSLUA_ATTRIBUTE_SET(C,name, { \
648 if (! lua_isboolean(L,-1) ) \
649 return luaL_error(L, "%s's attribute `%s' must be a boolean", #C , #name ); \
650 obj->member = lua_toboolean(L,-1); \
651 })
652
653/* to make this integral-safe, we treat it as int32 and then cast
654 Note: This will truncate 64-bit integers (but then Lua itself only has doubles */
655#define WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,name,member,cast) \
656 WSLUA_ATTRIBUTE_SET(C,name, { \
657 if (! lua_isinteger(L,-1) ) \
658 return luaL_error(L, "%s's attribute `%s' must be an integer", #C , #name ); \
659 obj->member = (cast) wslua_toint32(L,-1); \
660 })
661
662#define WSLUA_ATTRIBUTE_INTEGER_SETTER(C,member,cast) \
663 WSLUA_ATTRIBUTE_NAMED_INTEGER_SETTER(C,member,member,cast)
664
665#define WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,member,need_free) \
666 static int C##_set_##field (lua_State* L) { \
667 C obj = check##C (L,1); \
668 char* s = NULL; \
669 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
670 s = g_strdup(lua_tostring(L,-1)); \
671 } else { \
672 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
673 } \
674 if (obj->member != NULL && need_free) \
675 g_free((void*) obj->member); \
676 obj->member = s; \
677 return 0; \
678 } \
679 /* silly little trick so we can add a semicolon after this macro */ \
680 typedef void __dummy##C##_set_##field
681
682#define WSLUA_ATTRIBUTE_STRING_SETTER(C,field,need_free) \
683 WSLUA_ATTRIBUTE_NAMED_STRING_SETTER(C,field,field,need_free)
684
685#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_STRING_SETTER(C,field,member,option) \
686 static int C##_set_##field (lua_State* L) { \
687 C obj = check##C (L,1); \
688 char* s = NULL; \
689 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
690 s = g_strdup(lua_tostring(L,-1)); \
691 } else { \
692 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
693 } \
694 if ((obj->member) && (obj->member->len > 0)) { \
695 wtap_block_set_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, s, strlen(s)); \
696 } \
697 g_free(s); \
698 return 0; \
699 } \
700 /* silly little trick so we can add a semicolon after this macro */ \
701 typedef void __dummy##C##_set_##field
702
703#define WSLUA_ATTRIBUTE_NAMED_OPT_BLOCK_NTH_STRING_SETTER(C,field,member,option) \
704 static int C##_set_##field (lua_State* L) { \
705 C obj = check##C (L,1); \
706 char* s = NULL; \
707 if (lua_isstring(L,-1) || lua_isnil(L,-1)) { \
708 s = g_strdup(lua_tostring(L,-1)); \
709 } else { \
710 return luaL_error(L, "%s's attribute `%s' must be a string or nil", #C , #field ); \
711 } \
712 if ((obj->member) && (obj->member->len > 0)) { \
713 wtap_block_set_nth_string_option_value(g_array_index(obj->member, wtap_block_t, 0), option, 0, s, strlen(s)); \
714 } \
715 g_free(s); \
716 return 0; \
717 } \
718 /* silly little trick so we can add a semicolon after this macro */ \
719 typedef void __dummy##C##_set_##field
720
721#define WSLUA_ERROR(name,error) { luaL_error(L, "%s%s", #name ": ", error); }
722#define WSLUA_ARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_ARG_ ## name ## _ ## attr, #name ": " error); }
723#define WSLUA_OPTARG_ERROR(name,attr,error) { luaL_argerror(L,WSLUA_OPTARG_##name##_ ##attr, #name ": " error); }
724
725#define WSLUA_REG_GLOBAL_BOOL(L,n,v) { lua_pushboolean(L,v); lua_setglobal(L,n); }
726#define WSLUA_REG_GLOBAL_STRING(L,n,v) { lua_pushstring(L,v); lua_setglobal(L,n); }
727#define WSLUA_REG_GLOBAL_INTEGER(L,n,v) { lua_pushinteger(L,v); lua_setglobal(L,n); }
728
729#define WSLUA_RETURN(i) return (i)
730
731#define WSLUA_API extern
732
733/* empty macro arguments trigger ISO C90 warnings, so do this */
734#define NOP (void)p
735
736#define FAIL_ON_NULL(s) if (! *p) luaL_argerror(L,idx,"null " s)
737
738#define FAIL_ON_NULL_OR_EXPIRED(s) if (!*p) { \
739 luaL_argerror(L,idx,"null " s); \
740 } else if ((*p)->expired) { \
741 luaL_argerror(L,idx,"expired " s); \
742 }
743
744/* Clears or marks references that connects Lua to Wireshark structures */
745#define CLEAR_OUTSTANDING(C, marker, marker_val) void clear_outstanding_##C(void) { \
746 while (outstanding_##C->len) { \
747 C p = (C)g_ptr_array_remove_index_fast(outstanding_##C,0); \
748 if (p) { \
749 if (p->marker != marker_val) \
750 p->marker = marker_val; \
751 else \
752 g_free(p); \
753 } \
754 } \
755}
756
757#define WSLUA_CLASS_DECLARE(C) \
758 extern C to##C(lua_State* L, int idx); \
759 extern C check##C(lua_State* L, int idx); \
760 extern C* push##C(lua_State* L, C v); \
761 extern int C##_register(lua_State* L); \
762 extern bool is##C(lua_State* L,int i); \
763 extern C shift##C(lua_State* L,int i)
764
765
766/* Throws a Wireshark exception, catchable via normal exceptions.h routines. */
767#define THROW_LUA_ERROR(...) \
768 THROW_FORMATTED(DissectorError, __VA_ARGS__)
769
770/* Catches any Wireshark exceptions in code and convert it into a Lua error.
771 * Normal restrictions for TRY/CATCH apply, in particular, do not return!
772 *
773 * This means do not call lua[L]_error() inside code, as that longjmps out
774 * of the TRY block to the Lua pcall! Use THROW_LUA_ERROR, which is caught
775 * and then converted into a Lua error.
776 *
777 * XXX: We CATCH_ALL here, although there's little point in catching
778 * OutOfMemoryError here. (Is CATCH_BOUNDS_AND_DISSECTOR_ERRORS sufficient?)
779 * There are some Exceptions that we catch and show but don't want to add
780 * the Lua error malformed expert info to the tree: BoundsError,
781 * FragmentBoundsError, and ScsiBoundsError (show_exception doesn't consider
782 * those malformed). The traceback might (or might not) be useful for those.
783 * Putting an extra malformed expert info in the tree in the cases that are
784 * malformed seems not so bad, but we might want to reduce that. Perhaps
785 * at least we could have a separate LuaError type and not call show_exception
786 * for that (we still need to handle some Lua errors that don't use this in
787 * dissector_error_handler.)
788 */
789#define WRAP_NON_LUA_EXCEPTIONS(code) \
790{ \
791 volatile bool has_error = false; \
792 TRY { \
793 code \
794 } CATCH3(BoundsError, FragmentBoundsError, ScsiBoundsError) { \
795 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
796 } CATCH_ALL { \
797 show_exception(lua_tvb, lua_pinfo, lua_tree->tree, EXCEPT_CODE, GET_MESSAGE); \
798 lua_pushfstring(L, "%s: %s", __func__, GET_MESSAGE ? GET_MESSAGE : "Malformed packet"); \
799 has_error = true; \
800 } ENDTRY; \
801 if (has_error) { lua_error(L); } \
802}
803
804
805 extern packet_info* lua_pinfo;
806 extern TreeItem lua_tree;
807 extern tvbuff_t* lua_tvb;
808 extern bool lua_initialized;
809 extern int lua_dissectors_table_ref;
810 extern int lua_heur_dissectors_table_ref;
811 extern const char* lua_app_env_var_prefix;
812 extern GPtrArray* lua_outstanding_FuncSavers;
813
814WSLUA_DECLARE_CLASSES()
815WSLUA_DECLARE_FUNCTIONS()
816
824extern lua_State* wslua_state(void);
825
826
827/* wslua_internals.c */
834typedef struct _wslua_class {
835 const char *name;
836 const luaL_Reg *class_methods;
837 const luaL_Reg *class_meta;
838 const luaL_Reg *instance_methods;
839 const luaL_Reg *instance_meta;
840 const wslua_attribute_table *attrs;
841} wslua_class;
842 void wslua_register_classinstance_meta(lua_State *L, const wslua_class *cls_def);
843 void wslua_register_class(lua_State *L, const wslua_class *cls_def);
844
854 extern int wslua__concat(lua_State* L);
855
867 extern bool wslua_toboolean(lua_State* L, int n);
868
878 extern bool wslua_checkboolean(lua_State* L, int n);
879
888 extern bool wslua_optbool(lua_State* L, int n, bool def);
889
897 extern lua_Integer wslua_tointeger(lua_State* L, int n);
898
907 extern int wslua_optboolint(lua_State* L, int n, int def);
908
917 extern const char* wslua_checklstring_only(lua_State* L, int n, size_t *l);
918
926 extern const char* wslua_checkstring_only(lua_State* L, int n);
927
935 extern void wslua_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
936 extern const char* wslua_typeof_unknown;
937 extern const char* wslua_typeof(lua_State *L, int idx);
938 extern bool wslua_get_table(lua_State *L, int idx, const char *name);
939 extern bool wslua_get_field(lua_State *L, int idx, const char *name);
940 extern int dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data);
941 extern bool heur_dissect_lua(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data);
942
950 extern expert_field* wslua_get_expert_field(const int group, const int severity);
951
958 extern void wslua_prefs_changed(void);
959
965 extern void proto_register_lua(void);
966
974 extern GString* lua_register_all_taps(void);
975
983 extern void wslua_prime_dfilter(epan_dissect_t *edt);
984
990 extern bool wslua_has_field_extractors(void);
991
999 extern void lua_prime_all_fields(proto_tree* tree);
1000
1009 extern int Proto_commit(lua_State* L);
1010
1018 extern TreeItem create_TreeItem(proto_tree* tree, proto_item* item);
1019
1025 extern void clear_outstanding_FuncSavers(lua_State* L);
1026
1035 extern void Int64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1036
1045 extern int Int64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1046
1055 extern void UInt64_pack(lua_State* L, luaL_Buffer *b, int idx, bool asLittleEndian);
1056
1065 extern int UInt64_unpack(lua_State* L, const char *buff, bool asLittleEndian);
1066
1077 extern uint64_t getUInt64(lua_State *L, int i);
1078
1086 extern Tvb* push_Tvb(lua_State* L, tvbuff_t* tvb);
1087
1095 extern int push_wsluaTvb(lua_State* L, Tvb t);
1096
1106 extern bool push_TvbRange(lua_State* L, tvbuff_t* tvb, int offset, int len);
1107
1113 extern void clear_outstanding_Tvb(void);
1114
1118 extern void clear_outstanding_TvbRange(void);
1119
1127 extern Pinfo* push_Pinfo(lua_State* L, packet_info* p);
1128
1132 extern void clear_outstanding_Pinfo(void);
1133 extern void clear_outstanding_Column(void);
1134 extern void clear_outstanding_Columns(void);
1135
1139 extern void clear_outstanding_PrivateTable(void);
1140
1146 extern int get_hf_wslua_text(void);
1147
1156 extern TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item);
1157
1161 extern void clear_outstanding_TreeItem(void);
1162
1170 extern FieldInfo* push_FieldInfo(lua_State *L, field_info* f);
1171
1175 extern void clear_outstanding_FieldInfo(void);
1176
1183 extern void wslua_print_stack(char* s, lua_State* L);
1184
1194 extern void wslua_init(register_cb cb, void *client_data, const char* app_env_var_prefix);
1195 extern void wslua_early_cleanup(void);
1196
1202 extern void wslua_cleanup(void);
1203
1210 extern tap_extractor_t wslua_get_tap_extractor(const char* name);
1211
1218 extern int wslua_set_tap_enums(lua_State* L);
1219
1220 extern ProtoField wslua_is_field_available(lua_State* L, const char* field_abbr);
1221
1228 extern char* wslua_get_actual_filename(const char* fname);
1229
1242 extern int wslua_bin2hex(lua_State* L, const uint8_t* data, const unsigned len, const bool lowercase, const char* sep);
1243
1253 extern int wslua_hex2bin(lua_State* L, const char* data, const unsigned len, const char* sep);
1254
1261 extern int luaopen_rex_pcre2(lua_State *L);
1262
1268 extern const char* get_current_plugin_version(void);
1269
1273 extern void clear_current_plugin_version(void);
1274
1283 extern int wslua_deregister_heur_dissectors(lua_State* L);
1284 extern int wslua_deregister_protocols(lua_State* L);
1285
1294 extern int wslua_deregister_dissector_tables(lua_State* L);
1295 extern int wslua_deregister_listeners(lua_State* L);
1296
1303 extern int wslua_deregister_fields(lua_State* L);
1304
1312 extern int wslua_deregister_filehandlers(lua_State* L);
1313
1320 extern void wslua_deregister_menus(void);
1321
1330 extern void wslua_init_wtap_filetypes(lua_State* L);
1331
1337 extern const wslua_conv_types_t* wslua_inspect_convtype_enum(void);
1338
1339#endif
1340
1341/*
1342 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1343 *
1344 * Local variables:
1345 * c-basic-offset: 4
1346 * tab-width: 8
1347 * indent-tabs-mode: nil
1348 * End:
1349 *
1350 * vi: set shiftwidth=4 tabstop=8 expandtab:
1351 * :indentSize=4:tabSize=8:noTabs=true:
1352 */
column-utils.h
conversation.h
to_str.h
epan.h
epan_dissect.h
exceptions.h
expert.h
filesystem.h
funnel.h
nstime.h
packet.h
prefs-int.h
prefs.h
proto.h
report_message.h
show_exception.h
_address
Definition address.h:58
_funnel_text_window_t
Definition tap-funnel.c:21
_header_field_info
Definition proto.h:765
_packet_info
Definition packet_info.h:43
_proto_node
Definition proto.h:905
_tvbparse_elem_t
Definition tvbparse.h:163
_tvbparse_t
Represents an instance of a per-packet parser for tvbuff data.
Definition tvbparse.h:151
_tvbparse_wanted_t
Describes a parsing rule or expectation for a tvbuff parser.
Definition tvbparse.h:96
_uat_field_t
Definition uat.h:235
_wslua_attribute_table
Definition wslua.h:462
_wslua_captureinfo
Definition wslua.h:311
_wslua_class
Type for defining new classes.
Definition wslua.h:834
_wslua_class::attrs
const wslua_attribute_table * attrs
Definition wslua.h:840
_wslua_class::class_meta
const luaL_Reg * class_meta
Definition wslua.h:837
_wslua_class::name
const char * name
Definition wslua.h:835
_wslua_class::class_methods
const luaL_Reg * class_methods
Definition wslua.h:836
_wslua_class::instance_methods
const luaL_Reg * instance_methods
Definition wslua.h:838
_wslua_class::instance_meta
const luaL_Reg * instance_meta
Definition wslua.h:839
_wslua_col_info
Definition wslua.h:242
_wslua_cols
Definition wslua.h:248
_wslua_const_rec
Definition wslua.h:322
_wslua_conv_data_t
Definition wslua.h:225
_wslua_dir
Definition wslua.h:350
_wslua_distbl_t
Definition wslua.h:233
_wslua_expert_field_t
Definition wslua.h:165
_wslua_field_info
Definition wslua.h:271
_wslua_field_t
Definition wslua.h:152
_wslua_file
Definition wslua.h:304
_wslua_filehandler
Definition wslua.h:328
_wslua_func_saver
Definition wslua.h:280
_wslua_header_field_info
Definition wslua.h:266
_wslua_pinfo
Definition wslua.h:134
_wslua_pref_t
Definition wslua.h:173
_wslua_pref_t::uat_field_list
uat_field_t * uat_field_list
Definition wslua.h:196
_wslua_pref_t::uat_field_list_info
struct _wslua_pref_t::@509::@511 uat_field_list_info
_wslua_pref_t::radio_buttons
bool radio_buttons
Definition wslua.h:190
_wslua_pref_t::enum_info
struct _wslua_pref_t::@509::@510 enum_info
_wslua_pref_t::default_s
char * default_s
Definition wslua.h:198
_wslua_pref_t::max_value
uint32_t max_value
Definition wslua.h:187
_wslua_pref_t::enumvals
const enum_val_t * enumvals
Definition wslua.h:189
_wslua_pref_t::info
union _wslua_pref_t::@509 info
_wslua_private_table
Definition wslua.h:253
_wslua_progdlg
Definition wslua.h:356
_wslua_proto_t
Definition wslua.h:206
_wslua_rec
Definition wslua.h:317
_wslua_tap
Definition wslua.h:288
_wslua_treeitem
Definition wslua.h:259
_wslua_tvb
Definition wslua.h:128
_wslua_tvbrange
Definition wslua.h:139
_wslua_tw
Definition wslua.h:145
client_data
Definition packet-bt-dht.c:99
conversation
Definition conversation.h:230
dissector_handle
Definition packet.c:852
dissector_table
Definition packet.c:97
enum_val_t
Definition params.h:23
epan_column_info
Definition column-info.h:62
epan_dissect
Definition epan_dissect.h:28
epan_range
Definition range.h:41
expert_field
Definition expert.h:39
expert_module
Definition expert.c:48
field_info
Definition proto.h:814
file_type_subtype_info
Definition wtap.h:1928
heur_dissector_list
Definition packet.c:188
lua_pseudo_header
Definition wslua_dumper.c:58
nstime_t
Definition nstime.h:26
pref_module
Definition prefs-int.h:27
progdlg
Definition progress_frame.h:31
tappable_t
Definition wslua.h:363
tvbuff
Definition tvbuff-int.h:36
wslua_conv_types_t
Definition wslua.h:366
wslua_ft_types_t
Definition wslua.h:365
wtap_dumper
Wiretap dumper handle and associated state.
Definition wtap_module.h:163
wtap_reader
Definition file_wrappers.c:96
wtap_rec
Definition wtap.h:1512
wtap
Definition wtap_module.h:58
strutil.h
tap.h
tvbparse.h
uat-int.h
uat.h
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:1639
wslua_get_tap_extractor
tap_extractor_t wslua_get_tap_extractor(const char *name)
Retrieves a tap extractor by name.
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
lua_prime_all_fields
void lua_prime_all_fields(proto_tree *tree)
Primes all fields in the protocol tree.
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:2086
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)
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:32
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:484
wslua_prefs_changed
void wslua_prefs_changed(void)
Notify Lua scripts that preferences have changed.
Definition init_wslua.c:656
wslua_state
lua_State * wslua_state(void)
Retrieves the Lua state associated with Wireshark.
Definition init_wslua.c:2095
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_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:103
clear_current_plugin_version
void clear_current_plugin_version(void)
Clear the current plugin version.
Definition wslua_utility.c:36
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:1170
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_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)
Definition wslua_internals.c:470
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.
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_get_actual_filename
char * wslua_get_actual_filename(const char *fname)
Retrieves the actual filename with normalized path separators.
Definition wslua_utility.c:373
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
lua_register_all_taps
GString * lua_register_all_taps(void)
Registers all Lua taps.
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