aboutsummaryrefslogtreecommitdiffstats
path: root/epan/wslua/wslua_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/wslua/wslua_tree.c')
-rw-r--r--epan/wslua/wslua_tree.c226
1 files changed, 203 insertions, 23 deletions
diff --git a/epan/wslua/wslua_tree.c b/epan/wslua/wslua_tree.c
index 221e7e8066..927e6da798 100644
--- a/epan/wslua/wslua_tree.c
+++ b/epan/wslua/wslua_tree.c
@@ -53,16 +53,16 @@ TreeItem create_TreeItem(proto_tree* tree, proto_item* item)
CLEAR_OUTSTANDING(TreeItem, expired, TRUE)
WSLUA_CLASS_DEFINE(TreeItem,FAIL_ON_NULL_OR_EXPIRED("TreeItem"));
-/* <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.
+/* <<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.
A <<lua_class_TreeItem,`TreeItem`>> represents a node in the tree, which might also be a subtree and have a list of children.
The children of a subtree have zero or more siblings which are other children of the same <<lua_class_TreeItem,`TreeItem`>> subtree.
- During dissection, heuristic-dissection, and post-dissection, a root <lua_class_TreeItem,`TreeItem`>> is passed to dissectors as the third argument of the function
+ During dissection, heuristic-dissection, and post-dissection, a root <<lua_class_TreeItem,`TreeItem`>> is passed to dissectors as the third argument of the function
callback (e.g., `myproto.dissector(tvbuf,pktinfo,root)`).
In some cases the tree is not truly added to, in order to improve performance.
For example for packets not currently displayed/selected in Wireshark's visible
- window pane, or if Tshark isn't invoked with the `-V` switch. However the
+ window pane, or if TShark isn't invoked with the `-V` switch. However the
"add" type <<lua_class_TreeItem,`TreeItem`>> functions can still be called, and still return <<lua_class_TreeItem,`TreeItem`>>
objects - but the info isn't really added to the tree. Therefore you do not
typically need to worry about whether there's a real tree or not. If, for some
@@ -76,7 +76,7 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int
const ftenum_t type, const guint encoding, gint *ret_err)
{
gint err = 0;
- proto_item* item = NULL;
+ proto_item *volatile item = NULL;
gint endoff = 0;
switch(type) {
@@ -114,10 +114,162 @@ try_add_packet_field(lua_State *L, TreeItem tree_item, TvbRange tvbr, const int
}
break;
- /* XXX: what about these? */
- case FT_NONE:
- case FT_PROTOCOL:
- /* anything else just needs to be done the old fashioned way */
+ case FT_INT8:
+ case FT_INT16:
+ case FT_INT24:
+ case FT_INT32:
+ {
+ gint32 ret;
+ item = proto_tree_add_item_ret_int(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ lua_pushnumber(L, (lua_Number)ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_INT40:
+ case FT_INT48:
+ case FT_INT56:
+ case FT_INT64:
+ {
+ gint64 ret;
+ item = proto_tree_add_item_ret_int64(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ pushInt64(L, ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_CHAR:
+ case FT_UINT8:
+ case FT_UINT16:
+ case FT_UINT24:
+ case FT_UINT32:
+ {
+ guint32 ret;
+ item = proto_tree_add_item_ret_uint(tree_item-> tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ lua_pushnumber(L, (lua_Number)ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_UINT40:
+ case FT_UINT48:
+ case FT_UINT56:
+ case FT_UINT64:
+ {
+ guint64 ret;
+ item = proto_tree_add_item_ret_uint64(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ pushUInt64(L, ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_BOOLEAN:
+ {
+ gboolean ret;
+ item = proto_tree_add_item_ret_boolean(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ lua_pushboolean(L, ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_STRING:
+ {
+ const guint8 *ret;
+ gint len;
+ item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ NULL, &ret, &len);
+ lua_pushstring(L, ret);
+ lua_pushinteger(L, tvbr->offset + len);
+ wmem_free(NULL, (void*)ret);
+ }
+ break;
+
+ case FT_STRINGZ:
+ {
+ const guint8 *ret;
+ gint len;
+ item = proto_tree_add_item_ret_string_and_length(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, -1, encoding,
+ NULL, &ret, &len);
+ lua_pushstring(L, ret);
+ lua_pushinteger(L, tvbr->offset + len);
+ wmem_free(NULL, (void*)ret);
+ }
+ break;
+
+ case FT_FLOAT:
+ {
+ gfloat ret;
+ item = proto_tree_add_item_ret_float(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ lua_pushnumber(L, (lua_Number)ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_DOUBLE:
+ {
+ gdouble ret;
+ item = proto_tree_add_item_ret_double(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ lua_pushnumber(L, (lua_Number)ret);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_IPv4:
+ {
+ Address addr = g_new(address,1);
+ ws_in4_addr ret;
+ item = proto_tree_add_item_ret_ipv4(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ alloc_address_wmem(NULL, addr, AT_IPv4, sizeof(ret), &ret);
+ pushAddress(L, addr);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_IPv6:
+ {
+ Address addr = g_new(address, 1);
+ ws_in6_addr ret;
+ item = proto_tree_add_item_ret_ipv6(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ &ret);
+ alloc_address_wmem(NULL, addr, AT_IPv6, sizeof(ret), &ret);
+ pushAddress(L, addr);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
+ case FT_ETHER:
+ {
+ Address addr = g_new(address, 1);
+ guint8 bytes[FT_ETHER_LEN];
+
+ item = proto_tree_add_item_ret_ether(tree_item->tree, hfid, tvbr->tvb->ws_tvb,
+ tvbr->offset, tvbr->len, encoding,
+ bytes);
+ alloc_address_wmem(NULL, addr, AT_ETHER, sizeof(bytes), bytes);
+ pushAddress(L, addr);
+ lua_pushinteger(L, tvbr->offset + tvbr->len);
+ }
+ break;
+
default:
item = proto_tree_add_item(tree_item->tree, hfid, tvbr->tvb->ws_tvb, tvbr->offset, tvbr->len, encoding);
lua_pushnil(L);
@@ -158,20 +310,21 @@ WSLUA_METHOD TreeItem_add_packet_field(lua_State *L) {
In Wireshark version 1.11.3, this function was changed to return more than
just the new child <<lua_class_TreeItem,`TreeItem`>>. The child is the first return value, so that
- function chaining will still work as before; but it now also returns the value
- of the extracted field (i.e., a number, `UInt64`, `Address`, etc.). If the
- value could not be extracted from the `TvbRange`, the child <<lua_class_TreeItem,`TreeItem`>> is still
- returned, but the second returned value is `nil`.
+ function chaining will still work as before; but it now also returns more information.
+ The second return is the value of the extracted field (i.e., a number, `UInt64`, `Address`, etc.).
+ The third return is is the offset where data should be read next. This is useful when the length of the
+ field is not known in advance. The additional return values may be null if the field type
+ is not well supported in the Lua API.
Another new feature added to this function in Wireshark version 1.11.3 is the
- ability to extract native number `ProtoField`s from string encoding in the
+ ability to extract native number `ProtoField`++s++ from string encoding in the
`TvbRange`, for ASCII-based and similar string encodings. For example, a
- <<lua_class_ProtoField,`ProtoField`>> of as `ftypes.UINT32` type can be extracted from a `TvbRange`
+ <<lua_class_ProtoField,`ProtoField`>> of type `ftypes.UINT32` can be extracted from a `TvbRange`
containing the ASCII string "123", and it will correctly decode the ASCII to
the number `123`, both in the tree as well as for the second return value of
this function. To do so, you must set the `encoding` argument of this function
to the appropriate string `ENC_*` value, bitwise-or'd with the `ENC_STRING`
- value (see `init.lua`). `ENC_STRING` is guaranteed to be a unique bit flag, and
+ value. `ENC_STRING` is guaranteed to be a unique bit flag, and
thus it can added instead of bitwise-or'ed as well. Only single-byte ASCII digit
string encoding types can be used for this, such as `ENC_ASCII` and `ENC_UTF_8`.
@@ -354,11 +507,21 @@ static int TreeItem_add_item_any(lua_State *L, gboolean little_endian) {
break;
case FT_BOOLEAN:
{
- /* this needs to use checkinteger so that it can accept a Lua boolean and coerce it to an int */
- guint32 val = (guint32) (wslua_tointeger(L,1));
+ uint64_t val;
+ switch(lua_type(L, 1)) {
+
+ case LUA_TUSERDATA:
+ val = checkUInt64(L, 1);
+ break;
+
+ default:
+ /* this needs to use checkinteger so that it can accept a Lua boolean and coerce it to an int */
+ val = (uint64_t) (wslua_tointeger(L,1));
+ }
item = proto_tree_add_boolean(tree_item->tree,hfid,tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,val);
}
break;
+ case FT_CHAR:
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
@@ -678,12 +841,29 @@ WSLUA_METHOD TreeItem_add_expert_info(lua_State *L) {
be used in new Lua code. It may be removed in the future. You should only
use `TreeItem.add_proto_expert_info()`.
*/
-#define WSLUA_OPTARG_TreeItem_add_expert_info_GROUP 2 /* One of `PI_CHECKSUM`, `PI_SEQUENCE`,
- `PI_RESPONSE_CODE`, `PI_REQUEST_CODE`,
- `PI_UNDECODED`, `PI_REASSEMBLE`,
- `PI_MALFORMED` or `PI_DEBUG`. */
-#define WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY 3 /* One of `PI_CHAT`, `PI_NOTE`,
- `PI_WARN`, or `PI_ERROR`. */
+#define WSLUA_OPTARG_TreeItem_add_expert_info_GROUP 2 /* One of:
+ `PI_CHECKSUM`,
+ `PI_SEQUENCE`,
+ `PI_RESPONSE_CODE`,
+ `PI_REQUEST_CODE`,
+ `PI_UNDECODED`,
+ `PI_REASSEMBLE`,
+ `PI_MALFORMED`,
+ `PI_DEBUG`,
+ `PI_PROTOCOL`,
+ `PI_SECURITY`,
+ `PI_COMMENTS_GROUP`,
+ `PI_DECRYPTION`,
+ `PI_ASSUMPTION`,
+ `PI_DEPRECATED`,
+ `PI_RECEIVE`,
+ or `PI_INTERFACE`. */
+#define WSLUA_OPTARG_TreeItem_add_expert_info_SEVERITY 3 /* One of:
+ `PI_COMMENT`,
+ `PI_CHAT`,
+ `PI_NOTE`,
+ `PI_WARN`,
+ or `PI_ERROR`. */
#define WSLUA_OPTARG_TreeItem_add_expert_info_TEXT 4 /* The text for the expert info display. */
TreeItem ti = checkTreeItem(L,1);
int group = (int)luaL_optinteger(L,WSLUA_OPTARG_TreeItem_add_expert_info_GROUP,PI_DEBUG);