|
299 | 299 | t:add(f_length, buffer(2,2))
|
300 | 300 | local textlen = buffer(2,2):uint()
|
301 | 301 | if minetest_check_length(buffer, 4 + textlen*2, t) then
|
302 |
| - t:add(f_message, minetest_convert_utf16(buffer(4, textlen*2), "Converted chat message")) |
| 302 | + t:add(f_message, buffer(4, textlen*2), buffer(4, textlen*2):ustring()) |
303 | 303 | end
|
304 | 304 | end
|
305 | 305 | }
|
@@ -1379,35 +1379,6 @@ function minetest_check_length(tvb, min_len, t)
|
1379 | 1379 | end
|
1380 | 1380 | end
|
1381 | 1381 |
|
1382 |
| --- Takes a Tvb or TvbRange (i.e. part of a packet) that |
1383 |
| --- contains a UTF-16 string and returns a TvbRange containing |
1384 |
| --- string converted to ASCII. Any characters outside the range |
1385 |
| --- 0x20 to 0x7e are replaced by a question mark. |
1386 |
| --- Parameter: tvb: Tvb or TvbRange that contains the UTF-16 data |
1387 |
| --- Parameter: name: will be the name of the newly created Tvb. |
1388 |
| --- Returns: New TvbRange containing the ASCII string. |
1389 |
| --- TODO: Handle surrogates (should only produce one question mark) |
1390 |
| --- TODO: Remove this when Wireshark supports UTF-16 strings natively. |
1391 |
| -function minetest_convert_utf16(tvb, name) |
1392 |
| - local hex, pos, char |
1393 |
| - hex = "" |
1394 |
| - for pos = 0, tvb:len() - 2, 2 do |
1395 |
| - char = tvb(pos, 2):uint() |
1396 |
| - if (char >= 0x20 and char <= 0x7e) or char == 0x0a then |
1397 |
| - hex = hex .. string.format(" %02x", char) |
1398 |
| - else |
1399 |
| - hex = hex .. " 3F" |
1400 |
| - end |
1401 |
| - end |
1402 |
| - if hex == "" then |
1403 |
| - -- This is a hack to avoid a failed assertion in tvbuff.c |
1404 |
| - -- (function: ensure_contiguous_no_exception) |
1405 |
| - return ByteArray.new("00"):tvb(name):range(0,0) |
1406 |
| - else |
1407 |
| - return ByteArray.new(hex):tvb(name):range() |
1408 |
| - end |
1409 |
| -end |
1410 |
| - |
1411 | 1382 | -- Decodes a variable-length string as ASCII text
|
1412 | 1383 | -- t_textlen, t_text should be the ProtoFields created by minetest_field_helper
|
1413 | 1384 | -- 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
|
1438 | 1409 | end
|
1439 | 1410 | local textlen = tvb(offset, n):uint() * 2
|
1440 | 1411 | if minetest_check_length(tvb, offset + n + textlen, t) then
|
1441 |
| - t:add(f_text, minetest_convert_utf16(tvb(offset + n, textlen), "UTF-16 text")) |
| 1412 | + t:add(f_text, tvb(offset + n, textlen), tvb(offset + n, textlen):ustring()) |
1442 | 1413 | return offset + n + textlen
|
1443 | 1414 | end
|
1444 | 1415 | end
|
0 commit comments