如何在 Wireshark 的 Lua 脚本中显示 UTF-8 数据

我一直试图用 UTF-8 编码表示二进制的日文解码,但仍然没有找出如何正确地做到这一点。这里是代码。

vps_proto = Proto("vps", "VPS Packet")
Name_F = ProtoField.string("Name", "名称")
vps_proto.fields = {Name_F}

function RequestAccountPayloadParse(decoded_buf, pinfo, subtree)
    local PayloadNameRange = decoded_buf(0, 20)
    local PayloadName = PayloadNameRange:string(ENC_UTF_8)

    local payloadPacTree = subtree:add(decoded_buf(), pinfo, subtree)
    payloadPacTree:set_text("Payload")

    payloadPacTree:set_text:add(Name_F, PayloadNameRange, PayloadName)
end

在 wireshark 中显示的结果不包含正确的日文字,如下所示,

Payload
    Name: \350\213\227\...

应该是这样的

Payload
    Name: 山田太郎...

你能找出问题吗?谢谢。

原文链接 https://stackoverflow.com/questions/71167868

点赞
stackoverflow用户2755698
stackoverflow用户2755698

尝试将这些行替换为:

Name_F = ProtoField.string("vps.Name", "Name", base.UNICODE)

local PayloadName = PayloadNameRange:raw()

另请参见:wireshark lua string:byte() error

2022-02-18 19:09:05