Ask Your Question

Lua dissector, loop vs table, what is supported?

asked 2020-02-15 15:36:56 +0000

voltagex gravatar image

I've got a dissector with a loop that looks something like

 while i < payload_length do
    local tag_type=payload(i,1):uint()

    --Device Type
    if tag_type == 1 then
        tags_tree:add(hdhomerun_proto.fields.tag_device_type, payload(i+2,tag_length))   

    --Device ID
    elseif tag_type == 2 then
        tags_tree:add(hdhomerun_proto.fields.tag_device_id, payload(i+2,tag_length))


local hdhr_tag_types = {
[0x01] =
[0x02] =
[0x03] =

and then have tags_tree:add(hdhr_tag_types[tag_type]) or something similar (where tags_tree is a subtree)

When I tried something like that it seemed like having a ProtoField in a table isn't supported.

For reference, the protocol I'm looking at is in

What's supported? Is a loop with an if else statement for all 13 tags really the best way to make this work?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-02-16 18:04:32 +0000

Lekensteyn gravatar image

The result of should be added to the fields property of a Proto instance. This allows them to be registered with a dissector.

See for an example. If you have no other fields, you could use your_proto.fields = hdr_tag_types.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-02-15 15:36:56 +0000

Seen: 644 times

Last updated: Feb 16 '20