ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] How to print out string encoded data that contains nul character

From: "John Dill" <John.Dill@xxxxxxxxxxxxxxxxx>
Date: Wed, 9 Apr 2014 17:06:50 -0400
Title: How to print out string encoded data that contains nul characters?

I have several character data fields that happen to contain sections of non-ascii binary data including nul characters.  I'd like to get a string display that shows all of the characters according to the length of the field, i.e.

20 20 20 20 20 20 01 00 01 00 48 31 20 20 20 20

produces

"      \001\000\001\000H1    "

In proto.c, I see that all of the format_text calls use strlen(bytes) as the length.

case FT_STRING:
case FT_STRINGZ:
case FT_UINT_STRING:
        bytes = (guint8 *)fvalue_get(&fi->value);
        label_fill(label_str, hfinfo, format_text(bytes, strlen(bytes)));

What is the recommended way of creating a text string that uses the octal encoding '\xxx' for non-ASCII data including nul characters that uses the 'length' field of 'proto_tree_add_item'?  I'm currently using FT_STRING, but obviously the string label ends at the first nul character.  I do not want FT_BYTES because the characters themselves are the important data in the field.

Thanks,
John Dill