Enable Decode As for custom Lua dissector payload
I have a custom dissector written in Lua. One of the fields in my protocol is a payload which may be possible to analyze with a secondary dissector. I would like the user to be able to choose the secondary dissector in the Decode As dialog.
local proto = Proto("myproto", "My Protocol")
proto.fields.payload = ProtoField.bytes("myproto.payload", "Payload")
My understanding is that I need to create and use a DissectorTable
:
local dissector_table = DissectorTable.new(
"myproto.payload",
nil, -- use default description
ftypes.NONE
)
function proto.dissector(tvb, pinfo, tree)
-- Dispatch payload to sub-dissector
local dissector = dissector_table:get_dissector()
if dissector then
dissector:call(tvb:range(0), pinfo, tree)
end
end
Then, in the second dissector, I write:
local proto2 = Proto("my2ndproto", "My 2nd Protocol")
...
pcall(require, "myproto") -- make sure we load second
local dt = DissectorTable.get("myproto.payload")
if dt then
dt:add_for_decode_as(proto2)
end
This gets me to the point where I can set up a rule in the Decode As dialog, to dissect myproto.payload
with MY2NDPROTO
.
However, dissector_table:get_dissector()
always returns nil
.