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_PCRE' => "FT_PCRE", '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");
103 # Perl trim function to remove whitespace from the start and end of the string
112 # ---------------------------------------------------------------------
117 my $action = 'generate';
121 my $result = GetOptions(
122 'action=s' => \$action,
123 'encoding=s' => \$encoding,
124 'expert' => \$expert,
125 'help|?' => \$helpFlag
128 if (!$result || $helpFlag || !$ARGV[0]) {
133 print "\nUsage: $0 [--action=generate|fix-all|find-all] [--encoding=ENC_BIG_ENDIAN|ENC_LITTLE_ENDIAN] FILENAME [...]\n\n";
134 print " --action = generate (default)\n";
135 print " generate - create a delimited file (FILENAME.proto_tree_input) with\n";
136 print " proto_tree_add_text fields in FILENAME(s)\n";
137 print " fix-all - Use delimited file (FILENAME.proto_tree_input) to convert\n";
138 print " proto_tree_add_text to proto_tree_add_item\n";
139 print " Also generates FILENAME.hf and FILENAME.hf_array to be\n";
140 print " copy/pasted into the dissector where appropriate\n";
141 print " find-all - Output the number of eligible proto_tree_add_text calls\n";
142 print " for conversion\n\n";
143 print " --expert (Optional) Includes proto_tree_add_text calls with no printf arguments in\n";
144 print " the .proto_tree_input file as they could be converted to expert info\n";
145 print " (otherwise they are ignored)\n";
146 print " Must be called for 'fix-all' if called on 'generate'\n";
147 print " --encoding (Optional) Default encoding if one can't be determined\n";
148 print " (effective only for generate)\n";
149 print " If not specified, an encoding will not be auto-populated\n";
150 print " if undetermined\n\n";
156 # XXX Outline general algorithm here
159 my $protabbrev_index;
162 while (my $fileName = $ARGV[0]) {
164 my $fileContents = '';
166 die "No such file: \"$fileName\"\n" if (! -e $fileName);
168 # delete leading './'
169 $fileName =~ s{ ^ \. / } {}xo;
171 #determine PROTABBREV for dissector based on file name format of (dirs)/packet-PROTABBREV.c
172 $protabbrev_index = rindex($fileName, "packet-");
173 if ($protabbrev_index == -1) {
174 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
178 $protabbrev = substr($fileName, $protabbrev_index+length("packet-"));
179 $protabbrev_index = rindex($protabbrev, ".");
180 if ($protabbrev_index == -1) {
181 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
184 $protabbrev = lc(substr($protabbrev, 0, $protabbrev_index));
186 # Read in the file (ouch, but it's easier that way)
187 open(FCI, "<", $fileName) || die("Couldn't open $fileName");
193 if ($action eq "generate") {
194 generate_hfs(\$fileContents, $fileName);
197 if ($action eq "fix-all") {
198 # Read in the hf "input" file
201 open(FCI, "<", $fileName . ".proto_tree_input") || die("Couldn't open $fileName.proto_tree_input");
202 while(my $line=<FCI>){
203 my @proto_tree_item = split(/;|\n/, $line);
206 $errors += verify_line(@proto_tree_item);
208 push(@proto_tree_list, \@proto_tree_item);
209 if ($proto_tree_item[1] eq "2") {
210 push(@expert_list, \@proto_tree_item);
216 print "Aborting conversion.\n";
220 fix_proto_tree_add_text(\$fileContents, $fileName);
222 # Write out the hf data
223 output_hf_array($fileName);
224 output_hf($fileName);
226 # Write out the changed version to a file
227 open(FCO, ">", $fileName . ".proto_tree_add_text");
228 print FCO "$fileContents";
232 if ($action eq "find-all") {
233 # Find all proto_tree_add_text() statements eligible for conversion
234 $found_total += find_all(\$fileContents, $fileName);
241 # ---------------------------------------------------------------------
242 # Sanity check the data in the .proto_tree_input file
244 my( @proto_tree_item) = @_;
247 #do some basic error checking of the file
248 if ($proto_tree_item[0] eq "1") {
249 if (!($proto_tree_item[3] =~ /^hf_/)) {
250 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
254 foreach (split(/\|/, $proto_tree_item[7])) {
255 if (!exists($ENCODINGS{$_})) {
256 print "$line_number: Encoding value '$_' unknown!\n";
260 } elsif (($proto_tree_item[0] eq "10") ||
261 ($proto_tree_item[0] eq "11") ||
262 ($proto_tree_item[0] eq "12") ||
263 ($proto_tree_item[0] eq "13")) {
264 #expert info conversions
265 if (!($proto_tree_item[3] =~ /^ei_/)) {
266 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
269 } elsif ($proto_tree_item[0] ne "0") {
270 print "Bad conversion value! Aborting conversion.\n";
274 if ($proto_tree_item[1] eq "1") {
275 if (!($proto_tree_item[3] =~ /^hf_/)) {
276 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
279 if (!exists($FIELD_TYPE{$proto_tree_item[9]})) {
280 print "$line_number: Field type '$proto_tree_item[9]' unknown!\n";
283 foreach (split(/\|/, $proto_tree_item[11])) {
284 if ((!exists($DISPLAY_BASE{$_})) &&
285 (!($proto_tree_item[11] =~ /\d+/))) {
286 print "$line_number: Display base '$proto_tree_item[11]' unknown!\n";
290 if (($proto_tree_item[9] eq "FT_UINT8") ||
291 ($proto_tree_item[9] eq "FT_UINT16") ||
292 ($proto_tree_item[9] eq "FT_UINT24") ||
293 ($proto_tree_item[9] eq "FT_UINT32") ||
294 ($proto_tree_item[9] eq "FT_UINT64") ||
295 ($proto_tree_item[9] eq "FT_INT8") ||
296 ($proto_tree_item[9] eq "FT_INT16") ||
297 ($proto_tree_item[9] eq "FT_INT24") ||
298 ($proto_tree_item[9] eq "FT_INT32") ||
299 ($proto_tree_item[9] eq "FT_INT64")) {
300 if ($proto_tree_item[11] eq "BASE_NONE") {
301 print "$line_number: Interger type should not be BASE_NONE!\n";
306 } elsif ($proto_tree_item[1] eq "2") {
307 if (!($proto_tree_item[3] =~ /^ei_/)) {
308 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
311 if (!exists($EXPERT_SEVERITY{$proto_tree_item[9]})) {
312 print "$line_number: Expert severity value '$proto_tree_item[9]' unknown!\n";
315 if (!exists($EXPERT_GROUPS{$proto_tree_item[7]})) {
316 print "$line_number: Expert group value '$proto_tree_item[7]' unknown!\n";
320 } elsif ($proto_tree_item[1] ne "0") {
321 print "$line_number: Bad hf/ei variable generation value!\n";
329 my( $fileContentsRef, $fileName) = @_;
339 (?:proto_tree_add_text)\s* \(
348 (?:proto_tree_add_text)\s* \(
356 while ($$fileContentsRef =~ / $pat /xgso) {
357 my @proto_tree_item = (1, 1, "tree", "hf_name", "tvb", "offset", "length", "encoding",
358 "fieldfullname", "fieldtype", "fieldabbrevname", "BASE_NONE", "NULL", "0x0");
360 $str =~ tr/\t\n\r/ /d;
361 $str =~ s/ \s+ / /xg;
362 #print "$fileName: $str\n";
364 @args = split(/,/, $str);
365 #printf "ARGS(%d): %s\n", scalar @args, join("# ", @args);
366 $args[0] =~ s/proto_tree_add_text\s*\(\s*//;
367 $proto_tree_item[2] = $args[0]; #tree
368 $proto_tree_item[4] = trim($args[1]); #tvb
369 $proto_tree_item[5] = trim($args[2]); #offset
370 $proto_tree_item[6] = trim($args[3]); #length
371 if (scalar @args == 5) {
372 #remove the "); at the end
373 $args[4] =~ s/\"\s*\)\s*;$//;
377 if (scalar @args > 5) {
378 if (($proto_tree_item[6] eq "1") ||
379 ($args[5] =~ /tvb_get_guint8/) ||
380 ($args[5] =~ /tvb_bytes_to_str/) ||
381 ($args[5] =~ /tvb_ether_to_str/)) {
382 $proto_tree_item[7] = "ENC_NA";
383 } elsif ($args[5] =~ /tvb_get_ntoh/) {
384 $proto_tree_item[7] = "ENC_BIG_ENDIAN";
385 } elsif ($args[5] =~ /tvb_get_letoh/) {
386 $proto_tree_item[7] = "ENC_LITTLE_ENDIAN";
387 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
388 ($args[5] =~ /tvb_format_text/)){
389 $proto_tree_item[7] = "ENC_NA|ENC_ASCII";
390 } elsif ($encoding ne "") {
391 $proto_tree_item[7] = $encoding;
396 if (($expert ne "") || (scalar @args > 5)) {
397 my @arg_temp = split(/=|:/, $args[4]);
398 $proto_tree_item[8] = $arg_temp[0];
400 $proto_tree_item[8] = $args[4];
402 $proto_tree_item[8] =~ s/\"//;
403 $proto_tree_item[8] = trim($proto_tree_item[8]);
405 if ($proto_tree_item[8] eq "%s\"") {
406 #assume proto_tree_add_text will not be converted
407 $proto_tree_item[0] = 0;
408 $proto_tree_item[1] = 0;
409 $proto_tree_item[3] = sprintf("hf_%s_", $protabbrev);
410 $proto_tree_item[10] = sprintf("%s.", $protabbrev);
413 $proto_tree_item[3] = sprintf("hf_%s_%s", $protabbrev, lc($proto_tree_item[8]));
414 $proto_tree_item[3] =~ s/\s+|-|:/_/g;
416 #field abbreviated name
417 $proto_tree_item[10] = sprintf("%s.%s", $protabbrev, lc($proto_tree_item[8]));
418 $proto_tree_item[10] =~ s/\s+|-|:/_/g;
422 if ($str =~ /val_to_str(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
423 $proto_tree_item[12] = sprintf("VALS(%s)", trim($2));
424 } elsif ($str =~ /val_to_str(_const)?\([^\,]*\,([^\,]*)\,/) {
425 $proto_tree_item[12] = sprintf("VALS(%s)", trim($2));
426 } elsif ($str =~ /val_to_str_ext(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
427 $proto_tree_item[12] = trim($2);
428 } elsif ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
429 $proto_tree_item[12] = trim($2);
433 if (scalar @args > 5) {
434 if ($args[5] =~ /tvb_get_guint8/) {
435 if ($args[4] =~ /%[0-9]*[i]/) {
436 $proto_tree_item[9] = "FT_INT8";
438 $proto_tree_item[9] = "FT_UINT8";
440 } elsif ($args[5] =~ /tvb_get_(n|"le")tohs/) {
441 if ($args[4] =~ /%[0-9]*[i]/) {
442 $proto_tree_item[9] = "FT_INT16";
444 $proto_tree_item[9] = "FT_UINT16";
446 } elsif ($args[5] =~ /tvb_get_(n|"le")toh24/) {
447 if ($args[4] =~ /%[0-9]*[i]/) {
448 $proto_tree_item[9] = "FT_INT24";
450 $proto_tree_item[9] = "FT_UINT24";
452 } elsif ($args[5] =~ /tvb_get_(n|"le")tohl/) {
453 if ($args[4] =~ /%[0-9]*[i]/) {
454 $proto_tree_item[9] = "FT_INT32";
456 $proto_tree_item[9] = "FT_UINT32";
458 } elsif ($args[5] =~ /tvb_get_(n|"le")toh("40"|"48"|"56"|"64")/) {
459 if ($args[4] =~ /%[0-9]*[i]/) {
460 $proto_tree_item[9] = "FT_INT64";
462 $proto_tree_item[9] = "FT_UINT64";
464 } elsif (($args[5] =~ /tvb_get_(n|"le")tohieee_float/) ||
465 ($args[4] =~ /%[0-9\.]*[fFeEgG]/)) {
466 $proto_tree_item[9] = "FT_FLOAT";
467 } elsif ($args[5] =~ /tvb_get_(n|"le")tohieee_double/) {
468 $proto_tree_item[9] = "FT_DOUBLE";
469 } elsif (($args[5] =~ /tvb_get_ipv4/) ||
470 ($args[5] =~ /tvb_ip_to_str/)) {
471 $proto_tree_item[9] = "FT_IPv4";
472 } elsif (($args[5] =~ /tvb_get_ipv6/) ||
473 ($args[5] =~ /tvb_ip6_to_str/)) {
474 $proto_tree_item[9] = "FT_IPv6";
475 } elsif ($args[5] =~ /tvb_get_(n|"le")tohguid/) {
476 $proto_tree_item[9] = "FT_GUID";
477 } elsif ($args[5] =~ /tvb_get_ephemeral_stringz/) {
478 $proto_tree_item[9] = "FT_STRINGZ";
479 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
480 ($args[5] =~ /tvb_format_text/)){
481 $proto_tree_item[9] = "FT_STRING";
482 } elsif (($args[5] =~ /tvb_bytes_to_str/)) {
483 $proto_tree_item[9] = "FT_BYTES";
484 } elsif ($args[5] =~ /tvb_ether_to_str/) {
485 $proto_tree_item[9] = "FT_ETHER";
488 #if we still can't determine type, assume a constant length
489 #value means we have an unsigned value
490 if ($proto_tree_item[9] eq "fieldtype") {
491 my $len_str = trim($args[3]);
492 if ($len_str eq "1") {
493 $proto_tree_item[9] = "FT_UINT8";
494 } elsif ($len_str eq "2") {
495 $proto_tree_item[9] = "FT_UINT16";
496 } elsif ($len_str eq "3") {
497 $proto_tree_item[9] = "FT_UINT24";
498 } elsif ($len_str eq "4") {
499 $proto_tree_item[9] = "FT_UINT32";
500 } elsif ($len_str eq "8") {
501 $proto_tree_item[9] = "FT_UINT64";
507 if ($args[4] =~ /%[0-9]*[xX]/) {
508 $proto_tree_item[11] = "BASE_HEX";
509 } elsif ($args[4] =~ /%[0-9]*[uld]/) {
510 $proto_tree_item[11] = "BASE_DEC";
511 } elsif ($args[4] =~ /%[0-9]*o/) {
512 $proto_tree_item[11] = "BASE_OCT";
514 if ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
515 $proto_tree_item[11] .= "|BASE_EXT_STRING";
518 if (($proto_tree_item[7] eq "encoding") && ($proto_tree_item[9] eq "FT_BYTES")) {
519 $proto_tree_item[7] = "ENC_NA";
522 push(@proto_tree_list, \@proto_tree_item);
527 if ($num_items > 0) {
528 open(FCO, ">", $fileName . ".proto_tree_input");
529 for my $item (@proto_tree_list) {
530 print FCO join(";", @{$item}), "\n";
536 # ---------------------------------------------------------------------
537 # Find all proto_tree_add_text calls and replace them with the data
538 # found in proto_tree_list
539 sub fix_proto_tree_add_text {
540 my( $fileContentsRef, $fileName) = @_;
547 (?:proto_tree_add_text)\s* \(
556 (?:proto_tree_add_text)\s* \(
564 $$fileContentsRef =~ s/ $pat /patsub($found, $1)/xges;
567 # ---------------------------------------------------------------------
568 # Format proto_tree_add_item or expert info functions with proto_tree_list data
571 if ($proto_tree_list[$_[0]][0] eq "1") {
572 $item_str = sprintf("proto_tree_add_item(%s, %s, %s, %s, %s, %s);",
573 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
574 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
575 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][7]);
576 } elsif ($proto_tree_list[$_[0]][0] eq "10") {
577 $item_str = sprintf("expert_add_info(pinfo, %s, &%s);",
578 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3]);
579 } elsif ($proto_tree_list[$_[0]][0] eq "11") {
580 $item_str = sprintf("expert_add_info_format(pinfo, %s, &%s, \"%s\"",
581 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
582 $proto_tree_list[$_[0]][8]);
583 if ($proto_tree_list[$_[0]][11] ne "") {
584 $item_str .= ", $proto_tree_list[$_[0]][11]";
587 } elsif ($proto_tree_list[$_[0]][0] eq "12") {
588 $item_str = sprintf("proto_tree_add_expert(%s, pinfo, &%s, %s, %s, %s);",
589 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
590 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
591 $proto_tree_list[$_[0]][6]);
592 } elsif ($proto_tree_list[$_[0]][0] eq "13") {
593 $item_str = sprintf("proto_tree_add_expert_format(%s, pinfo, &%s, %s, %s, %s, \"%s\"",
594 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
595 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
596 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][8]);
597 if ($proto_tree_list[$_[0]][11] ne "") {
598 $item_str .= ", $proto_tree_list[$_[0]][11]";
610 # ---------------------------------------------------------------------
611 # Output the hf variable declarations. For now, write them to a file.
612 # XXX - Eventually find the right place to add it to the modified dissector file
620 open(FCO, ">", $fileName . ".hf");
622 print FCO "/* Generated from convert_proto_tree_add_text.pl */\n";
624 #add hfs to hash table to prevent against (accidental) duplicates
625 for ($index=0;$index<@proto_tree_list;$index++) {
626 if ($proto_tree_list[$index][1] eq "1") {
627 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
628 print FCO "static int $proto_tree_list[$index][3] = -1;\n";
629 } elsif ($proto_tree_list[$index][1] eq "2") {
630 $eis{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
634 if (scalar keys %hfs > 0) {
638 print FCO "/* Generated from convert_proto_tree_add_text.pl */\n";
640 foreach $key (keys %eis) {
641 print FCO "static expert_field $key = EI_INIT;\n";
647 # ---------------------------------------------------------------------
648 # Output the hf array items. For now, write them to a file.
649 # XXX - Eventually find the right place to add it to the modified dissector file
650 # (bonus points if formatting of hf array in dissector file is kept)
651 sub output_hf_array {
657 open(FCO, ">", $fileName . ".hf_array");
659 print FCO " /* Generated from convert_proto_tree_add_text.pl */\n";
661 for ($index=0;$index<@proto_tree_list;$index++) {
662 if ($proto_tree_list[$index][1] eq "1") {
663 if (exists($hfs{$proto_tree_list[$index][3]})) {
664 print "duplicate hf entry '$proto_tree_list[$index][3]' found! Aborting conversion.\n";
667 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
668 print FCO " { &$proto_tree_list[$index][3], { \"$proto_tree_list[$index][8]\", \"$proto_tree_list[$index][10]\", ";
669 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";
677 print FCO " /* Generated from convert_proto_tree_add_text.pl */\n";
678 for ($index=0;$index<@expert_list;$index++) {
679 if (exists($eis{$expert_list[$index][3]})) {
680 print "duplicate ei entry '$expert_list[$index][3]' found! Aborting conversion.\n";
683 $eis{$expert_list[$index][3]} = $expert_list[$index][3];
685 print FCO " { &$expert_list[$index][3], { \"$expert_list[$index][10]\", $expert_list[$index][7], ";
686 print FCO "$expert_list[$index][9], \"$expert_list[$index][8]\", EXPFILL }},\r\n";
692 # ---------------------------------------------------------------------
693 # Find all proto_tree_add_text calls that have parameters passed in them
694 # and output number found
697 my( $fileContentsRef, $fileName) = @_;
707 (?:proto_tree_add_text)\s* \(
716 (?:proto_tree_add_text)\s* \(
724 while ($$fileContentsRef =~ / $pat /xgso) {
726 my @args = split(/,/, ${1});
728 #cleanup whitespace to show proto_tree_add_text in single line (easier for seeing grep results)
729 $str =~ tr/\t\n\r/ /d;
730 $str =~ s/ \s+ / /xg;
731 #print "$fileName: $str\n";
733 #find all instances where proto_tree_add_text has a tvb_get (or similar) call, because
734 #convert_proto_tree_add_text.pl has an easier time determining hf_ field values with it
735 if (scalar @args > 5) {
736 my $tvb = trim($args[5]);
737 if ($tvb =~ /^tvb_/) {
746 if ($tvb_found > 0) {
747 $tvb_percent = 100*$tvb_found/$found;
749 printf "%s: Found %d proto_tree_add_text calls eligible for conversion, %d contain a \"tvb get\" call (%.2f%%).\n",
750 $fileName, $found, $tvb_found, $tvb_percent;
752 print "$fileName: Found $found proto_tree_add_text calls eligible for conversion, 0 \"tvb get\" calls.\n";