Ask Your Question
0

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] = ProtoField.new(...
[0x02] = ProtoField.new(...
[0x03] = ProtoField.new(...
}

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 https://github.com/Silicondust/libhdh...

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
0

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

Lekensteyn gravatar image

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

See https://www.wireshark.org/docs/wsdg_h... 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

Stats

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

Seen: 57 times

Last updated: Feb 16