Add new string_enc and stringz_enc methods that take an encoding value
as an argument, just as the add_packet_field method for a tree does. Use tvb_get_string_enc() and tvb_get_stringz_enc() rather than tvb_get_string(), tvb_get_stringz(), tvb_get_unicode_string(), and tvb_get_unicode_stringz(). Treat "ustring" as meaning "UTF-16-encoded Unicode string" rather than "UCS-2-encoded subset-of-Unicode string". svn path=/trunk/; revision=54310
This commit is contained in:
parent
7838eada54
commit
0f86a86f47
|
@ -1120,6 +1120,22 @@ WSLUA_METHOD TvbRange_le_nstime(lua_State* L) {
|
|||
WSLUA_RETURN(1); /* The NSTime */
|
||||
}
|
||||
|
||||
WSLUA_METHOD TvbRange_string_enc(lua_State* L) {
|
||||
/* Obtain a string from a TvbRange, using a specified encoding */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
guint encoding = (guint)luaL_checknumber(L,2);
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
luaL_error(L,"expired tvb");
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_pushlstring(L, (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,encoding), tvbr->len);
|
||||
|
||||
WSLUA_RETURN(1); /* The string */
|
||||
}
|
||||
|
||||
WSLUA_METHOD TvbRange_string(lua_State* L) {
|
||||
/* Obtain a string from a TvbRange */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
|
@ -1130,7 +1146,7 @@ WSLUA_METHOD TvbRange_string(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_pushlstring(L, (gchar*)tvb_get_string(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len), tvbr->len );
|
||||
lua_pushlstring(L, (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,ENC_ASCII|ENC_NA), tvbr->len);
|
||||
|
||||
WSLUA_RETURN(1); /* The string */
|
||||
}
|
||||
|
@ -1146,7 +1162,7 @@ static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
str = (gchar*)tvb_get_unicode_string(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN));
|
||||
str = (gchar*)tvb_get_string_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN));
|
||||
lua_pushlstring(L, str, strlen(str));
|
||||
|
||||
return 1; /* The string */
|
||||
|
@ -1162,6 +1178,48 @@ WSLUA_METHOD TvbRange_le_ustring(lua_State* L) {
|
|||
WSLUA_RETURN(TvbRange_ustring_any(L, TRUE)); /* The string */
|
||||
}
|
||||
|
||||
WSLUA_METHOD TvbRange_stringz_enc(lua_State* L) {
|
||||
/* Obtain a zero terminated string from a TvbRange, using a specified encoding */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
guint encoding = (guint)luaL_checknumber(L,2);
|
||||
gint offset;
|
||||
gunichar2 uchar;
|
||||
|
||||
if ( !(tvbr && tvbr->tvb)) return 0;
|
||||
if (tvbr->tvb->expired) {
|
||||
luaL_error(L,"expired tvb");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (encoding & ENC_CHARENCODING_MASK) {
|
||||
|
||||
case ENC_UTF_16:
|
||||
case ENC_UCS_2:
|
||||
offset = tvbr->offset;
|
||||
do {
|
||||
if (!tvb_bytes_exist (tvbr->tvb->ws_tvb, offset, 2)) {
|
||||
luaL_error(L,"out of bounds");
|
||||
return 0;
|
||||
}
|
||||
/* Endianness doesn't matter when looking for null */
|
||||
uchar = tvb_get_ntohs (tvbr->tvb->ws_tvb, offset);
|
||||
offset += 2;
|
||||
} while(uchar != 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
if (tvb_find_guint8 (tvbr->tvb->ws_tvb, tvbr->offset, -1, 0) == -1) {
|
||||
luaL_error(L,"out of bounds");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL,encoding));
|
||||
|
||||
WSLUA_RETURN(1); /* The zero terminated string */
|
||||
}
|
||||
|
||||
WSLUA_METHOD TvbRange_stringz(lua_State* L) {
|
||||
/* Obtain a zero terminated string from a TvbRange */
|
||||
TvbRange tvbr = checkTvbRange(L,1);
|
||||
|
@ -1177,7 +1235,7 @@ WSLUA_METHOD TvbRange_stringz(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL) );
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,NULL,ENC_ASCII|ENC_NA));
|
||||
|
||||
WSLUA_RETURN(1); /* The zero terminated string */
|
||||
}
|
||||
|
@ -1219,7 +1277,7 @@ static int TvbRange_ustringz_any(lua_State* L, gboolean little_endian) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
lua_pushstring(L, (gchar*)tvb_get_unicode_stringz(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,&count,(little_endian ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN)) );
|
||||
lua_pushstring(L, (gchar*)tvb_get_stringz_enc(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,&count,(little_endian ? ENC_UTF_16|ENC_LITTLE_ENDIAN : ENC_UTF_16|ENC_BIG_ENDIAN)) );
|
||||
lua_pushinteger(L,count);
|
||||
|
||||
return 2; /* The zero terminated string, the length found in tvbr */
|
||||
|
@ -1422,7 +1480,9 @@ static const luaL_Reg TvbRange_methods[] = {
|
|||
{"le_ipv4", TvbRange_le_ipv4},
|
||||
{"nstime", TvbRange_nstime},
|
||||
{"le_nstime", TvbRange_le_nstime},
|
||||
{"string_enc", TvbRange_string_enc},
|
||||
{"string", TvbRange_string},
|
||||
{"stringz_enc", TvbRange_stringz_enc},
|
||||
{"stringz", TvbRange_stringz},
|
||||
{"strsize", TvbRange_strsize},
|
||||
{"bytes", TvbRange_bytes},
|
||||
|
|
Loading…
Reference in New Issue