Lua 中的链式解剖器

Chained Dissector in Lua

我正在 Lua 中为 Ethercat 协议编写链式解析器。我将我的链式解剖器命名为小猫。

到目前为止,littlecat 正确地剖析了我想要的字段。然而,littlecat 并没有在内置的 ecat 解析器之后执行,而是完全接管了它。

这就是我的 Lua 代码末尾的注册内容。

-- Initialize Protocol
function littlecat.init()
end

-- Register Chained Dissector Ethercat Port
local ethercat_dissector_table = DissectorTable.get("ecatf.type")
dissector = ethercat_dissector_table:get_dissector(1)

 -- Dissector can be called from littlecat.dissector
 -- So the previous dissector gets called      
 ethercat_dissector_table:add(1, littlecat)

如何在执行 ecat 后执行解析器?

我找到了解决办法。

确保调用默认解析器,然后调用自定义解析器:

  1. 在解剖函数之前定义解剖器table和原始解剖器。
  2. 在解剖函数中调用原始解剖器。

例子

-- Initialize Protocol 
-- Initialize Protocol Fields

-- Define dissector table and default dissector here
-- so they can be called within the dissection func.

local dissector_table = DissectorTable.get("shortname")
dissector = dissector_table:get_dissector(PORT)

 -- Dissection Function
 function dissectorname.dissector (tvbuf, pktinfo, root)

    -- Call default dissector.
    dissector(tvbuf, pktinfo, root)

    -- Continue dissection....

end

-- Initialize Protocol
function dissectorname.init()
end

-- Dissector can be called from dissectorname.dissector
-- So the previous dissector gets called      
dissector_table:add(PORT, dissectorname)