首先,我完全是Lua的新手,这是我第一次尝试编写wirehark解剖器. 我的协议很简单 – 一个2字节长的字段,后跟一个长度的字符串. 当我通过Lua控制台运行代码时,一切都按预期工作. 当代码添
我的协议很简单 – 一个2字节长的字段,后跟一个长度的字符串.
当我通过Lua控制台运行代码时,一切都按预期工作.
当代码添加到Wireshark插件目录时,我收到错误
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行再次提供它们.
