Wireshark-bugs: [Wireshark-bugs] [Bug 6346] New: Lua: TvbRange missing unicode string method
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6346
Summary: Lua: TvbRange missing unicode string method
Product: Wireshark
Version: 1.7.x (Experimental)
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Low
Component: Extras
AssignedTo: bugzilla-admin@xxxxxxxxxxxxx
ReportedBy: avallee_30@xxxxxxxxxxx
Created an attachment (id=7023)
--> (https://bugs.wireshark.org/bugzilla/attachment.cgi?id=7023)
Sample capture
Build Information:
avallee@ubuntu:~$ ~/usr/bin/wireshark -v
wireshark 1.7.0 (SVN Rev 39010 from /trunk)
Copyright 1998-2011 Gerald Combs <gerald@xxxxxxxxxxxxx> and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiled (64-bit) with GTK+ 2.22.0, with Cairo 1.10.0, with Pango 1.28.2, with
GLib 2.26.1, with libpcap 1.1.1, with libz 1.2.3.4, without POSIX capabilities,
with threads support, without SMI, without c-ares, without ADNS, with Lua 5.1,
without Python, with GnuTLS 2.8.6, with Gcrypt 1.4.5, without Kerberos, with
GeoIP, without PortAudio, without AirPcap.
Running on Linux 2.6.35-30-virtual, with locale en_US.utf8, with libpcap
version
1.1.1, with libz 1.2.3.4, GnuTLS 2.8.6, Gcrypt 1.4.5.
Built using gcc 4.4.5.
--
Trying to read UTF-16 strings from a capture in a lua dissector is either
difficult or we must convert the bytes manually to UTF-8 that Wireshark will
understand.
In this example dissector with the attached pcap
foo = Proto("foo", "FOO")
foo.fields.string = ProtoField.string("foo.s", "name", "desc")
function foo.dissector( buffer, pinfo, tree )
local sub = tree:add(foo, buffer())
local a = buffer(0,22):le_ustring()
sub:add(foo.fields.string, buffer(0,22), a)
end
DissectorTable.get("tcp.port"):add(5707, foo)
I'd expect frame 6 to have the tree item foo.s="name: Hello World"
Proposed patch
Index: epan/wslua/wslua_tvb.c
===================================================================
--- epan/wslua/wslua_tvb.c (revision 39010)
+++ epan/wslua/wslua_tvb.c (working copy)
@@ -1065,6 +1065,31 @@
WSLUA_RETURN(1); /* The string */
}
+static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) {
+ /* Obtain a UTF-16 encoded string from a TvbRange */
+ TvbRange tvbr = checkTvbRange(L,1);
+
+ if ( !(tvbr && tvbr->tvb)) return 0;
+ if (tvbr->tvb->expired) {
+ luaL_error(L,"expired tvb");
+ return 0;
+ }
+
+ lua_pushlstring(L,
(gchar*)tvb_get_ephemeral_unicode_string(tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,
little_endian), tvbr->len );
+
+ return 1; /* The string */
+}
+
+WSLUA_METHOD TvbRange_ustring(lua_State* L) {
+ /* Obtain a Big Endian (network order) UTF-16 encoded string from a
TvbRange */
+ WSLUA_RETURN(TvbRange_ustring_any(L, FALSE)); /* The string */
+}
+
+WSLUA_METHOD TvbRange_le_ustring(lua_State* L) {
+ /* Obtain a Little Endian UTF-16 encoded string from a TvbRange */
+ WSLUA_RETURN(TvbRange_ustring_any(L, TRUE)); /* The string */
+}
+
WSLUA_METHOD TvbRange_stringz(lua_State* L) {
/* Obtain a zero terminated string from a TvbRange */
TvbRange tvbr = checkTvbRange(L,1);
@@ -1234,6 +1259,8 @@
{"len", TvbRange_len},
{"offset", TvbRange_offset},
{"tvb", TvbRange_tvb},
+ {"le_ustring", TvbRange_le_ustring},
+ {"ustring", TvbRange_ustring},
{ NULL, NULL }
};
--
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.