diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-01-21 09:56:34 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-01-21 09:56:34 +0000 |
commit | 4d9475e4ef71951d60120746f8bb130d3918f015 (patch) | |
tree | a9de685aba075743c570f46a7bd67a6aa9a8e26e | |
parent | 35d0d0f1ae67528f1f2f7f23651b498178f7143a (diff) | |
download | wireshark-4d9475e4ef71951d60120746f8bb130d3918f015.tar.gz wireshark-4d9475e4ef71951d60120746f8bb130d3918f015.tar.bz2 wireshark-4d9475e4ef71951d60120746f8bb130d3918f015.zip |
Get rid of tvb_get_faked_unicode() - tvb_get_string_enc() does the job
better.
We don't need eventlog_get_unicode_string_length() in the eventlog
dissector, either - tvb_unicode_strsize() does the job just as well.
svn path=/trunk/; revision=54874
-rw-r--r-- | epan/dissectors/packet-dcerpc-eventlog.c | 51 | ||||
-rw-r--r-- | epan/dissectors/pidl/eventlog.cnf | 48 | ||||
-rw-r--r-- | epan/tvbuff.c | 37 | ||||
-rw-r--r-- | epan/tvbuff.h | 13 |
4 files changed, 31 insertions, 118 deletions
diff --git a/epan/dissectors/packet-dcerpc-eventlog.c b/epan/dissectors/packet-dcerpc-eventlog.c index b85515bd39..88098eaeee 100644 --- a/epan/dissectors/packet-dcerpc-eventlog.c +++ b/epan/dissectors/packet-dcerpc-eventlog.c @@ -344,39 +344,25 @@ eventlog_dissect_element_Record_sid_offset(tvbuff_t *tvb, int offset, packet_inf return offset; } static int -eventlog_get_unicode_string_length(tvbuff_t *tvb, int offset) -{ - int len; - len=0; - while(1){ - if(!tvb_get_ntohs(tvb, offset+len*2)){ - len++; - break; - } - len++; - } - return len; -} -static int eventlog_dissect_element_Record_source_name(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, dcerpc_info *di _U_, guint8 *drep _U_) { - char *str; - int len; - len=eventlog_get_unicode_string_length(tvb, offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_source_name, tvb, offset, len*2, str, "source_name: %s", str); - offset+=len*2; + guint len; + + len=tvb_unicode_strsize(tvb, offset); + proto_tree_add_item(tree, hf_eventlog_Record_source_name, tvb, offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); + + offset+=len; return offset; } static int eventlog_dissect_element_Record_computer_name(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, dcerpc_info *di _U_, guint8 *drep _U_) { - char *str; - int len; - len=eventlog_get_unicode_string_length(tvb, offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_computer_name, tvb, offset, len*2, str, "computer_name: %s", str); - offset+=len*2; + guint len; + + len=tvb_unicode_strsize(tvb, offset); + proto_tree_add_item(tree, hf_eventlog_Record_computer_name, tvb, offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); + + offset+=len; return offset; } static guint16 num_of_strings; @@ -399,15 +385,16 @@ static int eventlog_dissect_element_Record_strings(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, dcerpc_info *di _U_, guint8 *drep _U_) { while(string_offset && num_of_strings){ - char *str; - int len; - len=eventlog_get_unicode_string_length(tvb, string_offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, string_offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_string, tvb, string_offset, len*2, str, "string: %s", str); - string_offset+=len*2; + guint len; + + len=tvb_unicode_strsize(tvb, string_offset); + proto_tree_add_item(tree, hf_eventlog_Record_string, tvb, string_offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); + string_offset+=len; num_of_strings--; } + + return offset; } diff --git a/epan/dissectors/pidl/eventlog.cnf b/epan/dissectors/pidl/eventlog.cnf index 8385363078..cc8491795f 100644 --- a/epan/dissectors/pidl/eventlog.cnf +++ b/epan/dissectors/pidl/eventlog.cnf @@ -104,49 +104,27 @@ eventlog_dissect_element_Record_sid_offset(tvbuff_t *tvb, int offset, packet_inf return offset; } - -static int -eventlog_get_unicode_string_length(tvbuff_t *tvb, int offset) -{ - int len; - - len=0; - while(1){ - if(!tvb_get_ntohs(tvb, offset+len*2)){ - len++; - break; - } - len++; - } - - return len; -} - static int eventlog_dissect_element_Record_source_name(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_) { - char *str; - int len; + guint len; - len=eventlog_get_unicode_string_length(tvb, offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_source_name, tvb, offset, len*2, str, "source_name: %s", str); + len=tvb_unicode_strsize(tvb, offset); + proto_tree_add_item(tree, hf_eventlog_Record_source_name, tvb, offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); - offset+=len*2; + offset+=len; return offset; } static int eventlog_dissect_element_Record_computer_name(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_) { - char *str; - int len; + guint len; - len=eventlog_get_unicode_string_length(tvb, offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_computer_name, tvb, offset, len*2, str, "computer_name: %s", str); + len=tvb_unicode_strsize(tvb, offset); + proto_tree_add_item(tree, hf_eventlog_Record_computer_name, tvb, offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); - offset+=len*2; + offset+=len; return offset; } @@ -176,13 +154,11 @@ static int eventlog_dissect_element_Record_strings(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, guint8 *drep _U_) { while(string_offset && num_of_strings){ - char *str; - int len; + guint len; - len=eventlog_get_unicode_string_length(tvb, string_offset); - str=tvb_get_faked_unicode(wmem_packet_scope(), tvb, string_offset, len, TRUE); - proto_tree_add_string_format(tree, hf_eventlog_Record_string, tvb, string_offset, len*2, str, "string: %s", str); - string_offset+=len*2; + len=tvb_unicode_strsize(tvb, string_offset); + proto_tree_add_item(tree, hf_eventlog_Record_string, tvb, string_offset, len, ENC_UTF_16|ENC_LITTLE_ENDIAN); + string_offset+=len; num_of_strings--; } diff --git a/epan/tvbuff.c b/epan/tvbuff.c index e9d23a5302..a0371a7423 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1741,43 +1741,6 @@ tvb_memeql(tvbuff_t *tvb, const gint offset, const guint8 *str, size_t size) } } -/* Convert a string from Unicode to ASCII. At the moment we fake it by - * replacing all non-ASCII characters with a '.' )-: The len parameter is - * the number of guint16's to convert from Unicode. - * - * If scope is set to NULL, returned buffer is allocated by g_malloc() - * and must be g_free by the caller. Otherwise memory is automatically - * freed when the scope lifetime is reached. - */ -/* XXX: This has been replaced by tvb_get_string() */ -char * -tvb_get_faked_unicode(wmem_allocator_t *scope, tvbuff_t *tvb, int offset, - const int len, const gboolean little_endian) -{ - char *buffer; - int i; - guint16 character; - - /* Make sure we have enough data before allocating the buffer, - so we don't blow up if the length is huge. */ - tvb_ensure_bytes_exist(tvb, offset, 2*len); - - /* We know we won't throw an exception, so we don't have to worry - about leaking this buffer. */ - buffer = (char *)wmem_alloc(scope, len + 1); - - for (i = 0; i < len; i++) { - character = little_endian ? tvb_get_letohs(tvb, offset) - : tvb_get_ntohs(tvb, offset); - buffer[i] = character < 256 ? character : '.'; - offset += 2; - } - - buffer[len] = 0; - - return buffer; -} - /* * Format the data in the tvb from offset for length ... */ diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 304684dc60..be7db043f3 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -436,19 +436,6 @@ WS_DLL_PUBLIC guint tvb_unicode_strsize(tvbuff_t *tvb, const gint offset); WS_DLL_PUBLIC gint tvb_strnlen(tvbuff_t *tvb, const gint offset, const guint maxlength); -/** Convert a string from Unicode to ASCII. At the moment we fake it by - * assuming all characters are ASCII )-: The len parameter is the number - * of guint16's to convert from Unicode. - * - * XXX - These functions have been superceded by tvb_get_unicode_string() - * - * If scope is set to NULL, returned buffer is allocated by g_malloc() - * and must be g_free by the caller. Otherwise memory is automatically - * freed when the scope lifetime is reached. - */ -WS_DLL_PUBLIC char *tvb_get_faked_unicode(wmem_allocator_t *scope, - tvbuff_t *tvb, int offset, const int len, const gboolean little_endian); - /** * Format the data in the tvb from offset for size ... */ |