I’m in the process to implement a WireShark dissector, and I have a technical question (I’m still learning the details of a lua dissector).
In particular I want to add int/float/string items to the dissected subtree based on a variable length array (the length depend on a file loaded from the preferences).
I would like to avoid to create as many ProtoField as there are items in the array (I don’t know the length), the arrays I dissect have a coherent item type, they are either all int or all float or all string.
I don’t see question in stack overflow of how to achieve that.
Assuming a protocol listener pattern, you can simply add to obtain a subtree and then add in a loop the values, for example:
function DecoderListener:setParameter(widgetID, paramID, value)
if (type(value) == "table") then
local array_tree = self.subtree:add(paramID)
if #value >= 1 then
for i, value0 in ipairs(value) do
self:setArrayParameter(array_tree, value0, i)
end
end
end
end
function DecoderListener:setArrayParameter(array_tree, value, index)
local real_value = value:getValue()
-- this can handle int/float/string real values
array_tree:add(real_value)
end
This will result in folding elements in Wireshark with all the values you have speficied.