我正在尝试使用Lua脚本在Wireshark中为非以太网数据创建解剖器。例如,我捕获了I2C总线数据,将其转换为.pcap文件格式,可由Wireshark打开。每条记录都有一个字节的地址和几个字节的数据。我如何在Lua中处理这个以解剖数据呢?
答案 0 :(得分:0)
如果您查看packet-i2c.c源文件,您将在第258行看到您需要使用“i2c.message”表注册您的解剖器,类似于它的方式在Wireshark的Q& A网站的How to register a Lua dissector for 802.1Q Ethernet payload问题中描述。所以,在你的情况下,像:
-- Protocol
local p_i2cfoo = Proto("i2cfoo", "I2C FOO Protocol")
-- Fields
local f_i2cfoo_addr = ProtoField.uint8("i2cfoo.addr", "Address", base.DEC)
local f_i2cfoo_val16 = ProtoField.uint16("i2cfoo.val16", "Value 16", base.HEX)
local f_i2cfoo_val32 = ProtoField.uint32("i2cfoo.val32", "Value 32", base.HEX)
p_i2cfoo.fields = { f_i2cfoo_addr, f_i2cfoo_val16, f_i2cfoo_val32 }
-- Dissection
function p_i2cfoo.dissector(buf, pinfo, tree)
local i2cfoo_tree = tree:add(p_i2cfoo, buf(0,-1))
pinfo.cols.protocol:set("I2CFOO")
pinfo.cols.info:set("Hello World!")
i2cfoo_tree:add(f_i2cfoo_addr, buf(0, 1))
i2cfoo_tree:add(f_i2cfoo_val16, buf(1, 2))
i2cfoo_tree:add(f_i2cfoo_val32, buf(3, 4))
end
-- Registration
local i2c_table = DissectorTable.get("i2c.message")
i2c_table:add(0, p_i2cfoo)