aboutsummaryrefslogtreecommitdiff
path: root/util/wireshark/minetest.lua
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-01-29 16:08:49 +0100
committersfan5 <sfan5@live.de>2021-02-02 20:46:08 +0100
commit9388c23e86e85e507c521b1ac01687f249fd1a0a (patch)
treeec0c3e9b9928e96e14111f075f2d12a1f221fc6e /util/wireshark/minetest.lua
parent674d67f312c815e7f10dc00705e352bc392fc2af (diff)
downloadminetest-9388c23e86e85e507c521b1ac01687f249fd1a0a.tar.gz
minetest-9388c23e86e85e507c521b1ac01687f249fd1a0a.tar.bz2
minetest-9388c23e86e85e507c521b1ac01687f249fd1a0a.zip
Handle UTF-16 correctly in Wireshark dissector
Diffstat (limited to 'util/wireshark/minetest.lua')
-rw-r--r--util/wireshark/minetest.lua33
1 files changed, 2 insertions, 31 deletions
diff --git a/util/wireshark/minetest.lua b/util/wireshark/minetest.lua
index dd0507c3e..d954c7597 100644
--- a/util/wireshark/minetest.lua
+++ b/util/wireshark/minetest.lua
@@ -299,7 +299,7 @@ do
t:add(f_length, buffer(2,2))
local textlen = buffer(2,2):uint()
if minetest_check_length(buffer, 4 + textlen*2, t) then
- t:add(f_message, minetest_convert_utf16(buffer(4, textlen*2), "Converted chat message"))
+ t:add(f_message, buffer(4, textlen*2), buffer(4, textlen*2):ustring())
end
end
}
@@ -1379,35 +1379,6 @@ function minetest_check_length(tvb, min_len, t)
end
end
--- Takes a Tvb or TvbRange (i.e. part of a packet) that
--- contains a UTF-16 string and returns a TvbRange containing
--- string converted to ASCII. Any characters outside the range
--- 0x20 to 0x7e are replaced by a question mark.
--- Parameter: tvb: Tvb or TvbRange that contains the UTF-16 data
--- Parameter: name: will be the name of the newly created Tvb.
--- Returns: New TvbRange containing the ASCII string.
--- TODO: Handle surrogates (should only produce one question mark)
--- TODO: Remove this when Wireshark supports UTF-16 strings natively.
-function minetest_convert_utf16(tvb, name)
- local hex, pos, char
- hex = ""
- for pos = 0, tvb:len() - 2, 2 do
- char = tvb(pos, 2):uint()
- if (char >= 0x20 and char <= 0x7e) or char == 0x0a then
- hex = hex .. string.format(" %02x", char)
- else
- hex = hex .. " 3F"
- end
- end
- if hex == "" then
- -- This is a hack to avoid a failed assertion in tvbuff.c
- -- (function: ensure_contiguous_no_exception)
- return ByteArray.new("00"):tvb(name):range(0,0)
- else
- return ByteArray.new(hex):tvb(name):range()
- end
-end
-
-- Decodes a variable-length string as ASCII text
-- t_textlen, t_text should be the ProtoFields created by minetest_field_helper
-- alternatively t_text can be a ProtoField.string and t_textlen can be nil
@@ -1438,7 +1409,7 @@ function minetest_decode_helper_utf16(tvb, t, lentype, offset, f_textlen, f_text
end
local textlen = tvb(offset, n):uint() * 2
if minetest_check_length(tvb, offset + n + textlen, t) then
- t:add(f_text, minetest_convert_utf16(tvb(offset + n, textlen), "UTF-16 text"))
+ t:add(f_text, tvb(offset + n, textlen), tvb(offset + n, textlen):ustring())
return offset + n + textlen
end
end