Bug Summary

File:builds/wireshark/wireshark/epan/wslua/wslua_tree.c
Warning:line 761, column 5
Undefined or garbage value returned to caller

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name wslua_tree.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-18/lib/clang/18 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/lua5.4 -isystem /builds/wireshark/wireshark/build/epan/wslua -isystem /builds/wireshark/wireshark/epan/wslua -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-truncation -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -ferror-limit 19 -fvisibility=hidden -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -dwarf-debug-flags /usr/lib/llvm-18/bin/clang -### --analyze -x c -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/lua5.4 -isystem /builds/wireshark/wireshark/build/epan/wslua -isystem /builds/wireshark/wireshark/epan/wslua -fvisibility=hidden -fexcess-precision=fast -fstrict-flex-arrays=3 -fstack-clash-protection -fcf-protection=full -D _GLIBCXX_ASSERTIONS -fstack-protector-strong -fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -fexceptions -Wno-format-truncation -Wno-format-nonliteral -fdiagnostics-color=always -Wno-pointer-sign -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -std=gnu11 -fPIC /builds/wireshark/wireshark/epan/wslua/wslua_tree.c -o /builds/wireshark/wireshark/sbout/2024-10-22-100333-3919-1 -Xclang -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2024-10-22-100333-3919-1 -x c /builds/wireshark/wireshark/epan/wslua/wslua_tree.c
1/*
2 * wslua_tree.c
3 *
4 * Wireshark's interface to the Lua Programming Language
5 *
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 * (c) 2008, Balint Reczey <balint.reczey@ericsson.com>
8 *
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16#include "config.h"
17
18/* WSLUA_MODULE Tree Adding Information To The Dissection Tree */
19
20#include "wslua.h"
21#include <epan/exceptions.h>
22#include <epan/show_exception.h>
23
24static int wslua_ett = -1;
25
26static GPtrArray* outstanding_TreeItem;
27
28
29/* pushing a TreeItem with a NULL item or subtree is completely valid for this function */
30TreeItem push_TreeItem(lua_State *L, proto_tree *tree, proto_item *item) {
31 TreeItem ti = g_new(struct _wslua_treeitem, 1)((struct _wslua_treeitem *) g_malloc_n ((1), sizeof (struct _wslua_treeitem
)))
;
32
33 ti->tree = tree;
34 ti->item = item;
35 ti->expired = false0;
36
37 g_ptr_array_add(outstanding_TreeItem, ti);
38
39 return *(pushTreeItem(L,ti));
40}
41
42/* creates the TreeItem but does NOT push it into Lua */
43TreeItem create_TreeItem(proto_tree* tree, proto_item* item)
44{
45 TreeItem tree_item = (TreeItem)g_malloc(sizeof(struct _wslua_treeitem));
46 tree_item->tree = tree;
47 tree_item->item = item;
48 tree_item->expired = false0;
49
50 return tree_item;
51}
52
53CLEAR_OUTSTANDING(TreeItem, expired, true)void clear_outstanding_TreeItem(void) { while (outstanding_TreeItem
->len) { TreeItem p = (TreeItem)g_ptr_array_remove_index_fast
(outstanding_TreeItem,0); if (p) { if (p->expired != 1) p->
expired = 1; else g_free(p); } } }
54
55WSLUA_CLASS_DEFINE(TreeItem,FAIL_ON_NULL_OR_EXPIRED("TreeItem"))TreeItem toTreeItem(lua_State* L, int idx) { TreeItem* v = (TreeItem
*)lua_touserdata (L, idx); if (!v) luaL_error(L, "bad argument %d (%s expected, got %s)"
, idx, "TreeItem", lua_typename(L, lua_type(L, idx))); return
v ? *v : ((void*)0); } TreeItem checkTreeItem(lua_State* L, int
idx) { TreeItem* p; luaL_checktype(L,idx,7); p = (TreeItem*)
luaL_checkudata(L, idx, "TreeItem"); if (!*p) { luaL_argerror
(L,idx,"null " "TreeItem"); } else if ((*p)->expired) { luaL_argerror
(L,idx,"expired " "TreeItem"); }; return p ? *p : ((void*)0);
} TreeItem* pushTreeItem(lua_State* L, TreeItem v) { TreeItem
* p; luaL_checkstack(L,2,"Unable to grow stack\n"); p = (TreeItem
*)lua_newuserdatauv(L,sizeof(TreeItem),1); *p = v; (lua_getfield
(L, (-1000000 - 1000), ("TreeItem"))); lua_setmetatable(L, -2
); return p; }_Bool isTreeItem(lua_State* L,int i) { void *p;
if(!lua_isuserdata(L,i)) return 0; p = lua_touserdata(L, i);
lua_getfield(L, (-1000000 - 1000), "TreeItem"); if (p == ((void
*)0) || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -2)) p
=((void*)0); lua_settop(L, -(2)-1); return p ? 1 : 0; } TreeItem
shiftTreeItem(lua_State* L,int i) { TreeItem* p; if(!lua_isuserdata
(L,i)) return ((void*)0); p = (TreeItem*)lua_touserdata(L, i)
; lua_getfield(L, (-1000000 - 1000), "TreeItem"); if (p == ((
void*)0) || !lua_getmetatable(L, i) || !lua_rawequal(L, -1, -
2)) p=((void*)0); lua_settop(L, -(2)-1); if (p) { (lua_rotate
(L, (i), -1), lua_settop(L, -(1)-1)); return *p; } else return
((void*)0);} typedef int dummyTreeItem
;
56/* <<lua_class_TreeItem,`TreeItem`>>s represent information in the https://www.wireshark.org/docs/wsug_html_chunked/ChUsePacketDetailsPaneSection.html[packet details] pane of Wireshark, and the packet details view of TShark.
57 A <<lua_class_TreeItem,`TreeItem`>> represents a node in the tree, which might also be a subtree and have a list of children.
58 The children of a subtree have zero or more siblings which are other children of the same <<lua_class_TreeItem,`TreeItem`>> subtree.
59
60 During dissection, heuristic-dissection, and post-dissection, a root <<lua_class_TreeItem,`TreeItem`>> is passed to dissectors as the third argument of the function
61 callback (e.g., `myproto.dissector(tvbuf,pktinfo,root)`).
62
63 In some cases the tree is not truly added to, in order to improve performance.
64 For example for packets not currently displayed/selected in Wireshark's visible
65 window pane, or if TShark isn't invoked with the `-V` switch. However the
66 "add" type <<lua_class_TreeItem,`TreeItem`>> functions can still be called, and still return <<lua_class_TreeItem,`TreeItem`>>
67 objects - but the info isn't really added to the tree. Therefore you do not
68 typically need to worry about whether there's a real tree or not. If, for some
69 reason, you need to know it, you can use the <<lua_class_attrib_treeitem_visible,`TreeItem.visible`>> attribute getter
70 to retrieve the state.
71 */
72
73/* the following is used by TreeItem_add_packet_field() - this can THROW errors */
74static proto_item *
75try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int hfid,
76 const ftenum_t type, const unsigned encoding, int *ret_err)
77{
78 int err = 0;
79 proto_item *volatile item = NULL((void*)0);
80 int endoff = 0;
81
82 switch(type) {
83 /* these all generate ByteArrays */
84 case FT_BYTES:
85 case FT_UINT_BYTES:
86 case FT_OID:
87 case FT_REL_OID:
88 case FT_SYSTEM_ID:
89 {
90 /* GByteArray and its data will be g_free'd by Lua */
91 GByteArray *gba = g_byte_array_new();
92 item = proto_tree_add_bytes_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
93 tvbr->offset, tvbr->len, encoding,
94 gba, &endoff, &err);
95 if (err == 0) {
96 pushByteArray(L, gba);
97 lua_pushinteger(L, endoff);
98 }
99 }
100 break;
101
102 case FT_ABSOLUTE_TIME:
103 case FT_RELATIVE_TIME:
104 {
105 /* nstime_t will be g_free'd by Lua */
106 nstime_t *nstime = g_new0(nstime_t, 1)((nstime_t *) g_malloc0_n ((1), sizeof (nstime_t)));
107 item = proto_tree_add_time_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
108 tvbr->offset, tvbr->len, encoding,
109 nstime, &endoff, &err);
110 if (err == 0) {
111 pushNSTime(L,nstime);
112 lua_pushinteger(L, endoff);
113 }
114 }
115 break;
116
117 case FT_INT8:
118 case FT_INT16:
119 case FT_INT24:
120 case FT_INT32:
121 {
122 int32_t ret;
123 item = proto_tree_add_item_ret_int(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
124 tvbr->offset, tvbr->len, encoding,
125 &ret);
126 lua_pushinteger(L, (lua_Integer)ret);
127 lua_pushinteger(L, tvbr->offset + tvbr->len);
128 }
129 break;
130
131 case FT_INT40:
132 case FT_INT48:
133 case FT_INT56:
134 case FT_INT64:
135 {
136 int64_t ret;
137 item = proto_tree_add_item_ret_int64(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
138 tvbr->offset, tvbr->len, encoding,
139 &ret);
140 pushInt64(L, ret);
141 lua_pushinteger(L, tvbr->offset + tvbr->len);
142 }
143 break;
144
145 case FT_CHAR:
146 case FT_UINT8:
147 case FT_UINT16:
148 case FT_UINT24:
149 case FT_UINT32:
150 {
151 uint32_t ret;
152 item = proto_tree_add_item_ret_uint(tree_item-> tree, hfid, tvbr->tvb->ws_tvb,
153 tvbr->offset, tvbr->len, encoding,
154 &ret);
155 lua_pushinteger(L, (lua_Integer)ret);
156 lua_pushinteger(L, tvbr->offset + tvbr->len);
157 }
158 break;
159
160 case FT_UINT40:
161 case FT_UINT48:
162 case FT_UINT56:
163 case FT_UINT64:
164 {
165 uint64_t ret;
166 item = proto_tree_add_item_ret_uint64(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
167 tvbr->offset, tvbr->len, encoding,
168 &ret);
169 pushUInt64(L, ret);
170 lua_pushinteger(L, tvbr->offset + tvbr->len);
171 }
172 break;
173
174 case FT_BOOLEAN:
175 {
176 bool_Bool ret;
177 item = proto_tree_add_item_ret_boolean(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
178 tvbr->offset, tvbr->len, encoding,
179 &ret);
180 lua_pushboolean(L, ret);
181 lua_pushinteger(L, tvbr->offset + tvbr->len);
182 }
183 break;
184
185 case FT_STRING:
186 {
187 const uint8_t *ret;
188 int len;
189 item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
190 tvbr->offset, tvbr->len, encoding,
191 NULL((void*)0), &ret, &len);
192 lua_pushstring(L, ret);
193 lua_pushinteger(L, tvbr->offset + len);
194 wmem_free(NULL((void*)0), (void*)ret);
195 }
196 break;
197
198 case FT_STRINGZ:
199 {
200 const uint8_t *ret;
201 int len;
202 item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
203 tvbr->offset, -1, encoding,
204 NULL((void*)0), &ret, &len);
205 lua_pushstring(L, ret);
206 lua_pushinteger(L, tvbr->offset + len);
207 wmem_free(NULL((void*)0), (void*)ret);
208 }
209 break;
210
211 case FT_FLOAT:
212 {
213 float ret;
214 item = proto_tree_add_item_ret_float(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
215 tvbr->offset, tvbr->len, encoding,
216 &ret);
217 lua_pushnumber(L, (lua_Number)ret);
218 lua_pushinteger(L, tvbr->offset + tvbr->len);
219 }
220 break;
221
222 case FT_DOUBLE:
223 {
224 double ret;
225 item = proto_tree_add_item_ret_double(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
226 tvbr->offset, tvbr->len, encoding,
227 &ret);
228 lua_pushnumber(L, (lua_Number)ret);
229 lua_pushinteger(L, tvbr->offset + tvbr->len);
230 }
231 break;
232
233 case FT_IPv4:
234 {
235 Address addr = g_new(address,1)((address *) g_malloc_n ((1), sizeof (address)));
236 ws_in4_addr ret;
237 item = proto_tree_add_item_ret_ipv4(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
238 tvbr->offset, tvbr->len, encoding,
239 &ret);
240 alloc_address_wmem(NULL((void*)0), addr, AT_IPv4, sizeof(ret), &ret);
241 pushAddress(L, addr);
242 lua_pushinteger(L, tvbr->offset + tvbr->len);
243 }
244 break;
245
246 case FT_IPv6:
247 {
248 Address addr = g_new(address, 1)((address *) g_malloc_n ((1), sizeof (address)));
249 ws_in6_addr ret;
250 item = proto_tree_add_item_ret_ipv6(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
251 tvbr->offset, tvbr->len, encoding,
252 &ret);
253 alloc_address_wmem(NULL((void*)0), addr, AT_IPv6, sizeof(ret), &ret);
254 pushAddress(L, addr);
255 lua_pushinteger(L, tvbr->offset + tvbr->len);
256 }
257 break;
258
259 case FT_ETHER:
260 {
261 Address addr = g_new(address, 1)((address *) g_malloc_n ((1), sizeof (address)));
262 uint8_t bytes[FT_ETHER_LEN6];
263
264 item = proto_tree_add_item_ret_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
265 tvbr->offset, tvbr->len, encoding,
266 bytes);
267 alloc_address_wmem(NULL((void*)0), addr, AT_ETHER, sizeof(bytes), bytes);
268 pushAddress(L, addr);
269 lua_pushinteger(L, tvbr->offset + tvbr->len);
270 }
271 break;
272
273 default:
274 item = proto_tree_add_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding);
275 lua_pushnil(L);
276 lua_pushnil(L);
277 break;
278 }
279
280 if (ret_err) *ret_err = err;
281
282 return item;
283}
284
285WSLUA_METHODstatic int TreeItem_add_packet_field(lua_State *L) {
286 /*
287 Adds a new child tree for the given <<lua_class_ProtoField,`ProtoField`>> object to this tree item,
288 returning the new child <<lua_class_TreeItem,`TreeItem`>>.
289
290 Unlike `TreeItem:add()` and `TreeItem:add_le()`, the <<lua_class_ProtoField,`ProtoField`>> argument
291 is not optional, and cannot be a `Proto` object. Instead, this function always
292 uses the <<lua_class_ProtoField,`ProtoField`>> to determine the type of field to extract from the
293 passed-in `TvbRange`, highlighting the relevant bytes in the Packet Bytes pane
294 of the GUI (if there is a GUI), etc. If no <<lua_class_TvbRange,`TvbRange`>>is given, no bytes are
295 highlighted and the field's value cannot be determined; the <<lua_class_ProtoField,`ProtoField`>> must
296 have been defined/created not to have a length in such a case, or an error will
297 occur. For backwards-compatibility reasons the `encoding` argument, however,
298 must still be given.
299
300 Unlike `TreeItem:add()` and `TreeItem:add_le()`, this function performs both
301 big-endian and little-endian decoding, by setting the `encoding` argument to
302 be `ENC_BIG_ENDIAN` or `ENC_LITTLE_ENDIAN`.
303
304 The signature of this function:
305
306 [source,lua]
307 ----
308 tree_item:add_packet_field(proto_field [,tvbrange], encoding, ...)
309 ----
310
311 In Wireshark version 1.11.3, this function was changed to return more than
312 just the new child <<lua_class_TreeItem,`TreeItem`>>. The child is the first return value, so that
313 function chaining will still work as before; but it now also returns more information.
314 The second return is the value of the extracted field (i.e., a number, `UInt64`, `Address`, etc.).
315 The third return is is the offset where data should be read next. This is useful when the length of the
316 field is not known in advance. The additional return values may be null if the field type
317 is not well supported in the Lua API.
318
319 Another new feature added to this function in Wireshark version 1.11.3 is the
320 ability to extract native number `ProtoField`++s++ from string encoding in the
321 `TvbRange`, for ASCII-based and similar string encodings. For example, a
322 <<lua_class_ProtoField,`ProtoField`>> of type `ftypes.UINT32` can be extracted from a `TvbRange`
323 containing the ASCII string "123", and it will correctly decode the ASCII to
324 the number `123`, both in the tree as well as for the second return value of
325 this function. To do so, you must set the `encoding` argument of this function
326 to the appropriate string `ENC_*` value, bitwise-or'd with the `ENC_STRING`
327 value. `ENC_STRING` is guaranteed to be a unique bit flag, and
328 thus it can added instead of bitwise-or'ed as well. Only single-byte ASCII digit
329 string encoding types can be used for this, such as `ENC_ASCII` and `ENC_UTF_8`.
330
331 For example, assuming the <<lua_class_Tvb,`Tvb`>> named "`tvb`" contains the string "123":
332
333 [source,lua]
334 ----
335 -- this is done earlier in the script
336 local myfield = ProtoField.new("Transaction ID", "myproto.trans_id", ftypes.UINT16)
337
338 -- this is done inside a dissector, post-dissector, or heuristic function
339 -- child will be the created child tree, and value will be the number 123 or nil on failure
340 local child, value = tree:add_packet_field(myfield, tvb:range(0,3), ENC_UTF_8 + ENC_STRING)
341 ----
342
343 */
344#define WSLUA_ARG_TreeItem_add_packet_field_PROTOFIELD2 2 /* The ProtoField field object to add to the tree. */
345#define WSLUA_OPTARG_TreeItem_add_packet_field_TVBRANGE3 3 /* The <<lua_class_TvbRange,`TvbRange`>> of bytes in the packet this tree item covers/represents. */
346#define WSLUA_ARG_TreeItem_add_packet_field_ENCODING4 4 /* The field's encoding in the `TvbRange`. */
347#define WSLUA_OPTARG_TreeItem_add_packet_field_LABEL5 5 /* One or more strings to append to the created <<lua_class_TreeItem,`TreeItem`>>. */
348 volatile TvbRange tvbr;
349 ProtoField field;
350 int hfid;
351 volatile int ett;
352 ftenum_t type;
353 TreeItem tree_item = shiftTreeItem(L,1);
354 unsigned encoding;
355 proto_item* item = NULL((void*)0);
356 volatile int nargs;
357 volatile int err = 0;
358 const char *volatile error = NULL((void*)0);
359
360 if (!tree_item) {
361 return luaL_error(L,"not a TreeItem!");
362 }
363 if (tree_item->expired) {
364 luaL_error(L,"expired TreeItem");
365 return 0;
366 }
367
368 if (! ( field = shiftProtoField(L,1) ) ) {
369 luaL_error(L,"TreeField:add_packet_field not passed a ProtoField");
370 return 0;
371 }
372 hfid = field->hfid;
373 type = field->type;
374 ett = field->ett;
375
376 tvbr = shiftTvbRange(L,1);
377 if (!tvbr) {
378 /* No TvbRange specified */
379 tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange)((struct _wslua_tvbrange*)wmem_alloc((lua_pinfo->pool), sizeof
(struct _wslua_tvbrange)))
;
380 tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb)((struct _wslua_tvb*)wmem_alloc((lua_pinfo->pool), sizeof(
struct _wslua_tvb)))
;
381 tvbr->tvb->ws_tvb = lua_tvb;
382 tvbr->offset = 0;
383 tvbr->len = 0;
384 }
385
386 encoding = wslua_checkuint(L,1)(unsigned) ( luaL_checkinteger(L,1) );
387 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
388
389 /* get the number of additional args before we add more to the stack */
390 nargs = lua_gettop(L);
391
392 /* XXX: why is this being done? If the length was -1, FT_STRINGZ figures out
393 * the right length in tvb_get_stringz_enc(); if it was 0, it should remain zero;
394 * if it was greater than zero, then it's the length the caller wanted.
395 */
396 if (type == FT_STRINGZ) {
397 switch (encoding & ENC_CHARENCODING_MASK0x0000FFFE) {
398
399 case ENC_UTF_160x00000004:
400 case ENC_UCS_20x00000006:
401 tvbr->len = tvb_unicode_strsize (tvbr->tvb->ws_tvb, tvbr->offset);
402 break;
403
404 default:
405 if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) {
406 luaL_error(L,"out of bounds");
407 return 0;
408 }
409 tvbr->len = tvb_strsize (tvbr->tvb->ws_tvb, tvbr->offset);
410 break;
411 }
412 }
413
414 TRY{ except_t *volatile exc; volatile int except_state = 0; static
const except_id_t catch_spec[] = { { 1, 0 } }; { struct except_stacknode
except_sn; struct except_catch except_ch; except_setup_try(&
except_sn, &except_ch, catch_spec, 1); if (_setjmp (except_ch
.except_jmp)) *(&exc) = &except_ch.except_obj; else *
(&exc) = 0; if(except_state & 1) except_state |= 2; except_state
&= ~1; if (except_state == 0 && exc == 0)
{
415 int errx = 0;
416 item = try_add_packet_field(L, tree_item, tvbr, hfid, type, encoding, &errx);
417 err = errx;
418 } CATCH_ALLif (except_state == 0 && exc != 0 && (except_state
|=1))
{
419 show_exception(tvbr->tvb->ws_tvb, lua_pinfo, tree_item->tree, EXCEPT_CODE((exc)->except_id.except_code), GET_MESSAGE((exc)->except_message));
420 error = "Lua programming error";
421 } ENDTRYif(!(except_state&1) && exc != 0) except_rethrow(
exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}
;
422
423 if (error) { WSLUA_ERROR(TreeItem_add_packet_field,error){ luaL_error(L, "%s%s", "TreeItem_add_packet_field" ": ", error
); }
; }
424
425 if (err != 0) {
426 lua_pushnil(L);
427 lua_pushnil(L);
428 }
429
430 while(nargs) {
431 const char* s;
432 s = lua_tostring(L,1)lua_tolstring(L, (1), ((void*)0));
433 if (s) proto_item_append_text(item, " %s", s);
434 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
435 nargs--;
436 }
437
438 push_TreeItem(L, proto_item_add_subtree(item,ett > 0 ? ett : wslua_ett), item);
439
440 /* move the tree object before the field value */
441 lua_insert(L, 1)lua_rotate(L, (1), 1);
442
443 WSLUA_RETURN(3)return (3); /* The new child <<lua_class_TreeItem,`TreeItem`>>, the field's extracted value or nil, and offset or nil. */
444}
445
446/* The following is used by TreeItem_add() and TreeItem_le() and can THROW.
447 * It should be called inside a TRY (e.g. WRAP_NON_LUA_EXCEPTIONS) block and
448 * THROW_LUA_ERROR should be used insteadof lua[L]_error.
449 */
450static int TreeItem_add_item_any(lua_State *L, bool_Bool little_endian) {
451 TvbRange tvbr;
452 Proto proto;
453 ProtoField field;
454 int hfid = -1;
455 int ett = -1;
456 ftenum_t type = FT_NONE;
457 TreeItem tree_item = shiftTreeItem(L,1);
458 proto_item* item = NULL((void*)0);
459
460 if (!tree_item) {
461 THROW_LUA_ERROR("not a TreeItem!")except_throwf(1, (6), "not a TreeItem!");
462 }
463 if (tree_item->expired) {
464 THROW_LUA_ERROR("expired TreeItem")except_throwf(1, (6), "expired TreeItem");
465 return 0;
466 }
467
468 if (! ( field = shiftProtoField(L,1) ) ) {
469 if (( proto = shiftProto(L,1) )) {
470 hfid = proto->hfid;
471 type = FT_PROTOCOL;
472 ett = proto->ett;
473 } else if (lua_isnil(L, 1)(lua_type(L, (1)) == 0)) {
474 THROW_LUA_ERROR("first argument to TreeItem:add is nil!")except_throwf(1, (6), "first argument to TreeItem:add is nil!"
)
;
475 }
476 } else {
477 hfid = field->hfid;
478 type = field->type;
479 ett = field->ett;
480 }
481
482 tvbr = shiftTvbRange(L,1);
483
484 if (!tvbr) {
485 tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange)((struct _wslua_tvbrange*)wmem_alloc((lua_pinfo->pool), sizeof
(struct _wslua_tvbrange)))
;
486 tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb)((struct _wslua_tvb*)wmem_alloc((lua_pinfo->pool), sizeof(
struct _wslua_tvb)))
;
487 tvbr->tvb->ws_tvb = lua_tvb;
488 tvbr->offset = 0;
489 tvbr->len = 0;
490 }
491
492 if (hfid > 0 ) {
493 /* hfid is > 0 when the first arg was a ProtoField or Proto */
494
495 if (type == FT_STRINGZ) {
496 if (tvb_find_uint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) {
497 THROW_LUA_ERROR("out of bounds")except_throwf(1, (6), "out of bounds");
498 return 0;
499 }
500 tvbr->len = tvb_strsize (tvbr->tvb->ws_tvb, tvbr->offset);
501 }
502
503 if (lua_gettop(L)) {
504 /* if we got here, the (L,1) index is the value to add, instead of decoding from the Tvb */
505
506 switch(type) {
507 case FT_PROTOCOL:
508 item = proto_tree_add_item(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,ENC_NA0x00000000);
509 lua_pushinteger(L,0);
510 lua_insert(L,1)lua_rotate(L, (1), 1);
511 break;
512 case FT_BOOLEAN:
513 {
514 uint64_t val;
515 switch(lua_type(L, 1)) {
516
517 case LUA_TUSERDATA7:
518 val = checkUInt64(L, 1);
519 break;
520
521 default:
522 /* this needs to use checkinteger so that it can accept a Lua boolean and coerce it to an int */
523 val = (uint64_t) (wslua_tointeger(L,1));
524 }
525 item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,val);
526 }
527 break;
528 case FT_CHAR:
529 case FT_UINT8:
530 case FT_UINT16:
531 case FT_UINT24:
532 case FT_UINT32:
533 case FT_FRAMENUM:
534 item = proto_tree_add_uint(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkuint32(L,1)(uint32_t) ( luaL_checkinteger(L,1) ));
535 break;
536 case FT_INT8:
537 case FT_INT16:
538 case FT_INT24:
539 case FT_INT32:
540 item = proto_tree_add_int(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,wslua_checkint32(L,1)(int32_t) ( luaL_checkinteger(L,1) ));
541 break;
542 case FT_FLOAT:
543 item = proto_tree_add_float(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(float)luaL_checknumber(L,1));
544 break;
545 case FT_DOUBLE:
546 item = proto_tree_add_double(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(double)luaL_checknumber(L,1));
547 break;
548 case FT_ABSOLUTE_TIME:
549 case FT_RELATIVE_TIME:
550 item = proto_tree_add_time(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,checkNSTime(L,1));
551 break;
552 case FT_STRING:
553 case FT_STRINGZ:
554 item = proto_tree_add_string(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,luaL_checkstring(L,1)(luaL_checklstring(L, (1), ((void*)0))));
555 break;
556 case FT_BYTES:
557 item = proto_tree_add_bytes(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len, (const uint8_t*) luaL_checkstring(L,1)(luaL_checklstring(L, (1), ((void*)0))));
558 break;
559 case FT_UINT64:
560 item = proto_tree_add_uint64(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,checkUInt64(L,1));
561 break;
562 case FT_INT64:
563 item = proto_tree_add_int64(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,checkInt64(L,1));
564 break;
565 case FT_IPv4:
566 {
567 Address addr = checkAddress(L,1);
568 uint32_t addr_value;
569
570 if (addr->type != AT_IPv4) {
571 THROW_LUA_ERROR("Expected IPv4 address for FT_IPv4 field")except_throwf(1, (6), "Expected IPv4 address for FT_IPv4 field"
)
;
572 return 0;
573 }
574
575 /*
576 * The address is not guaranteed to be aligned on a
577 * 32-bit boundary, so we can't safely dereference
578 * the pointer as if it were so aligned.
579 */
580 memcpy(&addr_value, addr->data, sizeof addr_value);
581 item = proto_tree_add_ipv4(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,addr_value);
582 }
583 break;
584 case FT_IPv6:
585 {
586 Address addr = checkAddress(L,1);
587 if (addr->type != AT_IPv6) {
588 THROW_LUA_ERROR("Expected IPv6 address for FT_IPv6 field")except_throwf(1, (6), "Expected IPv6 address for FT_IPv6 field"
)
;
589 return 0;
590 }
591
592 item = proto_tree_add_ipv6(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, (const ws_in6_addr *)addr->data);
593 }
594 break;
595 case FT_ETHER:
596 {
597 Address addr = checkAddress(L,1);
598 if (addr->type != AT_ETHER) {
599 THROW_LUA_ERROR("Expected MAC address for FT_ETHER field")except_throwf(1, (6), "Expected MAC address for FT_ETHER field"
)
;
600 return 0;
601 }
602
603 item = proto_tree_add_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, (const uint8_t *)addr->data);
604 }
605 break;
606 case FT_UINT_BYTES:
607 case FT_IPXNET:
608 case FT_GUID:
609 case FT_OID:
610 case FT_REL_OID:
611 case FT_SYSTEM_ID:
612 case FT_VINES:
613 case FT_FCWWN:
614 default:
615 THROW_LUA_ERROR("%s not yet supported", ftype_name(type))except_throwf(1, (6), "%s not yet supported", ftype_name(type
))
;
616 return 0;
617 }
618
619 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
620
621 } else {
622 if (type == FT_FRAMENUM) {
623 THROW_LUA_ERROR("ProtoField FRAMENUM cannot fetch value from Tvb")except_throwf(1, (6), "ProtoField FRAMENUM cannot fetch value from Tvb"
)
;
624 return 0;
625 }
626 /* the Lua stack is empty - no value was given - so decode the value from the tvb */
627 item = proto_tree_add_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, little_endian ? ENC_LITTLE_ENDIAN0x80000000 : ENC_BIG_ENDIAN0x00000000);
628 }
629
630 if ( lua_gettop(L) ) {
631 /* if there was a value, it was removed earlier, so what's left is the display string to set */
632 const char* s = lua_tostring(L,1)lua_tolstring(L, (1), ((void*)0));
633 if (s) proto_item_set_text(item,"%s",s);
634 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
635 }
636
637 } else {
638 /* no ProtoField or Proto was given */
639 if (lua_gettop(L)) {
640 const char* s = lua_tostring(L,1)lua_tolstring(L, (1), ((void*)0));
641 const int hf = get_hf_wslua_text();
642 if (hf > -1) {
643 /* use proto_tree_add_none_format() instead? */
644 item = proto_tree_add_item(tree_item->tree, hf, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, ENC_NA0x00000000);
645 proto_item_set_text(item, "%s", s);
646 } else {
647 THROW_LUA_ERROR("Internal error: hf_wslua_text not registered")except_throwf(1, (6), "Internal error: hf_wslua_text not registered"
)
;
648 }
649 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
650 } else {
651 THROW_LUA_ERROR("Tree item ProtoField/Protocol handle is invalid (ProtoField/Proto not registered?)")except_throwf(1, (6), "Tree item ProtoField/Protocol handle is invalid (ProtoField/Proto not registered?)"
)
;
652 }
653 }
654
655 while(lua_gettop(L)) {
656 /* keep appending more text */
657 const char* s = lua_tostring(L,1)lua_tolstring(L, (1), ((void*)0));
658 if (s) proto_item_append_text(item, " %s", s);
659 lua_remove(L,1)(lua_rotate(L, (1), -1), lua_settop(L, -(1)-1));
660 }
661
662 push_TreeItem(L, proto_item_add_subtree(item,ett > 0 ? ett : wslua_ett), item);
663
664 return 1;
665}
666
667
668WSLUA_METHODstatic int TreeItem_add(lua_State *L) {
669 /*
670 Adds a child item to this tree item, returning the new child <<lua_class_TreeItem,`TreeItem`>>.
671
672 If the <<lua_class_ProtoField,`ProtoField`>> represents a numeric value (int, uint or float), then it's treated as a Big Endian (network order) value.
673
674 This function has a complicated form: 'treeitem:add([protofield,] [tvbrange,] [[value], label]])', such that if the first
675 argument is a <<lua_class_ProtoField,`ProtoField`>> or a <<lua_class_Proto,`Proto`>>, the second argument is a <<lua_class_TvbRange,`TvbRange`>>, and a third argument is given, it's a value;
676 but if the second argument is a non-<<lua_class_TvbRange,`TvbRange`>>, then it's the value (as opposed to filling that argument with 'nil',
677 which is invalid for this function). If the first argument is a non-<<lua_class_ProtoField,`ProtoField`>> and a non-<<lua_class_Proto,`Proto`>> then this argument can
678 be either a <<lua_class_TvbRange,`TvbRange`>> or a label, and the value is not in use.
679
680 [discrete]
681 ====== Example
682
683 [source,lua]
684 ----
685 local proto_foo = Proto("foo", "Foo Protocol")
686 proto_foo.fields.bytes = ProtoField.bytes("foo.bytes", "Byte array")
687 proto_foo.fields.u16 = ProtoField.uint16("foo.u16", "Unsigned short", base.HEX)
688
689 function proto_foo.dissector(buf, pinfo, tree)
690 -- ignore packets less than 4 bytes long
691 if buf:len() < 4 then return end
692
693 -- ##############################################
694 -- # Assume buf(0,4) == {0x00, 0x01, 0x00, 0x02}
695 -- ##############################################
696
697 local t = tree:add( proto_foo, buf() )
698
699 -- Adds a byte array that shows as: "Byte array: 00010002"
700 t:add( proto_foo.fields.bytes, buf(0,4) )
701
702 -- Adds a byte array that shows as "Byte array: 313233"
703 -- (the ASCII char code of each character in "123")
704 t:add( proto_foo.fields.bytes, buf(0,4), "123" )
705
706 -- Adds a tree item that shows as: "Unsigned short: 0x0001"
707 t:add( proto_foo.fields.u16, buf(0,2) )
708
709 -- Adds a tree item that shows as: "Unsigned short: 0x0064"
710 t:add( proto_foo.fields.u16, buf(0,2), 100 )
711
712 -- Adds a tree item that shows as: "Unsigned short: 0x0064 ( big endian )"
713 t:add( proto_foo.fields.u16, buf(1,2), 100, nil, "(", nil, "big", 999, nil, "endian", nil, ")" )
714
715 -- LITTLE ENDIAN: Adds a tree item that shows as: "Unsigned short: 0x0100"
716 t:add_le( proto_foo.fields.u16, buf(0,2) )
717
718 -- LITTLE ENDIAN: Adds a tree item that shows as: "Unsigned short: 0x6400"
719 t:add_le( proto_foo.fields.u16, buf(0,2), 100 )
720
721 -- LITTLE ENDIAN: Adds a tree item that shows as: "Unsigned short: 0x6400 ( little endian )"
722 t:add_le( proto_foo.fields.u16, buf(1,2), 100, nil, "(", nil, "little", 999, nil, "endian", nil, ")" )
723 end
724
725 udp_table = DissectorTable.get("udp.port")
726 udp_table:add(7777, proto_foo)
727 ----
728 */
729#define WSLUA_OPTARG_TreeItem_add_PROTOFIELD2 2 /* The <<lua_class_ProtoField,`ProtoField`>> field or <<lua_class_Proto,`Proto`>> protocol object to add to the tree. */
730#define WSLUA_OPTARG_TreeItem_add_TVBRANGE3 3 /* The <<lua_class_TvbRange,`TvbRange`>> of bytes in the packet this tree item covers/represents. */
731#define WSLUA_OPTARG_TreeItem_add_VALUE4 4 /* The field's value, instead of the ProtoField/Proto one. */
732#define WSLUA_OPTARG_TreeItem_add_LABEL5 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */
733
734 volatile int ret;
735 WRAP_NON_LUA_EXCEPTIONS({ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,0)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
736 ret = TreeItem_add_item_any(L,false);{ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,0)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
737 ){ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,0)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
738 WSLUA_RETURN(ret)return (ret); /* The new child TreeItem. */
739}
740
741WSLUA_METHODstatic int TreeItem_add_le(lua_State *L) {
742 /*
743 Adds a child item to this tree item, returning the new child <<lua_class_TreeItem,`TreeItem`>>.
744
745 If the <<lua_class_ProtoField,`ProtoField`>> represents a numeric value (int, uint or float), then it's treated as a Little Endian value.
746
747 This function has a complicated form: 'treeitem:add_le([protofield,] [tvbrange,] [[value], label]])', such that if the first
748 argument is a <<lua_class_ProtoField,`ProtoField`>> or a <<lua_class_Proto,`Proto`>>, the second argument is a <<lua_class_TvbRange,`TvbRange`>>, and a third argument is given, it's a value;
749 but if the second argument is a non-<<lua_class_TvbRange,`TvbRange`>>, then it's the value (as opposed to filling that argument with 'nil',
750 which is invalid for this function). If the first argument is a non-<<lua_class_ProtoField,`ProtoField`>> and a non-<<lua_class_Proto,`Proto`>> then this argument can
751 be either a <<lua_class_TvbRange,`TvbRange`>> or a label, and the value is not in use.
752 */
753#define WSLUA_OPTARG_TreeItem_add_le_PROTOFIELD2 2 /* The ProtoField field or Proto protocol object to add to the tree. */
754#define WSLUA_OPTARG_TreeItem_add_le_TVBRANGE3 3 /* The TvbRange of bytes in the packet this tree item covers/represents. */
755#define WSLUA_OPTARG_TreeItem_add_le_VALUE4 4 /* The field's value, instead of the ProtoField/Proto one. */
756#define WSLUA_OPTARG_TreeItem_add_le_LABEL5 5 /* One or more strings to use for the tree item label, instead of the ProtoField/Proto one. */
757 volatile int ret;
1
'ret' declared without an initial value
758 WRAP_NON_LUA_EXCEPTIONS({ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,1)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
2
Assuming the condition is true
3
Taking true branch
4
Taking false branch
5
Taking false branch
6
Assuming field 'except_code' is equal to 1
7
Taking true branch
8
Taking false branch
759 ret = TreeItem_add_item_any(L,true);{ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,1)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
760 ){ volatile _Bool has_error = 0; { except_t *volatile exc; volatile
int except_state = 0; static const except_id_t catch_spec[] =
{ { 1, 0 } }; { struct except_stacknode except_sn; struct except_catch
except_ch; except_setup_try(&except_sn, &except_ch, catch_spec
, 1); if (_setjmp (except_ch.except_jmp)) *(&exc) = &
except_ch.except_obj; else *(&exc) = 0; if(except_state &
1) except_state |= 2; except_state &= ~1; if (except_state
== 0 && exc == 0) { ret = TreeItem_add_item_any(L,1)
; } if (except_state == 0 && exc != 0 && (exc
->except_id.except_code == (1) || exc->except_id.except_code
== (4) || exc->except_id.except_code == (7)) && (
except_state|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree
->tree, ((exc)->except_id.except_code), ((exc)->except_message
)); } if (except_state == 0 && exc != 0 && (except_state
|=1)) { show_exception(lua_tvb, lua_pinfo, lua_tree->tree,
((exc)->except_id.except_code), ((exc)->except_message
)); lua_pushfstring(L, "%s: %s", __func__, ((exc)->except_message
) ? ((exc)->except_message) : "Malformed packet"); has_error
= 1; } if(!(except_state&1) && exc != 0) except_rethrow
(exc); except_free(except_ch.except_obj.except_dyndata); except_pop
(); };}; if (has_error) { lua_error(L); } }
761 WSLUA_RETURN(ret)return (ret); /* The new child TreeItem. */
9
Undefined or garbage value returned to caller
762}
763
764/* WSLUA_ATTRIBUTE TreeItem_text RW Set/get the <<lua_class_TreeItem,`TreeItem`>>'s display string (string).
765
766 For the getter, if the TreeItem has no display string, then nil is returned.
767 */
768static int TreeItem_get_text(lua_State* L) {
769 TreeItem ti = checkTreeItem(L,1);
770 char label_str[ITEM_LABEL_LENGTH240+1];
771 char *label_ptr;
772
773 if (ti->item) {
774 field_info *fi = PITEM_FINFO(ti->item)((ti->item)->finfo);
775
776 if (!fi->rep) {
777 label_ptr = label_str;
778 proto_item_fill_label(fi, label_str, NULL((void*)0));
779 } else
780 label_ptr = fi->rep->representation;
781
782 if (label_ptr) {
783 lua_pushstring(L, label_ptr);
784 } else {
785 lua_pushnil(L);
786 }
787 } else {
788 lua_pushnil(L);
789 }
790
791 return 1;
792}
793
794/* the following is used as both a method and attribute */
795WSLUA_METHODstatic int TreeItem_set_text(lua_State *L) {
796 /* Sets the text of the label.
797
798 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
799 */
800#define WSLUA_ARG_TreeItem_set_text_TEXT2 2 /* The text to be used. */
801 TreeItem ti = checkTreeItem(L,1);
802 const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_set_text_TEXT)(luaL_checklstring(L, (2), ((void*)0)));
803
804 proto_item_set_text(ti->item,"%s",s);
805
806 /* copy the TreeItem userdata so we give it back */
807 lua_pushvalue(L, 1);
808
809 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
810}
811
812WSLUA_METHODstatic int TreeItem_append_text(lua_State *L) {
813 /* Appends text to the label.
814
815 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
816 */
817#define WSLUA_ARG_TreeItem_append_text_TEXT2 2 /* The text to be appended. */
818 TreeItem ti = checkTreeItem(L,1);
819 const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_append_text_TEXT)(luaL_checklstring(L, (2), ((void*)0)));
820
821 proto_item_append_text(ti->item,"%s",s);
822
823 /* copy the TreeItem userdata so we give it back */
824 lua_pushvalue(L, 1);
825
826 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
827}
828
829WSLUA_METHODstatic int TreeItem_prepend_text(lua_State *L) {
830 /* Prepends text to the label.
831
832 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
833 */
834#define WSLUA_ARG_TreeItem_prepend_text_TEXT2 2 /* The text to be prepended. */
835 TreeItem ti = checkTreeItem(L,1);
836 const char* s = luaL_checkstring(L,WSLUA_ARG_TreeItem_prepend_text_TEXT)(luaL_checklstring(L, (2), ((void*)0)));
837
838 proto_item_prepend_text(ti->item,"%s",s);
839
840 /* copy the TreeItem userdata so we give it back */
841 lua_pushvalue(L, 1);
842
843 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
844}
845
846WSLUA_METHODstatic int TreeItem_add_expert_info(lua_State *L) {
847 /* Sets the expert flags of the item and adds expert info to the packet.
848
849 This function does *not* create a truly filterable expert info for a protocol.
850 Instead you should use `TreeItem.add_proto_expert_info()`.
851
852 Note: This function is provided for backwards compatibility only, and should not
853 be used in new Lua code. It may be removed in the future. You should only
854 use `TreeItem.add_proto_expert_info()`.
855 */
856#define WSLUA_OPTARG_TreeItem_add_expert_info_GROUP2 2 /* One of:
857 `PI_CHECKSUM`,
858 `PI_SEQUENCE`,
859 `PI_RESPONSE_CODE`,
860 `PI_REQUEST_CODE`,
861 `PI_UNDECODED`,
862 `PI_REASSEMBLE`,
863 `PI_MALFORMED`,
864 `PI_DEBUG`,
865 `PI_PROTOCOL`,
866 `PI_SECURITY`,
867 `PI_COMMENTS_GROUP`,
868 `PI_DECRYPTION`,
869 `PI_ASSUMPTION`,
870 `PI_DEPRECATED`,
871 `PI_RECEIVE`,
872 `PI_INTERFACE`,
873 or `PI_DISSECTOR_BUG`. */
874#define WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY3 3 /* One of:
875 `PI_COMMENT`,
876 `PI_CHAT`,
877 `PI_NOTE`,
878 `PI_WARN`,
879 or `PI_ERROR`. */
880#define WSLUA_OPTARG_TreeItem_add_expert_info_TEXT4 4 /* The text for the expert info display. */
881 TreeItem ti = checkTreeItem(L,1);
882 int group = (int)luaL_optinteger(L,WSLUA_OPTARG_TreeItem_add_expert_info_GROUP2,PI_DEBUG0x08000000);
883 int severity = (int)luaL_optinteger(L,WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY3,PI_CHAT0x00200000);
884 expert_field* ei_info = wslua_get_expert_field(group, severity);
885 const char* str;
886
887 if (lua_gettop(L) >= WSLUA_OPTARG_TreeItem_add_expert_info_TEXT4) {
888 str = wslua_checkstring_only(L, WSLUA_OPTARG_TreeItem_add_expert_info_TEXT4);
889 expert_add_info_format(lua_pinfo, ti->item, ei_info, "%s", str);
890 } else {
891 expert_add_info(lua_pinfo, ti->item, ei_info);
892 }
893
894 /* copy the TreeItem userdata so we give it back */
895 lua_pushvalue(L, 1);
896
897 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
898}
899
900WSLUA_METHODstatic int TreeItem_add_proto_expert_info(lua_State *L) {
901 /* Sets the expert flags of the tree item and adds expert info to the packet. */
902#define WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT2 2 /* The <<lua_class_ProtoExpert,`ProtoExpert`>> object to add to the tree. */
903#define WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT3 3 /* Text for the expert info display
904 (default is to use the registered
905 text). */
906 TreeItem ti = checkTreeItem(L,1);
907 ProtoExpert expert = checkProtoExpert(L,WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT2);
908 const char* str;
909
910 if (expert->ids.ei == EI_INIT_EI-1 || expert->ids.hf == EI_INIT_HF-1) {
911 luaL_error(L, "ProtoExpert is not registered");
912 return 0;
913 }
914
915 if (lua_gettop(L) >= WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT3) {
916 str = wslua_checkstring_only(L, WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT3);
917 expert_add_info_format(lua_pinfo, ti->item, &expert->ids, "%s", str);
918 } else {
919 expert_add_info(lua_pinfo, ti->item, &expert->ids);
920 }
921
922 /* copy the TreeItem userdata so we give it back */
923 lua_pushvalue(L, 1);
924
925 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
926}
927
928WSLUA_METHODstatic int TreeItem_add_tvb_expert_info(lua_State *L) {
929 /* Sets the expert flags of the tree item and adds expert info to the packet
930 associated with the <<lua_class_Tvb,`Tvb`>> or <<lua_class_TvbRange,`TvbRange`>> bytes in the packet. */
931#define WSLUA_ARG_TreeItem_add_tvb_expert_info_EXPERT2 2 /* The <<lua_class_ProtoExpert,`ProtoExpert`>> object to add to the tree. */
932#define WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB3 3 /* The <<lua_class_Tvb,`Tvb`>> or <<lua_class_TvbRange,`TvbRange`>> object bytes to associate
933 the expert info with. */
934#define WSLUA_OPTARG_TreeItem_add_tvb_expert_info_TEXT4 4 /* Text for the expert info display
935 (default is to use the registered
936 text). */
937 TreeItem ti = checkTreeItem(L,1);
938 ProtoExpert expert = checkProtoExpert(L,WSLUA_ARG_TreeItem_add_proto_expert_info_EXPERT2);
939 TvbRange tvbr;
940 const char* str;
941
942 if (expert->ids.ei == EI_INIT_EI-1 || expert->ids.hf == EI_INIT_HF-1) {
943 luaL_error(L, "ProtoExpert is not registered");
944 return 0;
945 }
946
947 tvbr = shiftTvbRange(L,WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB3);
948
949 if (!tvbr) {
950 tvbr = wmem_new(lua_pinfo->pool, struct _wslua_tvbrange)((struct _wslua_tvbrange*)wmem_alloc((lua_pinfo->pool), sizeof
(struct _wslua_tvbrange)))
;
951 tvbr->tvb = shiftTvb(L,WSLUA_ARG_TreeItem_add_tvb_expert_info_TVB3);
952 if (!tvbr->tvb) {
953 tvbr->tvb = wmem_new(lua_pinfo->pool, struct _wslua_tvb)((struct _wslua_tvb*)wmem_alloc((lua_pinfo->pool), sizeof(
struct _wslua_tvb)))
;
954 }
955 tvbr->tvb->ws_tvb = lua_tvb;
956 tvbr->offset = 0;
957 tvbr->len = 0;
958 }
959
960 if (lua_gettop(L) >= WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT3) {
961 str = wslua_checkstring_only(L, WSLUA_OPTARG_TreeItem_add_proto_expert_info_TEXT3);
962 proto_tree_add_expert_format(ti->tree, lua_pinfo, &expert->ids,
963 tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len,
964 "%s", str);
965 } else {
966 proto_tree_add_expert(ti->tree, lua_pinfo, &expert->ids,
967 tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len);
968 }
969
970 /* copy the TreeItem userdata so we give it back */
971 lua_pushvalue(L, 1);
972
973 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
974}
975
976
977/* WSLUA_ATTRIBUTE TreeItem_visible RO Get the <<lua_class_TreeItem,`TreeItem`>>'s subtree visibility status (boolean). */
978static int TreeItem_get_visible(lua_State* L) {
979 TreeItem ti = checkTreeItem(L,1);
980
981 if (ti->tree) {
982 lua_pushboolean(L, PTREE_DATA(ti->tree)((ti->tree)->tree_data)->visible);
983 }
984 else {
985 lua_pushboolean(L, false0);
986 }
987
988 return 1;
989}
990
991
992/* WSLUA_ATTRIBUTE TreeItem_generated RW Set/get the <<lua_class_TreeItem,`TreeItem`>>'s generated state (boolean). */
993static int TreeItem_get_generated(lua_State* L) {
994 TreeItem ti = checkTreeItem(L,1);
995
996 lua_pushboolean(L, proto_item_is_generated(ti->item));
997
998 return 1;
999}
1000
1001/* the following is used as both a method and attribute. As a method it defaults
1002 to setting the value, because that's what it used to do before. */
1003WSLUA_METHODstatic int TreeItem_set_generated(lua_State *L) {
1004 /* Marks the <<lua_class_TreeItem,`TreeItem`>> as a generated field (with data inferred but not contained in the packet).
1005
1006 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
1007 */
1008#define WSLUA_OPTARG_TreeItem_set_generated_BOOL2 2 /* A Lua boolean, which if `true` sets the <<lua_class_TreeItem,`TreeItem`>>
1009 generated flag, else clears it (default=true) */
1010 TreeItem ti = checkTreeItem(L,1);
1011 bool_Bool set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_generated_BOOL2, true1);
1012
1013 if (set) {
1014 proto_item_set_generated(ti->item);
1015 } else {
1016 if (ti->item)
1017 FI_RESET_FLAG(PITEM_FINFO(ti->item), FI_GENERATED)do { if (((ti->item)->finfo)) (((ti->item)->finfo
))->flags = (((ti->item)->finfo))->flags & ~(
0x00000002); } while(0)
;
1018 }
1019
1020 /* copy the TreeItem userdata so we give it back */
1021 lua_pushvalue(L, 1);
1022
1023 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
1024}
1025
1026/* WSLUA_ATTRIBUTE TreeItem_hidden RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s hidden state (boolean). */
1027static int TreeItem_get_hidden(lua_State* L) {
1028 TreeItem ti = checkTreeItem(L,1);
1029
1030 lua_pushboolean(L, proto_item_is_hidden(ti->item));
1031
1032 return 1;
1033}
1034
1035/* the following is used as both a method and attribute. As a method it defaults
1036 to setting the value, because that's what it used to do before. */
1037WSLUA_METHODstatic int TreeItem_set_hidden(lua_State *L) {
1038 /*
1039 Marks the <<lua_class_TreeItem,`TreeItem`>> as a hidden field (neither displayed nor used in filters).
1040 Deprecated
1041
1042 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
1043 */
1044#define WSLUA_OPTARG_TreeItem_set_hidden_BOOL2 2 /* A Lua boolean, which if `true` sets the <<lua_class_TreeItem,`TreeItem`>>
1045 hidden flag, else clears it. Default is `true`. */
1046 TreeItem ti = checkTreeItem(L,1);
1047 bool_Bool set = wslua_optbool(L, WSLUA_OPTARG_TreeItem_set_hidden_BOOL2, true1);
1048
1049 if (set) {
1050 proto_item_set_hidden(ti->item);
1051 } else {
1052 proto_item_set_visible(ti->item);
1053 }
1054
1055 /* copy the TreeItem userdata so we give it back */
1056 lua_pushvalue(L, 1);
1057
1058 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
1059}
1060
1061/* WSLUA_ATTRIBUTE TreeItem_len RW Set/get <<lua_class_TreeItem,`TreeItem`>>'s length inside tvb, after it has already been created. */
1062static int TreeItem_get_len(lua_State* L) {
1063 TreeItem ti = checkTreeItem(L,1);
1064 int len = 0;
1065
1066 /* XXX - this is *NOT* guaranteed to return a correct value! */
1067 len = proto_item_get_len(ti->item);
1068
1069 lua_pushinteger(L, len > 0 ? len : 0);
1070
1071 return 1;
1072}
1073
1074WSLUA_METHODstatic int TreeItem_set_len(lua_State *L) {
1075 /* Set <<lua_class_TreeItem,`TreeItem`>>'s length inside tvb, after it has already been created.
1076
1077 This used to return nothing, but as of 1.11.3 it returns the same tree item to allow chained calls.
1078 */
1079#define WSLUA_ARG_TreeItem_set_len_LEN2 2 /* The length to be used. */
1080 TreeItem ti = checkTreeItem(L,1);
1081 int len = (int)luaL_checkinteger(L,WSLUA_ARG_TreeItem_set_len_LEN2);
1082
1083 proto_item_set_len(ti->item, len);
1084
1085 /* copy the TreeItem userdata so we give it back */
1086 lua_pushvalue(L, 1);
1087
1088 WSLUA_RETURN(1)return (1); /* The same TreeItem. */
1089}
1090
1091WSLUA_METHODstatic int TreeItem_referenced(lua_State *L) {
1092 /* Checks if a <<lua_class_ProtoField,`ProtoField`>> or <<lua_class_Dissector,`Dissector`>> is referenced by a filter/tap/UI.
1093
1094 If this function returns `false`, it means that the field (or dissector) does not need to be dissected
1095 and can be safely skipped. By skipping a field rather than dissecting it, the dissector will
1096 usually run faster since Wireshark will not do extra dissection work when it doesn't need the field.
1097
1098 You can use this in conjunction with the TreeItem.visible attribute. This function will always return
1099 true when the TreeItem is visible. When it is not visible and the field is not referenced, you can
1100 speed up the dissection by not dissecting the field as it is not needed for display or filtering.
1101
1102 This function takes one parameter that can be a <<lua_class_ProtoField,`ProtoField`>> or <<lua_class_Dissector,`Dissector`>>.
1103 The <<lua_class_Dissector,`Dissector`>> form is useful when you need to decide whether to call a sub-dissector.
1104 */
1105#define WSLUA_ARG_TreeItem_referenced_PROTOFIELD2 2 /* The <<lua_class_ProtoField,`ProtoField`>> or <<lua_class_Dissector,`Dissector`>> to check if referenced. */
1106 TreeItem ti = checkTreeItem(L, 1);
1107 if (!ti) return 0;
1108 ProtoField f = shiftProtoField(L, WSLUA_ARG_TreeItem_referenced_PROTOFIELD2);
1109 if (f) {
1110 lua_pushboolean(L, proto_field_is_referenced(ti->tree, f->hfid));
1111 }
1112 else {
1113 Dissector d = checkDissector(L, WSLUA_ARG_TreeItem_referenced_PROTOFIELD2);
1114 if (!d) return 0;
1115 lua_pushboolean(L, proto_field_is_referenced(ti->tree, dissector_handle_get_protocol_index(d)));
1116 }
1117 WSLUA_RETURN(1)return (1); /* A boolean indicating if the ProtoField/Dissector is referenced */
1118}
1119
1120WSLUA_METAMETHODstatic int TreeItem__tostring(lua_State* L) {
1121 /* Returns string debug information about the <<lua_class_TreeItem,`TreeItem`>>. */
1122 TreeItem ti = toTreeItem(L,1);
1123
1124 if (ti) {
1125 lua_pushfstring(L,
1126 "TreeItem: expired=%s, has item=%s, has subtree=%s, they are %sthe same",
1127 ti->expired ? "true" : "false",
1128 ti->item ? "true" : "false",
1129 ti->tree ? "true" : "false",
1130 (ti->tree == ti->item) ? "" : "not ");
1131 }
1132 else {
1133 lua_pushstring(L, "No TreeItem object!");
1134 }
1135
1136 return 1;
1137}
1138
1139/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
1140static int TreeItem__gc(lua_State* L) {
1141 TreeItem ti = toTreeItem(L,1);
1142 if (!ti) return 0;
1143 if (!ti->expired)
1144 ti->expired = true1;
1145 else
1146 g_free(ti);
1147 return 0;
1148}
1149
1150WSLUA_ATTRIBUTESstatic const wslua_attribute_table TreeItem_attributes[] = {
1151 WSLUA_ATTRIBUTE_RWREG(TreeItem,generated){ "generated", TreeItem_get_generated, TreeItem_set_generated
}
,
1152 WSLUA_ATTRIBUTE_RWREG(TreeItem,hidden){ "hidden", TreeItem_get_hidden, TreeItem_set_hidden },
1153 WSLUA_ATTRIBUTE_RWREG(TreeItem,len){ "len", TreeItem_get_len, TreeItem_set_len },
1154 WSLUA_ATTRIBUTE_RWREG(TreeItem,text){ "text", TreeItem_get_text, TreeItem_set_text },
1155 WSLUA_ATTRIBUTE_ROREG(TreeItem,visible){ "visible", TreeItem_get_visible, ((void*)0) },
1156 { NULL((void*)0), NULL((void*)0), NULL((void*)0) }
1157};
1158
1159WSLUA_METHODSstatic const luaL_Reg TreeItem_methods[] = {
1160 WSLUA_CLASS_FNREG(TreeItem,add_packet_field){ "add_packet_field", TreeItem_add_packet_field },
1161 WSLUA_CLASS_FNREG(TreeItem,add){ "add", TreeItem_add },
1162 WSLUA_CLASS_FNREG(TreeItem,add_le){ "add_le", TreeItem_add_le },
1163 WSLUA_CLASS_FNREG(TreeItem,set_text){ "set_text", TreeItem_set_text },
1164 WSLUA_CLASS_FNREG(TreeItem,append_text){ "append_text", TreeItem_append_text },
1165 WSLUA_CLASS_FNREG(TreeItem,prepend_text){ "prepend_text", TreeItem_prepend_text },
1166 WSLUA_CLASS_FNREG(TreeItem,add_expert_info){ "add_expert_info", TreeItem_add_expert_info },
1167 WSLUA_CLASS_FNREG(TreeItem,add_proto_expert_info){ "add_proto_expert_info", TreeItem_add_proto_expert_info },
1168 WSLUA_CLASS_FNREG(TreeItem,add_tvb_expert_info){ "add_tvb_expert_info", TreeItem_add_tvb_expert_info },
1169 WSLUA_CLASS_FNREG(TreeItem,set_generated){ "set_generated", TreeItem_set_generated },
1170 WSLUA_CLASS_FNREG(TreeItem,set_hidden){ "set_hidden", TreeItem_set_hidden },
1171 WSLUA_CLASS_FNREG(TreeItem,set_len){ "set_len", TreeItem_set_len },
1172 WSLUA_CLASS_FNREG(TreeItem,referenced){ "referenced", TreeItem_referenced },
1173 { NULL((void*)0), NULL((void*)0) }
1174};
1175
1176WSLUA_METAstatic const luaL_Reg TreeItem_meta[] = {
1177 WSLUA_CLASS_MTREG(TreeItem,tostring){ "__" "tostring", TreeItem__tostring },
1178 { NULL((void*)0), NULL((void*)0) }
1179};
1180
1181int TreeItem_register(lua_State *L) {
1182 int* etts[] = { &wslua_ett };
1183 wslua_ett = -1; /* Reset to support reload Lua plugins */
1184 WSLUA_REGISTER_CLASS_WITH_ATTRS(TreeItem){ const wslua_class TreeItem_class = { .name = "TreeItem", .class_methods
= TreeItem_methods, .class_meta = TreeItem_meta, .instance_methods
= TreeItem_methods, .instance_meta = TreeItem_meta, .attrs =
TreeItem_attributes }; wslua_register_class(L, &TreeItem_class
); (lua_getfield(L, (-1000000 - 1000), ("TreeItem"))); lua_pushcclosure
(L, (TreeItem__gc), 0); lua_setfield(L, -2, "__gc"); lua_settop
(L, -(1)-1); }
;
1185 if (outstanding_TreeItem != NULL((void*)0)) {
1186 g_ptr_array_unref(outstanding_TreeItem);
1187 }
1188 outstanding_TreeItem = g_ptr_array_new();
1189 proto_register_subtree_array(etts,1);
1190 return 0;
1191}
1192
1193/*
1194 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1195 *
1196 * Local variables:
1197 * c-basic-offset: 4
1198 * tab-width: 8
1199 * indent-tabs-mode: nil
1200 * End:
1201 *
1202 * vi: set shiftwidth=4 tabstop=8 expandtab:
1203 * :indentSize=4:tabSize=8:noTabs=true:
1204 */