I just started with lua plugins in wireshark. I wanted to know if it is possible to create like a global object that can be called by dissector in one packet and used by dissector called by another packet.
Certainly lua has globals which are accessible from different dissectors of a different packet.
Following is a trivial dissector based on that in https://wiki.wireshark.org/Lua/Dissectors, with the addition of a variable counter, which is local to the file and global to the dissector:
-- test with tshark -r CAP1 -n -X lua_script:filename.lua -V local counter = 0; triviala_proto = Proto("triviala", "Trivial Protocol A") function triviala_proto.dissector(buffer, pinfo, tree) pinfo.cols.protocol = "TRIVIALA" local subtree = tree:add(triviala_proto, buffer(), "Trivial") subtree:add(buffer(0, 2), "++" .. counter .. "/" .. buffer(0, 2):uint()) counter = counter + 1; end udp_table = DissectorTable.get("udp.port") udp_table:add(7777, triviala_proto)
The global is available to other dissectors in the same file (easily tested: just make a matching "trivialb_proto" on port 8888).