From 98c04ca24cc7d943b5fe2537a980c0b329117534 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 7 Nov 2017 14:30:27 +0000 Subject: lua/trivial: add some more comments And remove the unnecessary nothing() function, it was there to test a crash issue. --- lua/trivial.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/lua/trivial.lua b/lua/trivial.lua index abcb5e6..3c775c0 100644 --- a/lua/trivial.lua +++ b/lua/trivial.lua @@ -1,23 +1,39 @@ -- trivial protocol example -- declare our protocol -trivial_proto = Proto("trivial", "Trivial Protocol") +local trivial_proto = Proto("trivial", "Trivial Protocol") -function dissect_foo(tvb, pinfo, tree) - nothing(); - local subtree = tree:add(trivial_proto, tvb(),"Trivial Protocol Data") +-- Will be called below in trivial_proto.dissector +local function dissect_foo(tvb, pinfo, tree) + -- Add an additional "layer" (think of IP, TCP, etc.) + local subtree = tree:add(trivial_proto, tvb(), "Trivial Protocol Data") + + -- To that layer, add a field that highlights the last two bytes of the + -- buffer ("tvb") and add the textual label "Len: " followed by the length + -- extracted from the tvb. subtree:add(tvb(3,2), "Len: " .. tvb(3,2):uint()) end -function get_pdu_len(tvb, pinfo, tree) +-- Will be used in trivial_proto.dissector +local function get_pdu_len(tvb, pinfo, tree) + -- Extract 2 bytes from offset 3 (so the last two bytes of a five-byte + -- buffer). This will be the length of the full PDU. return tvb(3, 2):uint() end function trivial_proto.dissector(tvb, pinfo, tree) + -- Change the "Protocol" column pinfo.cols.protocol = "TRIVIAL" + + -- Try to call the "dissect_foo" dissector for each PDU ("message"). The + -- PDU is expected to have a header of five bytes and the actual length is + -- returned by "get_pdu_len". dissect_tcp_pdus(tvb, tree, 5, get_pdu_len, dissect_foo) end - -tcp_table = DissectorTable.get("tcp.port") +-- Ensure that the dissector is called for TCP port numbers 7777 and 443. +local tcp_table = DissectorTable.get("tcp.port") tcp_table:add(7777, trivial_proto) tcp_table:add(443, trivial_proto) + +-- For another example, see +-- https://www.wireshark.org/docs/wsdg_html_chunked/wslua_dissector_example.html -- cgit v1.2.1