如何将Wireshark解剖器改写为支持长尾词查询的Lua脚本?

2026-04-01 19:171阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计424个文字,预计阅读时间需要2分钟。

如何将Wireshark解剖器改写为支持长尾词查询的Lua脚本?

首先,我完全是个Lua新手,这是我第一次尝试编写Wireshark解码器。我的协议很简单——一个由两个字符组成的字段,后面跟着一个长度较长的字符串。当我通过Lua控制台运行代码时,一切都会按照预期工作。

首先,我完全是Lua的新手,这是我第一次尝试编写wirehark解剖器.

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

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

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

如何将Wireshark解剖器改写为支持长尾词查询的Lua脚本?

Lua Error: [string “C:\Users…\AppData\Roaming\Wireshark…”]: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,buf(0,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,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,buf(0,2)) --let Wireshark do the hard work t:add(f_text,buf(2,len)) --you've already defined their labels etc. end

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

本文共计424个文字,预计阅读时间需要2分钟。

如何将Wireshark解剖器改写为支持长尾词查询的Lua脚本?

首先,我完全是个Lua新手,这是我第一次尝试编写Wireshark解码器。我的协议很简单——一个由两个字符组成的字段,后面跟着一个长度较长的字符串。当我通过Lua控制台运行代码时,一切都会按照预期工作。

首先,我完全是Lua的新手,这是我第一次尝试编写wirehark解剖器.

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

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

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

如何将Wireshark解剖器改写为支持长尾词查询的Lua脚本?

Lua Error: [string “C:\Users…\AppData\Roaming\Wireshark…”]: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,buf(0,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,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,buf(0,2)) --let Wireshark do the hard work t:add(f_text,buf(2,len)) --you've already defined their labels etc. end

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