Convert NetMon comment titles to UTF-8 when reading the file.
authorGuy Harris <guy@alum.mit.edu>
Fri, 15 Jun 2018 01:21:16 +0000 (18:21 -0700)
committerGuy Harris <guy@alum.mit.edu>
Fri, 15 Jun 2018 01:22:12 +0000 (01:22 +0000)
Fix indentation, and note that the comment "description" (contents) are
RTF (as opposed to plain text).

Change-Id: I668a08c06e39a32318454d2ee73933083c5cb516
Reviewed-on: https://code.wireshark.org/review/28279
Reviewed-by: Guy Harris <guy@alum.mit.edu>
epan/dissectors/packet-netmon.c
wiretap/netmon.c
wiretap/wtap.h

index 962d446cb40564e5c9bd86dc29bda0cc9655fc32..77b4a723bb5d4ca6e0bd456dfe28b57976e388f2 100644 (file)
@@ -403,28 +403,19 @@ dissect_netmon_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void*
        proto_tree *header_tree;
        union wtap_pseudo_header temp_header;
        gchar *comment;
-       GIConv cd;
 
        ti = proto_tree_add_item(tree, proto_netmon_header, tvb, 0, 0, ENC_NA);
        header_tree = proto_item_add_subtree(ti, ett_netmon_header);
 
        if (pinfo->pseudo_header->netmon.title != NULL) {
-               /* Title comment is UTF-16 */
-
-               if ((cd = g_iconv_open("UTF-8", "UTF-16")) != (GIConv) -1)
-               {
-                       comment = g_convert_with_iconv(pinfo->pseudo_header->netmon.title, pinfo->pseudo_header->netmon.titleLength, cd, NULL, NULL, NULL);
-                       g_iconv_close(cd);
-
-                       ti = proto_tree_add_string(header_tree, hf_netmon_header_title_comment, tvb, 0, 0, comment);
-                       PROTO_ITEM_SET_GENERATED(ti);
-                       g_free(comment);
-               }
-
+               ti = proto_tree_add_string(header_tree, hf_netmon_header_title_comment, tvb, 0, 0, pinfo->pseudo_header->netmon.title);
+               PROTO_ITEM_SET_GENERATED(ti);
        }
 
        if (pinfo->pseudo_header->netmon.description != NULL) {
-               /* Description comment is only ASCII */
+               /* Description comment is only ASCII.  However, it's
+                * RTF, not raw text.
+                */
 
                /* Ensure string termination */
                comment = wmem_strndup(wmem_packet_scope(), pinfo->pseudo_header->netmon.description, pinfo->pseudo_header->netmon.descLength);
index 37312ac697a827fe2103e0fa3892f2993a2bc758..5ff1582e0b66be1a8a17b070f8ba68ce4a58a21a 100644 (file)
@@ -110,12 +110,11 @@ struct netmonrec_2_3_trlr {
 };
 
 struct netmonrec_comment {
-       guint32 numFramePerComment;             /* Currently, this is always set to 1. Each comment is attached to only one frame. */
-       guint32 frameOffset;    /* Offset in the capture file table that indicates the beginning of the frame.  Key used to match comment with frame */
-       guint32 titleLength;    /* Number of bytes in the comment title. Must be greater than zero. */
+       guint32 numFramePerComment;     /* Currently, this is always set to 1. Each comment is attached to only one frame. */
+       guint32 frameOffset;            /* Offset in the capture file table that indicates the beginning of the frame.  Key used to match comment with frame */
        guint8* title;                  /* Comment title */
        guint32 descLength;             /* Number of bytes in the comment description. Must be at least zero. */
-       guint8* description;    /* Comment description */
+       guint8* description;            /* Comment description */
 };
 
 /* Just the first few fields of netmonrec_comment so it can be read sequentially from file */
@@ -683,7 +682,9 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info)
 
                while (comment_table_size > 16) {
                        struct netmonrec_comment_header comment_header;
+                       guint32 title_length;
                        guint32 desc_length;
+                       guint8 *utf16_str;
 
                        /* Read the first 12 bytes of the structure */
                        if (!wtap_read_bytes(wth->fh, &comment_header, 12, err, err_info)) {
@@ -710,17 +711,31 @@ wtap_open_return_val netmon_open(wtap *wth, int *err, gchar **err_info)
                        comment_rec = g_new0(struct netmonrec_comment, 1);
                        comment_rec->numFramePerComment = pletoh32(&comment_header.numFramePerComment);
                        comment_rec->frameOffset = pletoh32(&comment_header.frameOffset);
-                       comment_rec->titleLength = pletoh32(&comment_header.titleLength);
-                       comment_rec->title = (guint8*)g_malloc(comment_rec->titleLength);
+                       title_length = pletoh32(&comment_header.titleLength);
 
                        g_hash_table_insert(comment_table, GUINT_TO_POINTER(comment_rec->frameOffset), comment_rec);
 
-                       /* Read the comment title */
-                       if (!wtap_read_bytes(wth->fh, comment_rec->title, comment_rec->titleLength, err, err_info)) {
+                       /*
+                        * Read in the comment title.
+                        *
+                        * It is in UTF-16-encoded Unicode, and the title
+                        * size is a count of octets, not octet pairs or
+                        * Unicode characters.
+                        */
+                       utf16_str = (guint8*)g_malloc(title_length);
+                       if (!wtap_read_bytes(wth->fh, utf16_str, title_length,
+                           err, err_info)) {
                                g_hash_table_destroy(comment_table);
                                return WTAP_OPEN_ERROR;
                        }
-                       comment_table_size -= comment_rec->titleLength;
+                       comment_table_size -= title_length;
+
+                       /*
+                        * Now convert it to UTF-8 for internal use.
+                        */
+                       comment_rec->title = utf_16_to_utf_8(utf16_str,
+                           title_length);
+                       g_free(utf16_str);
 
                        if (comment_table_size < 4) {
                                *err = WTAP_ERR_BAD_FILE;
@@ -1387,7 +1402,6 @@ netmon_process_record(wtap *wth, FILE_T fh, wtap_rec *rec,
                rec->rec_header.packet_header.pseudo_header.netmon.sub_encap = rec->rec_header.packet_header.pkt_encap;
 
                /* Copy the comment data */
-               rec->rec_header.packet_header.pseudo_header.netmon.titleLength = comment_rec->titleLength;
                rec->rec_header.packet_header.pseudo_header.netmon.title = comment_rec->title;
                rec->rec_header.packet_header.pseudo_header.netmon.descLength = comment_rec->descLength;
                rec->rec_header.packet_header.pseudo_header.netmon.description = comment_rec->description;
index 4ea94b686db7b43337685fe0a7b0936f643feeb9..3822b1b4326654e476cd3645ce7f3ce019d45c05 100644 (file)
@@ -1147,10 +1147,9 @@ struct logcat_phdr {
 /* Packet "pseudo-header" information for header data from NetMon files. */
 
 struct netmon_phdr {
-    guint32 titleLength;    /* Number of bytes in the comment title */
-    guint8* title;          /* Comment title */
+    guint8* title;          /* Comment title, as a null-terminated UTF-8 string */
     guint32 descLength;     /* Number of bytes in the comment description */
-    guint8* description;    /* Comment description */
+    guint8* description;    /* Comment description, in ASCII RTF */
     guint sub_encap;        /* "Real" encap value for the record that will be used once pseudo header data is display */
     union sub_wtap_pseudo_header {
         struct eth_phdr     eth;