Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Wireshark-users: Re: [Wireshark-users] Wide char strings in LUA dissector

From: Helge Kruse <Helge.Kruse@xxxxxxx>
Date: Wed, 30 Nov 2016 15:39:24 +0100
Am 29.11.2016 um 04:00 schrieb Guy Harris:
> 
> So you'd either have to fetch the length yourself and use an FT_STRING field, or get FT_UINT_STRING supported in Lua.

Currently I used a workaround and wrote a LUA function that retrieves
the wide char string from the tvb.

-- Get a wide character string from a TVB.
-- Assume the high byte of all 16-bit characters is always zero.
-- If the number of bytes is not know pass -1 to get the remaing
-- bytes of the packet.
function WideCharString(tvb, offset, remaining)
	local s = ""
	if remaining == -1 then
		remaining = tvb:reported_length_remaining()
	end
	while (offset < remaining) do
		local c = tvb:range(offset, 1):string()
		if c == "" then return s end
		s = s .. c -- string.format("%s", c)
		offset = offset + 2
	end
	return s
end

If I add this to a tree then I get the correct name:
	local rem = tvb:reported_length_remaining()
	local name = WideCharString(tvb, 8, rem - 8)
	tree:add("WName:", tvb:range(8, rem - 8), name)

But although the range is addressed with "tvb:range(8, rem - 8)" the
bytes in the packet panes are not highlighted for this tree item.

So, I fear it would be better to get FT_UINT_STRING in LUA supported.

Regards
Helge