Wireshark lua 脚本来剖析 CoAP 选项

Wireshark lua scripting to dissect CoAP option

我正在编写 lua 脚本来剖析 coap 协议。但是,如果有几个相同的选项,我无法获得第二个或更高版本的 coap 选项(URI-Path)。

do
 local test_proto = Proto("test_proto", "Test Protocol")
 local test_uripath = ProtoField.string("test.uripath", "Uri-Path")
 test_proto.fields = {test_uripath}
 local coap_uripath = Field.new("coap.opt.uri_path")
 function test_proto.dissector(tvbuffer, pinfo, treeitem)
  local subtree = treeitem:add(test_proto)
  subtree:add(test_uripath, tostring(coap_uripath().value))
 end
register_postdissector(test_proto)
end

即使 coap URI-Path 选项具有如下几个值,也只会在子树中显示第一个 URI-Path。

Opt Name: #1: URI-Path: XXX
Opt Name: #2: URI-Path: YYY

我只能通过coap.opt.uri_path获得XXX。我怎样才能获得第二个或以后相同的选项字段?

如果您对所有字段都感兴趣而不仅仅是第一个字段,那么您将需要处理整个 table。例如:

do
    local test_proto = Proto("test_proto", "Test Protocol")
    local test_uripath = ProtoField.string("test.uripath", "Uri-Path")
    test_proto.fields = {test_uripath}

    local coap_uripath = Field.new("coap.opt.uri_path")

    function test_proto.dissector(tvbuffer, pinfo, treeitem)
        local subtree = treeitem:add(test_proto)
        local coap_uripath_table = { coap_uripath() }

        for i,uripath in ipairs(coap_uripath_table) do
            subtree:add(test_uripath, tostring(uripath.value))
        end
    end

    register_postdissector(test_proto)
end

另请参阅:
https://osqa-ask.wireshark.org/questions/35682/lua-accessing-multiple-smb2msg_id-values
https://osqa-ask.wireshark.org/questions/1579/fetching-multiple-named-values-with-lua