diff --git a/common/utils/itti_analyzer/libparser/array_type.c b/common/utils/itti_analyzer/libparser/array_type.c index 0a2fe60b57db6f7ada5b9b474a14c2e426a0a491..ebeb6b87d3cd3c581c0d71020e3d03660d027cf9 100644 --- a/common/utils/itti_analyzer/libparser/array_type.c +++ b/common/utils/itti_analyzer/libparser/array_type.c @@ -2,6 +2,7 @@ #include <stdlib.h> #include <assert.h> #include <string.h> +#include <ctype.h> #include "array_type.h" #include "fundamental_type.h" @@ -29,6 +30,8 @@ int array_dissect_from_buffer( int items = type->size / type_child->size; int i; int zero_counter = 0; + gboolean is_string = FALSE; + char *string; /* Factorizes trailing 0 */ if ((items > 1) && (type_child->type == TYPE_FUNDAMENTAL)) @@ -44,30 +47,60 @@ int array_dissect_from_buffer( break; } } - /* Do not factorize if there is only one item */ + + /* Check if this is an array of 8 bits items and if at least the firsts ones are not null */ + if ((type_child->size == 8) && ((items - zero_counter) >= 2)) + { + /* check if this is a printable string */ + is_string = TRUE; + string = calloc(items + 1, 1); + + for (i = 0; i < (items - zero_counter); i++) + { + string[i] = fundamental_read_from_buffer(type_child, buffer, parent_offset, offset + i * type_child->size); + if (isprint(string[i]) == 0) + { + /* This is not a printable string */ + is_string = FALSE; + break; + } + } + + if (is_string) + { + INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] \"%s\"\n", 0, (items - zero_counter - 1), string)); + ui_set_signal_text_cb(user_data, cbuf, length); + } + } + + /* Do not factorize if there is only one null item */ if (zero_counter <= 1) { zero_counter = 0; } } - for (i = 0; i < (items - zero_counter); i++) - { - INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d] ", i)); - ui_set_signal_text_cb(user_data, cbuf, length); - type->child->type_dissect_from_buffer ( - type->child, ui_set_signal_text_cb, user_data, buffer, parent_offset, - offset + i * type_child->size, indent, - FALSE); - } - if (zero_counter > 0) + if (is_string == FALSE) { - INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] ", i, items -1)); - ui_set_signal_text_cb(user_data, cbuf, length); + for (i = 0; i < (items - zero_counter); i++) + { + INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d] ", i)); + ui_set_signal_text_cb(user_data, cbuf, length); - type->child->type_dissect_from_buffer ( - type->child, ui_set_signal_text_cb, user_data, - buffer, parent_offset, offset + i * type_child->size, indent, FALSE); + type->child->type_dissect_from_buffer ( + type->child, ui_set_signal_text_cb, user_data, buffer, parent_offset, + offset + i * type_child->size, indent, + FALSE); + } + if (zero_counter > 0) + { + INDENTED_STRING(cbuf, indent, length = sprintf(cbuf, "[%d .. %d] ", i, items -1)); + ui_set_signal_text_cb(user_data, cbuf, length); + + type->child->type_dissect_from_buffer ( + type->child, ui_set_signal_text_cb, user_data, + buffer, parent_offset, offset + i * type_child->size, indent, FALSE); + } } } if (type->name) { diff --git a/common/utils/itti_analyzer/libparser/fundamental_type.c b/common/utils/itti_analyzer/libparser/fundamental_type.c index 51045b56ee66c7c1fac9e5a44a0e9d90c7d28b80..0ff786e58d52ac4fe017040fde0d9fc3232c034a 100644 --- a/common/utils/itti_analyzer/libparser/fundamental_type.c +++ b/common/utils/itti_analyzer/libparser/fundamental_type.c @@ -1,7 +1,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <inttypes.h> #include "fundamental_type.h" @@ -64,7 +63,7 @@ int fundamental_dissect_from_buffer( case 8: value8 = (uint8_t) value64; INDENTED_STRING(cbuf, indent, - length = sprintf(cbuf, type_unsigned ? "(0x%02" PRIx8 ") %3" PRIu8 " '%c';\n" : "(0x%02" PRIx8 ") %4" PRId8 " '%c';\n", value8, value8, isprint(value8) ? value8 : '.')); + length = sprintf(cbuf, type_unsigned ? "(0x%02" PRIx8 ") %3" PRIu8 ";\n" : "(0x%02" PRIx8 ") %4" PRId8 ";\n", value8, value8)); break; case 16: