如何在Wireshark中使用Lua字段提取器?

我有一个这样的协议:

“数据包”-一系列消息

{Head}{Content}{Head}{Content}...

“Head”-1字节

位1-7:消息长度

第8位:真实消息还是不是

这是一种 UDP 通信,我必须使用第8位来确定是否需要跳过消息。

以下是我的玩具解析器,我面临的问题是如何提取帮助我做决策的布尔值。

TOY_proto = Proto("TOY", "TOY Protocol")

local isSkip = ProtoField.new("Is Skip?", "mytoy.isSkip", ftypes.BOOLEAN, {"Yes", "No"}, 8, 0x01)
local msgLen = ProroField.new("Message Length", "mytoy.msgLen", ftypes.UINT8, nil, base.DEC, 0xFE)

TOY_proto.fields = {isSkip, msgLen}

local isSkip_Field = Field.new("mytoy.isSkip")
local function getIsSkip()
    return isSkip_Field()()
end
local msgLen_Field = Field.new("mytoy.msgLen")
local function getMsgLen()
    return msgLen_Field()()
end

function TOY_proto.dissector(tvbuf, pktinfo, root)
    pktinfo.cols.protocol = "TOY"
    local pktlen = tvbuf:reported_length_remaining()
    local pos = 0

    while pos < pktlen do
        local headTree = tree:add("Head")
        headTree:add_le(isSkip, tvbuf:range(pos,1))
        headTree:add_le(msgLen, tvbuf:range(pos,1))
        if getIsSkip() then
            pos = pos + getMsgLen()
        else
            -- do something else
        end
    end
end
udp_table = DissectorTable.get("udp.port")
udp_table:add(6628, TOY_proto)

问题在于,在第一次循环中,每个变量都做得对,但是在第一次循环之后,getIsSkip()和getMsgLen()返回的值始终没有改变。

点赞