3 # Copyright 2013 Michael Mann (see AUTHORS file)
5 # A program to help convert proto_tree_add_text calls into filterable "items" that
6 # use proto_tree_add_item. The program requires 2 passes. "Pass 1" (generate) collects
7 # the eligible proto_tree_add_text calls and outputs the necessary data into a delimited
8 # file. "Pass 2" (fix-all) takes the data from the delimited file and replaces the
9 # proto_tree_add_text calls with proto_tree_add_item or "expert info" calls as well as
10 # generating separate files for the hf and/or ei variable declarations and hf and/or ei array data.
11 # The hf "files" can be copy/pasted into the dissector where appropriate (until such time as
12 # its done automatically)
14 # Note that the output from "Pass 1" won't always be a perfect conversion for "Pass 2", so
15 # "human interaction" is needed as an intermediary to verify and update the delimited file
16 # before "Pass 2" is done.
17 # It is also recommended to run checkhf.pl and checkAPIs.pl after "Pass 2" is completed.
19 # Delimited file field format:
20 # <convert proto_tree_add_text_call[0|1|10-13]><add hf or ei variable[0|1|2]><proto_tree var><hf var><tvb var><offset><length><encoding|[EXPERT_GROUPS]>
21 # <[FIELDNAME]><[FIELDTYPE]|[EXPERT_SEVERITY]><[FIELDABBREV]><[FIELDDISPLAY]><[FIELDCONVERT]><[BITMASK]>
23 # convert proto_tree_add_text_call enumerations:
25 # 1 - proto_tree_add_item
26 # 10 - expert_add_info
27 # 11 - expert_add_info_format
28 # 12 - proto_tree_add_expert
29 # 13 - proto_tree_add_expert_format
31 # Usage: convert_proto_tree_add_text.pl action=<generate|fix-all> <file or files>
33 # Lots of code shamelessly borrowed from fix-encoding-args.pl (Thanks Bill!)
35 # Wireshark - Network traffic analyzer
36 # By Gerald Combs <gerald@wireshark.org>
37 # Copyright 1998 Gerald Combs
39 # SPDX-License-Identifier: GPL-2.0-or-later
47 my %DISPLAY_BASE = ('BASE_NONE' => "BASE_NONE",
48 'BASE_DEC' => "BASE_DEC",
49 'BASE_HEX' => "BASE_HEX",
50 'BASE_OCT' => "BASE_OCT",
51 'BASE_DEC_HEX' => "BASE_DEC_HEX",
52 'BASE_HEX_DEC' => "BASE_HEX_DEC",
53 'BASE_EXT_STRING' => "BASE_EXT_STRING",
54 'BASE_RANGE_STRING' => "BASE_RANGE_STRING",
55 'ABSOLUTE_TIME_LOCAL' => "ABSOLUTE_TIME_LOCAL",
56 'ABSOLUTE_TIME_UTC' => "ABSOLUTE_TIME_UTC",
57 'ABSOLUTE_TIME_DOY_UTC' => "ABSOLUTE_TIME_DOY_UTC",
58 'BASE_CUSTOM' => "BASE_CUSTOM");
60 my %ENCODINGS = ('ENC_BIG_ENDIAN' => "ENC_BIG_ENDIAN",
61 'ENC_LITTLE_ENDIAN' => "ENC_LITTLE_ENDIAN",
62 'ENC_TIME_SECS_NSECS' => "ENC_TIME_SECS_NSECS",
63 'ENC_TIME_NTP' => "ENC_TIME_NTP",
64 'ENC_ASCII' => "ENC_ASCII",
65 'ENC_UTF_8' => "ENC_UTF_8",
66 'ENC_UTF_16' => "ENC_UTF_16",
67 'ENC_UCS_2' => "ENC_UCS_2",
68 'ENC_EBCDIC' => "ENC_EBCDIC",
69 'ENC_NA' => "ENC_NA");
71 my %FIELD_TYPE = ('FT_NONE' => "FT_NONE", 'FT_PROTOCOL' => "FT_PROTOCOL", 'FT_BOOLEAN' => "FT_BOOLEAN",
72 'FT_UINT8' => "FT_UINT8", 'FT_UINT16' => "FT_UINT16", 'FT_UINT24' => "FT_UINT24", 'FT_UINT32' => "FT_UINT32", 'FT_UINT64' => "FT_UINT64",
73 'FT_INT8' => "FT_INT8", 'FT_INT16' => "FT_INT16", 'FT_INT24' => "FT_INT24", 'FT_INT32' => "FT_INT32", 'FT_INT64' => "FT_INT64",
74 'FT_FLOAT' => "FT_FLOAT", 'FT_DOUBLE' => "FT_DOUBLE",
75 'FT_ABSOLUTE_TIME' => "FT_ABSOLUTE_TIME", 'FT_RELATIVE_TIME' => "FT_RELATIVE_TIME",
76 'FT_STRING' => "FT_STRING", 'FT_STRINGZ' => "FT_STRINGZ", 'FT_UINT_STRING' => "FT_UINT_STRING",
77 'FT_ETHER' => "FT_ETHER", 'FT_BYTES' => "FT_BYTES", 'FT_UINT_BYTES' => "FT_UINT_BYTES",
78 'FT_IPv4' => "FT_IPv4", 'FT_IPv6' => "FT_IPv6", 'FT_IPXNET' => "FT_IPXNET", 'FT_AX25' => "FT_AX25", 'FT_VINES' => "FT_VINES",
79 'FT_FRAMENUM' => "FT_FRAMENUM", 'FT_GUID' => "FT_GUID", 'FT_OID' => "FT_OID", 'FT_REL_OID' => "FT_REL_OID", 'FT_EUI64' => "FT_EUI64");
81 my %EXPERT_SEVERITY = ('PI_COMMENT' => "PI_COMMENT",
82 'PI_CHAT' => "PI_CHAT",
83 'PI_NOTE' => "PI_NOTE",
84 'PI_WARN' => "PI_WARN",
85 'PI_ERROR' => "PI_ERROR");
87 my %EXPERT_GROUPS = ('PI_CHECKSUM' => "PI_CHECKSUM",
88 'PI_SEQUENCE' => "PI_SEQUENCE",
89 'PI_RESPONSE_CODE' => "PI_RESPONSE_CODE",
90 'PI_REQUEST_CODE' => "PI_REQUEST_CODE",
91 'PI_UNDECODED' => "PI_UNDECODED",
92 'PI_REASSEMBLE' => "PI_REASSEMBLE",
93 'PI_MALFORMED' => "PI_MALFORMED",
94 'PI_DEBUG' => "PI_DEBUG",
95 'PI_PROTOCOL' => "PI_PROTOCOL",
96 'PI_SECURITY' => "PI_SECURITY",
97 'PI_COMMENTS_GROUP' => "PI_COMMENTS_GROUP",
98 'PI_DECRYPTION' => "PI_DECRYPTION",
99 'PI_ASSUMPTION' => "PI_ASSUMPTION",
100 'PI_DEPRECATED' => "PI_DEPRECATED",
101 'PI_RECEIVE' => "PI_RECEIVE",
102 'PI_INTERFACE' => "PI_INTERFACE",
103 'PI_DISSECTOR_BUG' => "PI_DISSECTOR_BUG");
109 # Perl trim function to remove whitespace from the start and end of the string
118 # ---------------------------------------------------------------------
123 my $action = 'generate';
127 my $result = GetOptions
(
128 'action=s' => \
$action,
129 'encoding=s' => \
$encoding,
130 'expert' => \
$expert,
131 'help|?' => \
$helpFlag
134 if (!$result || $helpFlag || !$ARGV[0]) {
139 print "\nUsage: $0 [--action=generate|fix-all|find-all] [--encoding=ENC_BIG_ENDIAN|ENC_LITTLE_ENDIAN] FILENAME [...]\n\n";
140 print " --action = generate (default)\n";
141 print " generate - create a delimited file (FILENAME.proto_tree_input) with\n";
142 print " proto_tree_add_text fields in FILENAME(s)\n";
143 print " fix-all - Use delimited file (FILENAME.proto_tree_input) to convert\n";
144 print " proto_tree_add_text to proto_tree_add_item\n";
145 print " Also generates FILENAME.hf and FILENAME.hf_array to be\n";
146 print " copy/pasted into the dissector where appropriate\n";
147 print " find-all - Output the number of eligible proto_tree_add_text calls\n";
148 print " for conversion\n\n";
149 print " --expert (Optional) Includes proto_tree_add_text calls with no printf arguments in\n";
150 print " the .proto_tree_input file as they could be converted to expert info\n";
151 print " (otherwise they are ignored)\n";
152 print " Must be called for 'fix-all' if called on 'generate'\n";
153 print " --encoding (Optional) Default encoding if one can't be determined\n";
154 print " (effective only for generate)\n";
155 print " If not specified, an encoding will not be auto-populated\n";
156 print " if undetermined\n\n";
162 # XXX Outline general algorithm here
165 my $protabbrev_index;
168 while (my $fileName = $ARGV[0]) {
170 my $fileContents = '';
172 die "No such file: \"$fileName\"\n" if (! -e
$fileName);
174 # delete leading './'
175 $fileName =~ s{ ^ \. / } {}xo;
177 #determine PROTABBREV for dissector based on file name format of (dirs)/packet-PROTABBREV.c
178 $protabbrev_index = rindex($fileName, "packet-");
179 if ($protabbrev_index == -1) {
180 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
184 $protabbrev = substr($fileName, $protabbrev_index+length("packet-"));
185 $protabbrev_index = rindex($protabbrev, ".");
186 if ($protabbrev_index == -1) {
187 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
190 $protabbrev = lc(substr($protabbrev, 0, $protabbrev_index));
192 # Read in the file (ouch, but it's easier that way)
193 open(FCI
, "<", $fileName) || die("Couldn't open $fileName");
199 if ($action eq "generate") {
200 generate_hfs
(\
$fileContents, $fileName);
203 if ($action eq "fix-all") {
204 # Read in the hf "input" file
207 open(FCI
, "<", $fileName . ".proto_tree_input") || die("Couldn't open $fileName.proto_tree_input");
208 while(my $line=<FCI
>){
209 my @proto_tree_item = split(/;|\n/, $line);
212 $errors += verify_line
(@proto_tree_item);
214 push(@proto_tree_list, \
@proto_tree_item);
215 if ($proto_tree_item[1] eq "2") {
216 push(@expert_list, \
@proto_tree_item);
222 print "Aborting conversion.\n";
226 fix_proto_tree_add_text
(\
$fileContents, $fileName);
228 # Write out the hf data
229 output_hf_array
($fileName);
230 output_hf
($fileName);
232 # Write out the changed version to a file
233 open(FCO
, ">", $fileName . ".proto_tree_add_text");
234 print FCO
"$fileContents";
238 if ($action eq "find-all") {
239 # Find all proto_tree_add_text() statements eligible for conversion
240 $found_total += find_all
(\
$fileContents, $fileName);
247 # ---------------------------------------------------------------------
248 # Sanity check the data in the .proto_tree_input file
250 my( @proto_tree_item) = @_;
253 #do some basic error checking of the file
254 if ($proto_tree_item[0] eq "1") {
255 if (!($proto_tree_item[3] =~ /^hf_/)) {
256 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
260 foreach (split(/\|/, $proto_tree_item[7])) {
261 if (!exists($ENCODINGS{$_})) {
262 print "$line_number: Encoding value '$_' unknown!\n";
266 } elsif (($proto_tree_item[0] eq "10") ||
267 ($proto_tree_item[0] eq "11") ||
268 ($proto_tree_item[0] eq "12") ||
269 ($proto_tree_item[0] eq "13")) {
270 #expert info conversions
271 if (!($proto_tree_item[3] =~ /^ei_/)) {
272 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
275 } elsif ($proto_tree_item[0] ne "0") {
276 print "Bad conversion value! Aborting conversion.\n";
280 if ($proto_tree_item[1] eq "1") {
281 if (!($proto_tree_item[3] =~ /^hf_/)) {
282 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
285 if (!exists($FIELD_TYPE{$proto_tree_item[9]})) {
286 print "$line_number: Field type '$proto_tree_item[9]' unknown!\n";
289 foreach (split(/\|/, $proto_tree_item[11])) {
290 if ((!exists($DISPLAY_BASE{$_})) &&
291 (!($proto_tree_item[11] =~ /\d+/))) {
292 print "$line_number: Display base '$proto_tree_item[11]' unknown!\n";
296 if (($proto_tree_item[9] eq "FT_UINT8") ||
297 ($proto_tree_item[9] eq "FT_UINT16") ||
298 ($proto_tree_item[9] eq "FT_UINT24") ||
299 ($proto_tree_item[9] eq "FT_UINT32") ||
300 ($proto_tree_item[9] eq "FT_UINT64") ||
301 ($proto_tree_item[9] eq "FT_INT8") ||
302 ($proto_tree_item[9] eq "FT_INT16") ||
303 ($proto_tree_item[9] eq "FT_INT24") ||
304 ($proto_tree_item[9] eq "FT_INT32") ||
305 ($proto_tree_item[9] eq "FT_INT64")) {
306 if ($proto_tree_item[11] eq "BASE_NONE") {
307 print "$line_number: Interger type should not be BASE_NONE!\n";
312 } elsif ($proto_tree_item[1] eq "2") {
313 if (!($proto_tree_item[3] =~ /^ei_/)) {
314 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
317 if (!exists($EXPERT_SEVERITY{$proto_tree_item[9]})) {
318 print "$line_number: Expert severity value '$proto_tree_item[9]' unknown!\n";
321 if (!exists($EXPERT_GROUPS{$proto_tree_item[7]})) {
322 print "$line_number: Expert group value '$proto_tree_item[7]' unknown!\n";
326 } elsif ($proto_tree_item[1] ne "0") {
327 print "$line_number: Bad hf/ei variable generation value!\n";
335 my( $fileContentsRef, $fileName) = @_;
345 (?
:proto_tree_add_text
)\s
* \
(
354 (?
:proto_tree_add_text
)\s
* \
(
362 while ($$fileContentsRef =~ / $pat /xgso) {
363 my @proto_tree_item = (1, 1, "tree", "hf_name", "tvb", "offset", "length", "encoding",
364 "fieldfullname", "fieldtype", "fieldabbrevname", "BASE_NONE", "NULL", "0x0");
366 $str =~ tr/\t\n\r/ /d;
367 $str =~ s/ \s+ / /xg;
368 #print "$fileName: $str\n";
370 @args = split(/,/, $str);
371 #printf "ARGS(%d): %s\n", scalar @args, join("# ", @args);
372 $args[0] =~ s/proto_tree_add_text\s*\(\s*//;
373 $proto_tree_item[2] = $args[0]; #tree
374 $proto_tree_item[4] = trim
($args[1]); #tvb
375 $proto_tree_item[5] = trim
($args[2]); #offset
376 $proto_tree_item[6] = trim
($args[3]); #length
377 if (scalar @args == 5) {
378 #remove the "); at the end
379 $args[4] =~ s/\"\s*\)\s*;$//;
383 if (scalar @args > 5) {
384 if (($proto_tree_item[6] eq "1") ||
385 ($args[5] =~ /tvb_get_g?uint8/) ||
386 ($args[5] =~ /tvb_bytes_to_str/) ||
387 ($args[5] =~ /tvb_ether_to_str/)) {
388 $proto_tree_item[7] = "ENC_NA";
389 } elsif ($args[5] =~ /tvb_get_ntoh/) {
390 $proto_tree_item[7] = "ENC_BIG_ENDIAN";
391 } elsif ($args[5] =~ /tvb_get_letoh/) {
392 $proto_tree_item[7] = "ENC_LITTLE_ENDIAN";
393 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
394 ($args[5] =~ /tvb_format_text/)){
395 $proto_tree_item[7] = "ENC_NA|ENC_ASCII";
396 } elsif ($encoding ne "") {
397 $proto_tree_item[7] = $encoding;
402 if (($expert ne "") || (scalar @args > 5)) {
403 my @arg_temp = split(/=|:/, $args[4]);
404 $proto_tree_item[8] = $arg_temp[0];
406 $proto_tree_item[8] = $args[4];
408 $proto_tree_item[8] =~ s/\"//;
409 $proto_tree_item[8] = trim
($proto_tree_item[8]);
411 if ($proto_tree_item[8] eq "%s\"") {
412 #assume proto_tree_add_text will not be converted
413 $proto_tree_item[0] = 0;
414 $proto_tree_item[1] = 0;
415 $proto_tree_item[3] = sprintf("hf_%s_", $protabbrev);
416 $proto_tree_item[10] = sprintf("%s.", $protabbrev);
419 $proto_tree_item[3] = sprintf("hf_%s_%s", $protabbrev, lc($proto_tree_item[8]));
420 $proto_tree_item[3] =~ s/\s+|-|:/_/g;
422 #field abbreviated name
423 $proto_tree_item[10] = sprintf("%s.%s", $protabbrev, lc($proto_tree_item[8]));
424 $proto_tree_item[10] =~ s/\s+|-|:/_/g;
428 if ($str =~ /val_to_str(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
429 $proto_tree_item[12] = sprintf("VALS(%s)", trim
($2));
430 } elsif ($str =~ /val_to_str(_const)?\([^\,]*\,([^\,]*)\,/) {
431 $proto_tree_item[12] = sprintf("VALS(%s)", trim
($2));
432 } elsif ($str =~ /val_to_str_ext(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
433 $proto_tree_item[12] = trim
($2);
434 } elsif ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
435 $proto_tree_item[12] = trim
($2);
439 if (scalar @args > 5) {
440 if ($args[5] =~ /tvb_get_g?uint8/) {
441 if ($args[4] =~ /%[0-9]*[i]/) {
442 $proto_tree_item[9] = "FT_INT8";
444 $proto_tree_item[9] = "FT_UINT8";
446 } elsif ($args[5] =~ /tvb_get_(n|"le")tohs/) {
447 if ($args[4] =~ /%[0-9]*[i]/) {
448 $proto_tree_item[9] = "FT_INT16";
450 $proto_tree_item[9] = "FT_UINT16";
452 } elsif ($args[5] =~ /tvb_get_(n|"le")toh24/) {
453 if ($args[4] =~ /%[0-9]*[i]/) {
454 $proto_tree_item[9] = "FT_INT24";
456 $proto_tree_item[9] = "FT_UINT24";
458 } elsif ($args[5] =~ /tvb_get_(n|"le")tohl/) {
459 if ($args[4] =~ /%[0-9]*[i]/) {
460 $proto_tree_item[9] = "FT_INT32";
462 $proto_tree_item[9] = "FT_UINT32";
464 } elsif ($args[5] =~ /tvb_get_(n|"le")toh("40"|"48"|"56"|"64")/) {
465 if ($args[4] =~ /%[0-9]*[i]/) {
466 $proto_tree_item[9] = "FT_INT64";
468 $proto_tree_item[9] = "FT_UINT64";
470 } elsif (($args[5] =~ /tvb_get_(n|"le")tohieee_float/) ||
471 ($args[4] =~ /%[0-9\.]*[fFeEgG]/)) {
472 $proto_tree_item[9] = "FT_FLOAT";
473 } elsif ($args[5] =~ /tvb_get_(n|"le")tohieee_double/) {
474 $proto_tree_item[9] = "FT_DOUBLE";
475 } elsif (($args[5] =~ /tvb_get_ipv4/) ||
476 ($args[5] =~ /tvb_ip_to_str/)) {
477 $proto_tree_item[9] = "FT_IPv4";
478 } elsif (($args[5] =~ /tvb_get_ipv6/) ||
479 ($args[5] =~ /tvb_ip6_to_str/)) {
480 $proto_tree_item[9] = "FT_IPv6";
481 } elsif ($args[5] =~ /tvb_get_(n|"le")tohguid/) {
482 $proto_tree_item[9] = "FT_GUID";
483 } elsif ($args[5] =~ /tvb_get_ephemeral_stringz/) {
484 $proto_tree_item[9] = "FT_STRINGZ";
485 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
486 ($args[5] =~ /tvb_format_text/)){
487 $proto_tree_item[9] = "FT_STRING";
488 } elsif (($args[5] =~ /tvb_bytes_to_str/)) {
489 $proto_tree_item[9] = "FT_BYTES";
490 } elsif ($args[5] =~ /tvb_ether_to_str/) {
491 $proto_tree_item[9] = "FT_ETHER";
494 #if we still can't determine type, assume a constant length
495 #value means we have an unsigned value
496 if ($proto_tree_item[9] eq "fieldtype") {
497 my $len_str = trim
($args[3]);
498 if ($len_str eq "1") {
499 $proto_tree_item[9] = "FT_UINT8";
500 } elsif ($len_str eq "2") {
501 $proto_tree_item[9] = "FT_UINT16";
502 } elsif ($len_str eq "3") {
503 $proto_tree_item[9] = "FT_UINT24";
504 } elsif ($len_str eq "4") {
505 $proto_tree_item[9] = "FT_UINT32";
506 } elsif ($len_str eq "8") {
507 $proto_tree_item[9] = "FT_UINT64";
513 if ($args[4] =~ /%[0-9]*[xX]/) {
514 $proto_tree_item[11] = "BASE_HEX";
515 } elsif ($args[4] =~ /%[0-9]*[uld]/) {
516 $proto_tree_item[11] = "BASE_DEC";
517 } elsif ($args[4] =~ /%[0-9]*o/) {
518 $proto_tree_item[11] = "BASE_OCT";
520 if ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
521 $proto_tree_item[11] .= "|BASE_EXT_STRING";
524 if (($proto_tree_item[7] eq "encoding") && ($proto_tree_item[9] eq "FT_BYTES")) {
525 $proto_tree_item[7] = "ENC_NA";
528 push(@proto_tree_list, \
@proto_tree_item);
533 if ($num_items > 0) {
534 open(FCO
, ">", $fileName . ".proto_tree_input");
535 for my $item (@proto_tree_list) {
536 print FCO
join(";", @
{$item}), "\n";
542 # ---------------------------------------------------------------------
543 # Find all proto_tree_add_text calls and replace them with the data
544 # found in proto_tree_list
545 sub fix_proto_tree_add_text
{
546 my( $fileContentsRef, $fileName) = @_;
553 (?
:proto_tree_add_text
)\s
* \
(
562 (?
:proto_tree_add_text
)\s
* \
(
570 $$fileContentsRef =~ s/ $pat /patsub($found, $1)/xges;
573 # ---------------------------------------------------------------------
574 # Format proto_tree_add_item or expert info functions with proto_tree_list data
577 if ($proto_tree_list[$_[0]][0] eq "1") {
578 $item_str = sprintf("proto_tree_add_item(%s, %s, %s, %s, %s, %s);",
579 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
580 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
581 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][7]);
582 } elsif ($proto_tree_list[$_[0]][0] eq "10") {
583 $item_str = sprintf("expert_add_info(pinfo, %s, &%s);",
584 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3]);
585 } elsif ($proto_tree_list[$_[0]][0] eq "11") {
586 $item_str = sprintf("expert_add_info_format(pinfo, %s, &%s, \"%s\"",
587 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
588 $proto_tree_list[$_[0]][8]);
589 if ($proto_tree_list[$_[0]][11] ne "") {
590 $item_str .= ", $proto_tree_list[$_[0]][11]";
593 } elsif ($proto_tree_list[$_[0]][0] eq "12") {
594 $item_str = sprintf("proto_tree_add_expert(%s, pinfo, &%s, %s, %s, %s);",
595 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
596 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
597 $proto_tree_list[$_[0]][6]);
598 } elsif ($proto_tree_list[$_[0]][0] eq "13") {
599 $item_str = sprintf("proto_tree_add_expert_format(%s, pinfo, &%s, %s, %s, %s, \"%s\"",
600 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
601 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
602 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][8]);
603 if ($proto_tree_list[$_[0]][11] ne "") {
604 $item_str .= ", $proto_tree_list[$_[0]][11]";
616 # ---------------------------------------------------------------------
617 # Output the hf variable declarations. For now, write them to a file.
618 # XXX - Eventually find the right place to add it to the modified dissector file
626 open(FCO
, ">", $fileName . ".hf");
628 print FCO
"/* Generated from convert_proto_tree_add_text.pl */\n";
630 #add hfs to hash table to prevent against (accidental) duplicates
631 for ($index=0;$index<@proto_tree_list;$index++) {
632 if ($proto_tree_list[$index][1] eq "1") {
633 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
634 print FCO
"static int $proto_tree_list[$index][3] = -1;\n";
635 } elsif ($proto_tree_list[$index][1] eq "2") {
636 $eis{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
640 if (scalar keys %hfs > 0) {
644 print FCO
"/* Generated from convert_proto_tree_add_text.pl */\n";
646 foreach $key (keys %eis) {
647 print FCO
"static expert_field $key = EI_INIT;\n";
653 # ---------------------------------------------------------------------
654 # Output the hf array items. For now, write them to a file.
655 # XXX - Eventually find the right place to add it to the modified dissector file
656 # (bonus points if formatting of hf array in dissector file is kept)
657 sub output_hf_array
{
663 open(FCO
, ">", $fileName . ".hf_array");
665 print FCO
" /* Generated from convert_proto_tree_add_text.pl */\n";
667 for ($index=0;$index<@proto_tree_list;$index++) {
668 if ($proto_tree_list[$index][1] eq "1") {
669 if (exists($hfs{$proto_tree_list[$index][3]})) {
670 print "duplicate hf entry '$proto_tree_list[$index][3]' found! Aborting conversion.\n";
673 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
674 print FCO
" { &$proto_tree_list[$index][3], { \"$proto_tree_list[$index][8]\", \"$proto_tree_list[$index][10]\", ";
675 print FCO
"$proto_tree_list[$index][9], $proto_tree_list[$index][11], $proto_tree_list[$index][12], $proto_tree_list[$index][13], NULL, HFILL }},\r\n";
683 print FCO
" /* Generated from convert_proto_tree_add_text.pl */\n";
684 for ($index=0;$index<@expert_list;$index++) {
685 if (exists($eis{$expert_list[$index][3]})) {
686 print "duplicate ei entry '$expert_list[$index][3]' found! Aborting conversion.\n";
689 $eis{$expert_list[$index][3]} = $expert_list[$index][3];
691 print FCO
" { &$expert_list[$index][3], { \"$expert_list[$index][10]\", $expert_list[$index][7], ";
692 print FCO
"$expert_list[$index][9], \"$expert_list[$index][8]\", EXPFILL }},\r\n";
698 # ---------------------------------------------------------------------
699 # Find all proto_tree_add_text calls that have parameters passed in them
700 # and output number found
703 my( $fileContentsRef, $fileName) = @_;
713 (?
:proto_tree_add_text
)\s
* \
(
722 (?
:proto_tree_add_text
)\s
* \
(
730 while ($$fileContentsRef =~ / $pat /xgso) {
732 my @args = split(/,/, ${1});
734 #cleanup whitespace to show proto_tree_add_text in single line (easier for seeing grep results)
735 $str =~ tr/\t\n\r/ /d;
736 $str =~ s/ \s+ / /xg;
737 #print "$fileName: $str\n";
739 #find all instances where proto_tree_add_text has a tvb_get (or similar) call, because
740 #convert_proto_tree_add_text.pl has an easier time determining hf_ field values with it
741 if (scalar @args > 5) {
742 my $tvb = trim
($args[5]);
743 if ($tvb =~ /^tvb_/) {
752 if ($tvb_found > 0) {
753 $tvb_percent = 100*$tvb_found/$found;
755 printf "%s: Found %d proto_tree_add_text calls eligible for conversion, %d contain a \"tvb get\" call (%.2f%%).\n",
756 $fileName, $found, $tvb_found, $tvb_percent;
758 print "$fileName: Found $found proto_tree_add_text calls eligible for conversion, 0 \"tvb get\" calls.\n";