如何添加到Lua DissectorTable?

时间:2018-07-11 13:50:30

标签: lua wireshark wireshark-dissector

我正在为Wireshark编写一个Lua解剖器,用于复杂的协议。该协议具有包含msgType字段的消息头。我想为每种消息类型编写一个子分解器,每个子分解器存储在单独的源文件中。

我的顶级脚本是general.lua,它解剖消息头并创建解剖器表:

DissectorTable.new("myProtocol.Message")
dofile(DATA_DIR.."cplane.lua")

cplane.lua是消息类型'cplane'的子分解器,并包含以下代码:

my_dissector_table = DissectorTable.get("myProtocol.Message")
my_dissector_table:add(0x02, myProtocol_cplane_proto)

这两个脚本都在Wireshark的插件目录的同一子目录中。

加载插件时出现错误:

Lua: Error during loading:
 [string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:9: bad argument 
#1 to 'get' (DissectorTable_get: no such dissector_table)

Lua: Error during loading:
 [string "C:\Program Files (x86)\Wireshark\plugins\2.4...."]:170: bad 
argument #1 to 'dofile' (dofile: file does not exist)

我该如何解决?问题与脚本的加载顺序有关吗?是否需要dofile()调用?

2 个答案:

答案 0 :(得分:1)

由于插件目录中的所有脚本均已加载,因此不必使用dofile。但是,加载顺序不是固定的(至少没有记录为固定的)。目前,Lua插件是在其他解剖器之后加载的,因此尝试在“全局范围”中查找解剖器表仅适用于内置解剖器,例如tcp.port

local myproto = Proto("myproto", "My Protocol")
function myproto.dissector(tvb, pinfo, tree)
    ...
end
-- Register with a built-in dissector table
DissectorTable.get("tcp.port"):add(1234, myproto)

要使用自定义解剖器表进行注册,必须推迟此注册。在C解剖器中,您可以将注册放入proto_reg_handoff_PROTOABBREV(其中PROTOABBREV应该相应地替换),但是在Lua中则没有这样的功能。

您可以得到的最接近的是“ init”例程(Proto类的属性,proto.init)。在剖析任何数据包之前,打开捕获文件时将调用这些方法。示例:

function myproto.init()
    DissectorTable.get("your-custom-table"):add(1234, myproto)
end

答案 1 :(得分:0)

  1. Lua: Error during loading:  [string "C:\Program Files
        (x86)\Wireshark\plugins\2.4...."]:9: bad argument 
        #1 to 'get' (DissectorTable_get: no such dissector_table)
    

答案:此错误意味着找不到Dissector表。原因可能是路径不正确或文件执行的顺序。

  1. Lua: Error during loading:  [string "C:\Program Files
        (x86)\Wireshark\plugins\2.4...."]:170: bad  argument #1 to 'dofile'
        (dofile: file does not exist)
    

答案:对我来说,输入完全正确的路径可以消除此错误

相关问题