Скриптинг Wireshark lua для анализа опции CoAP - PullRequest
0 голосов
/ 12 июня 2019

Я пишу сценарий lua для анализа протокола coap. Однако я не могу получить параметры coap (URI-Path) 2-го или более поздних версий, если есть несколько одинаковых параметров.

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

Только первый URI-путь отображается на поддереве, даже если параметр coap URI-Path имеет несколько значений, подобных следующему.

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

Я могу получить XXX только с помощью coap.opt.uri_path . Как я могу получить 2-е или более поздние поля с такими же параметрами?

1 Ответ

0 голосов
/ 13 июня 2019

Если вас интересуют все поля, а не только первое, вам нужно обработать всю таблицу.Например:

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-множественный-smb2msg_id-values ​​
https://osqa -ask.wireshark.org / questions / 1579 / fetching-multiple-named-values-with-lua

...