Search code examples
utf-8luabase64encodewireshark

How to display UTF-8 data in Lua script for wireshark


I've been trying to represent binary in Japanese decoding by UTF-8, but still haven't figured out how to do it properly. Here is the codes.

vps_proto = Proto("vps", "VPS Packet")
Name_F = ProtoField.string("Name", "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

The results showed in wireshark don't contain proper Japanese characters as seen below,

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

which is supposed to be like

🔻Payload
    Name: 山田太郎...

Could you find out the problems for that? Thank you.


Solution

  • Try replacing these lines:

    Name_F = ProtoField.string("Name", "Name")
    
    local PayloadName = PayloadNameRange:string(ENC_UTF_8)
    

    With these:

    Name_F = ProtoField.string("vps.Name", "Name", base.UNICODE)
    
    local PayloadName = PayloadNameRange:raw()
    

    See also: wireshark lua string:byte() error