加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Lua的Wireshark解剖器

发布时间:2020-12-15 00:25:40 所属栏目:大数据 来源:网络整理
导读:首先,我完全是Lua的新手,这是我第一次尝试编写wirehark解剖器. 我的协议很简单 – 一个2字节长的字段,后跟一个长度的字符串. 当我通过Lua控制台运行代码时,一切都按预期工作. 当代码添加到Wireshark插件目录时,我收到错误 Lua Error: [string “C:Users…A
首先,我完全是Lua的新手,这是我第一次尝试编写wirehark解剖器.

我的协议很简单 – 一个2字节长的字段,后跟一个长度的字符串.

当我通过Lua控制台运行代码时,一切都按预期工作.

当代码添加到Wireshark插件目录时,我收到错误

Lua Error: [string “C:Users…AppDataRoamingWireshark…”]:15: calling ‘add’ on bad self (number expected,got string)

第15行对应的是t:add(f_text … line.

任何人都可以解释执行方法之间的差异吗?

do
    local p_multi = Proto("aggregator","Aggregator");

    local f_len = ProtoField.int16("aggregator.length","Length",base.DEC)
    local f_text = ProtoField.string("aggregator.text","Text")

    p_multi.fields = { f_len,f_text }

    local data_dis = Dissector.get("data")

    function p_multi.dissector(buf,pkt,root)
            pkt.cols.protocol = "Aggregator"
            local len = buf(0,2):int()
            local t = root:add(p_multi,buf(0,len+2))
            t:add(f_len,2),"Length: " .. buf(0,2):int())
            t:add(f_text,buf(2,len),"Text: " .. buf(2,len):string())
    end

    local tcp_encap_table = DissectorTable.get("tcp.port")
    tcp_encap_table:add(4321,p_multi)
end

解决方法

您的解剖器代码非常接近正确,但您正在做额外的工作,接口不接受.如果您改变解剖器功能,
function p_multi.dissector(buf,root)
        pkt.cols.protocol = "Aggregator"
        local len = buf(0,2):int()
        local t = root:add(p_multi,len+2))
        t:add(f_len,2)) --let Wireshark do the hard work
        t:add(f_text,len)) --you've already defined their labels etc.
end

你会得到理想的行为.已经为您的字段定义了“文本”和“长度”标签,因此无需在第15行和第16行再次提供它们.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读