如何向 Lua DissectorTable 中添加内容?

我正在为 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() 调用是必需的吗?

点赞
用户427545
用户427545

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

local myproto = Proto("myproto", "My Protocol")
function myproto.dissector(tvb, pinfo, tree)
    ...
end
-- 注册内置解剖表
DissectorTable.get("tcp.port"):add(1234, myproto)

要在自定义解剖器表中注册,必须推迟此注册。在C解剖器中,您将在proto_reg_handoff_PROTOABBREV(其中PROTOABBREV应相应地替换)中放置注册,但是在Lua中没有这样的函数。

您可以获得的最接近的是“init”例程(proto.init的属性,proto.init)。这些在打开捕获文件之前(在分解任何数据包之前)调用。例如:

function myproto.init()
    DissectorTable.get("your-custom-table"):add(1234, myproto)
end
2018-07-11 16:57:01
用户10716389
用户10716389

, or checking if the file really exists or not.

2019-06-24 13:40:23