This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

using treeitem:set_generated() in a LUA script

0

Hello,

I have a basic lua dissector where data from the packet is being displayed properly in a tree view. I am trying to display some calculated values based on the data in the protocol; however, none of the data is being displayed as documented.

Question: Has anybody successfully used the treeitem:set_generated() function as documented in the lua API?

Here's the basic construct that I am using:

local ABCD = Proto("ABCD") local ABCDFields = ABCD.fields

ABCDFields.f1 = ProtoField.uint32("ABCD.f1") -- data extracted from packet ABCDFields.f2 = ProtoField.uint32("ABCD.f2") -- data extracted from packet ABCDFields.f3 = ProtoField.double("ABCD.f3") -- calculated based on f1 and f2

function ABCD.dissector(buffer, pinfo, tree) local maxLen = buffer:len() local start = maxLen - 15 local f1 = tonumber('0x'..buffer:range(start, 4), 16) local f2 = tonumber('0x'..buffer:range(start+4, 4), 16) local f3 = <do some="" math="" on="" f1="" and="" f2="">

local subtree = tree:add(ABCD, buffer()) subtree:add(ABCDFields.f1, f1) -- displays properly subtree:add(ABCDFields.f2, f2) -- displays properly subtree:add(ABCDFields.f3, f3) -- displays f3 subtree:set_generated() -- if this is added, then I would expect f3 to be displayed in brackets; however, this has no impact

end

...

asked 07 Jun '11, 09:30

mrai's gravatar image

mrai
1112
accept rate: 0%


One Answer:

1

The problem is you're calling set_generated() on the root tree node when you actually want to call it on a child node (i.e., the tree node for f3).

Change the last two lines from:

subtree:add(ABCDFields.f3, f3) -- displays f3
subtree:set_generated() -- if this is added, then I would expect f3 to be displayed in brackets; however, this has no impact

to:

subtree:add(ABCDFields.f3, f3):set_generated() -- displays f3 (generated)

answered 07 Jun '11, 09:42

bstn's gravatar image

bstn
3751415
accept rate: 14%