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 # This program is free software; you can redistribute it and/or
40 # modify it under the terms of the GNU General Public License
41 # as published by the Free Software Foundation; either version 2
42 # of the License, or (at your option) any later version.
44 # This program is distributed in the hope that it will be useful,
45 # but WITHOUT ANY WARRANTY; without even the implied warranty of
46 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47 # GNU General Public License for more details.
49 # You should have received a copy of the GNU General Public License
50 # along with this program; if not, write to the Free Software
51 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
59 my %DISPLAY_BASE = ('BASE_NONE' => "BASE_NONE",
60 'BASE_DEC' => "BASE_DEC",
61 'BASE_HEX' => "BASE_HEX",
62 'BASE_OCT' => "BASE_OCT",
63 'BASE_DEC_HEX' => "BASE_DEC_HEX",
64 'BASE_HEX_DEC' => "BASE_HEX_DEC",
65 'BASE_EXT_STRING' => "BASE_EXT_STRING",
66 'BASE_RANGE_STRING' => "BASE_RANGE_STRING",
67 'ABSOLUTE_TIME_LOCAL' => "ABSOLUTE_TIME_LOCAL",
68 'ABSOLUTE_TIME_UTC' => "ABSOLUTE_TIME_UTC",
69 'ABSOLUTE_TIME_DOY_UTC' => "ABSOLUTE_TIME_DOY_UTC",
70 'BASE_CUSTOM' => "BASE_CUSTOM");
72 my %ENCODINGS = ('ENC_BIG_ENDIAN' => "ENC_BIG_ENDIAN",
73 'ENC_LITTLE_ENDIAN' => "ENC_LITTLE_ENDIAN",
74 'ENC_TIME_TIMESPEC' => "ENC_TIME_TIMESPEC",
75 'ENC_TIME_NTP' => "ENC_TIME_NTP",
76 'ENC_ASCII' => "ENC_ASCII",
77 'ENC_UTF_8' => "ENC_UTF_8",
78 'ENC_UTF_16' => "ENC_UTF_16",
79 'ENC_UCS_2' => "ENC_UCS_2",
80 'ENC_EBCDIC' => "ENC_EBCDIC",
81 'ENC_NA' => "ENC_NA");
83 my %FIELD_TYPE = ('FT_NONE' => "FT_NONE", 'FT_PROTOCOL' => "FT_PROTOCOL", 'FT_BOOLEAN' => "FT_BOOLEAN",
84 'FT_UINT8' => "FT_UINT8", 'FT_UINT16' => "FT_UINT16", 'FT_UINT24' => "FT_UINT24", 'FT_UINT32' => "FT_UINT32", 'FT_UINT64' => "FT_UINT64",
85 'FT_INT8' => "FT_INT8", 'FT_INT16' => "FT_INT16", 'FT_INT24' => "FT_INT24", 'FT_INT32' => "FT_INT32", 'FT_INT64' => "FT_INT64",
86 'FT_FLOAT' => "FT_FLOAT", 'FT_DOUBLE' => "FT_DOUBLE",
87 'FT_ABSOLUTE_TIME' => "FT_ABSOLUTE_TIME", 'FT_RELATIVE_TIME' => "FT_RELATIVE_TIME",
88 'FT_STRING' => "FT_STRING", 'FT_STRINGZ' => "FT_STRINGZ", 'FT_UINT_STRING' => "FT_UINT_STRING",
89 'FT_ETHER' => "FT_ETHER", 'FT_BYTES' => "FT_BYTES", 'FT_UINT_BYTES' => "FT_UINT_BYTES",
90 'FT_IPv4' => "FT_IPv4", 'FT_IPv6' => "FT_IPv6", 'FT_IPXNET' => "FT_IPXNET", 'FT_AX25' => "FT_AX25", 'FT_VINES' => "FT_VINES",
91 '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");
93 my %EXPERT_SEVERITY = ('PI_COMMENT' => "PI_COMMENT",
94 'PI_CHAT' => "PI_CHAT",
95 'PI_NOTE' => "PI_NOTE",
96 'PI_WARN' => "PI_WARN",
97 'PI_ERROR' => "PI_ERROR");
99 my %EXPERT_GROUPS = ('PI_CHECKSUM' => "PI_CHECKSUM",
100 'PI_SEQUENCE' => "PI_SEQUENCE",
101 'PI_RESPONSE_CODE' => "PI_RESPONSE_CODE",
102 'PI_REQUEST_CODE' => "PI_REQUEST_CODE",
103 'PI_UNDECODED' => "PI_UNDECODED",
104 'PI_REASSEMBLE' => "PI_REASSEMBLE",
105 'PI_MALFORMED' => "PI_MALFORMED",
106 'PI_DEBUG' => "PI_DEBUG",
107 'PI_PROTOCOL' => "PI_PROTOCOL",
108 'PI_SECURITY' => "PI_SECURITY",
109 'PI_COMMENTS_GROUP' => "PI_COMMENTS_GROUP");
115 # Perl trim function to remove whitespace from the start and end of the string
124 # ---------------------------------------------------------------------
129 my $action = 'generate';
133 my $result = GetOptions(
134 'action=s' => \$action,
135 'encoding=s' => \$encoding,
136 'expert' => \$expert,
137 'help|?' => \$helpFlag
140 if (!$result || $helpFlag || !$ARGV[0]) {
145 print "\nUsage: $0 [--action=generate|fix-all|find-all] [--encoding=ENC_BIG_ENDIAN|ENC_LITTLE_ENDIAN] FILENAME [...]\n\n";
146 print " --action = generate (default)\n";
147 print " generate - create a delimited file (FILENAME.proto_tree_input) with\n";
148 print " proto_tree_add_text fields in FILENAME(s)\n";
149 print " fix-all - Use delimited file (FILENAME.proto_tree_input) to convert\n";
150 print " proto_tree_add_text to proto_tree_add_item\n";
151 print " Also generates FILENAME.hf and FILENAME.hf_array to be\n";
152 print " copy/pasted into the dissector where appropriate\n";
153 print " find-all - Output the number of eligible proto_tree_add_text calls\n";
154 print " for conversion\n\n";
155 print " --expert (Optional) Includes proto_tree_add_text calls with no printf arguments in\n";
156 print " the .proto_tree_input file as they could be converted to expert info\n";
157 print " (otherwise they are ignored)\n";
158 print " Must be called for 'fix-all' if called on 'generate'\n";
159 print " --encoding (Optional) Default encoding if one can't be determined\n";
160 print " (effective only for generate)\n";
161 print " If not specified, an encoding will not be auto-populated\n";
162 print " if undetermined\n\n";
168 # XXX Outline general algorithm here
171 my $protabbrev_index;
174 while (my $fileName = $ARGV[0]) {
176 my $fileContents = '';
178 die "No such file: \"$fileName\"\n" if (! -e $fileName);
180 # delete leading './'
181 $fileName =~ s{ ^ \. / } {}xo;
183 #determine PROTABBREV for dissector based on file name format of (dirs)/packet-PROTABBREV.c
184 $protabbrev_index = rindex($fileName, "packet-");
185 if ($protabbrev_index == -1) {
186 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
190 $protabbrev = substr($fileName, $protabbrev_index+length("packet-"));
191 $protabbrev_index = rindex($protabbrev, ".");
192 if ($protabbrev_index == -1) {
193 print "$fileName doesn't fit format of packet-PROTABBREV.c\n";
196 $protabbrev = lc(substr($protabbrev, 0, $protabbrev_index));
198 # Read in the file (ouch, but it's easier that way)
199 open(FCI, "<", $fileName) || die("Couldn't open $fileName");
205 if ($action eq "generate") {
206 generate_hfs(\$fileContents, $fileName);
209 if ($action eq "fix-all") {
210 # Read in the hf "input" file
213 open(FCI, "<", $fileName . ".proto_tree_input") || die("Couldn't open $fileName.proto_tree_input");
214 while(my $line=<FCI>){
215 my @proto_tree_item = split(/;|\n/, $line);
218 $errors += verify_line(@proto_tree_item);
220 push(@proto_tree_list, \@proto_tree_item);
221 if ($proto_tree_item[1] eq "2") {
222 push(@expert_list, \@proto_tree_item);
228 print "Aborting conversion.\n";
232 fix_proto_tree_add_text(\$fileContents, $fileName);
234 # Write out the hf data
235 output_hf_array($fileName);
236 output_hf($fileName);
238 # Write out the changed version to a file
239 open(FCO, ">", $fileName . ".proto_tree_add_text");
240 print FCO "$fileContents";
244 if ($action eq "find-all") {
245 # Find all proto_tree_add_text() statements eligible for conversion
246 $found_total += find_all(\$fileContents, $fileName);
253 # ---------------------------------------------------------------------
254 # Sanity check the data in the .proto_tree_input file
256 my( @proto_tree_item) = @_;
259 #do some basic error checking of the file
260 if ($proto_tree_item[0] eq "1") {
261 if (!($proto_tree_item[3] =~ /^hf_/)) {
262 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
266 foreach (split(/\|/, $proto_tree_item[7])) {
267 if (!exists($ENCODINGS{$_})) {
268 print "$line_number: Encoding value '$_' unknown!\n";
272 } elsif (($proto_tree_item[0] eq "10") ||
273 ($proto_tree_item[0] eq "11") ||
274 ($proto_tree_item[0] eq "12") ||
275 ($proto_tree_item[0] eq "13")) {
276 #expert info conversions
277 if (!($proto_tree_item[3] =~ /^ei_/)) {
278 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
281 } elsif ($proto_tree_item[0] ne "0") {
282 print "Bad conversion value! Aborting conversion.\n";
286 if ($proto_tree_item[1] eq "1") {
287 if (!($proto_tree_item[3] =~ /^hf_/)) {
288 print "$line_number: Poorly formed hf_ variable ($proto_tree_item[3])!\n";
291 if (!exists($FIELD_TYPE{$proto_tree_item[9]})) {
292 print "$line_number: Field type '$proto_tree_item[9]' unknown!\n";
295 foreach (split(/\|/, $proto_tree_item[11])) {
296 if ((!exists($DISPLAY_BASE{$_})) &&
297 (!($proto_tree_item[11] =~ /\d+/))) {
298 print "$line_number: Display base '$proto_tree_item[11]' unknown!\n";
302 if (($proto_tree_item[9] eq "FT_UINT8") ||
303 ($proto_tree_item[9] eq "FT_UINT16") ||
304 ($proto_tree_item[9] eq "FT_UINT24") ||
305 ($proto_tree_item[9] eq "FT_UINT32") ||
306 ($proto_tree_item[9] eq "FT_UINT64") ||
307 ($proto_tree_item[9] eq "FT_INT8") ||
308 ($proto_tree_item[9] eq "FT_INT16") ||
309 ($proto_tree_item[9] eq "FT_INT24") ||
310 ($proto_tree_item[9] eq "FT_INT32") ||
311 ($proto_tree_item[9] eq "FT_INT64")) {
312 if ($proto_tree_item[11] eq "BASE_NONE") {
313 print "$line_number: Interger type should not be BASE_NONE!\n";
318 } elsif ($proto_tree_item[1] eq "2") {
319 if (!($proto_tree_item[3] =~ /^ei_/)) {
320 print "$line_number: Poorly formed ei_ variable ($proto_tree_item[3])!\n";
323 if (!exists($EXPERT_SEVERITY{$proto_tree_item[9]})) {
324 print "$line_number: Expert severity value '$proto_tree_item[9]' unknown!\n";
327 if (!exists($EXPERT_GROUPS{$proto_tree_item[7]})) {
328 print "$line_number: Expert group value '$proto_tree_item[7]' unknown!\n";
332 } elsif ($proto_tree_item[1] ne "0") {
333 print "$line_number: Bad hf/ei variable generation value!\n";
341 my( $fileContentsRef, $fileName) = @_;
351 (?:proto_tree_add_text)\s* \(
360 (?:proto_tree_add_text)\s* \(
368 while ($$fileContentsRef =~ / $pat /xgso) {
369 my @proto_tree_item = (1, 1, "tree", "hf_name", "tvb", "offset", "length", "encoding",
370 "fieldfullname", "fieldtype", "fieldabbrevname", "BASE_NONE", "NULL", "0x0");
372 $str =~ tr/\t\n\r/ /d;
373 $str =~ s/ \s+ / /xg;
374 #print "$fileName: $str\n";
376 @args = split(/,/, $str);
377 #printf "ARGS(%d): %s\n", scalar @args, join("# ", @args);
378 $args[0] =~ s/proto_tree_add_text\s*\(\s*//;
379 $proto_tree_item[2] = $args[0]; #tree
380 $proto_tree_item[4] = trim($args[1]); #tvb
381 $proto_tree_item[5] = trim($args[2]); #offset
382 $proto_tree_item[6] = trim($args[3]); #length
383 if (scalar @args == 5) {
384 #remove the "); at the end
385 $args[4] =~ s/\"\s*\)\s*;$//;
389 if (scalar @args > 5) {
390 if (($proto_tree_item[6] eq "1") ||
391 ($args[5] =~ /tvb_get_guint8/) ||
392 ($args[5] =~ /tvb_bytes_to_str/) ||
393 ($args[5] =~ /tvb_ether_to_str/)) {
394 $proto_tree_item[7] = "ENC_NA";
395 } elsif ($args[5] =~ /tvb_get_ntoh/) {
396 $proto_tree_item[7] = "ENC_BIG_ENDIAN";
397 } elsif ($args[5] =~ /tvb_get_letoh/) {
398 $proto_tree_item[7] = "ENC_LITTLE_ENDIAN";
399 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
400 ($args[5] =~ /tvb_format_text/)){
401 $proto_tree_item[7] = "ENC_NA|ENC_ASCII";
402 } elsif ($encoding ne "") {
403 $proto_tree_item[7] = $encoding;
408 if (($expert ne "") || (scalar @args > 5)) {
409 my @arg_temp = split(/=|:/, $args[4]);
410 $proto_tree_item[8] = $arg_temp[0];
412 $proto_tree_item[8] = $args[4];
414 $proto_tree_item[8] =~ s/\"//;
415 $proto_tree_item[8] = trim($proto_tree_item[8]);
417 if ($proto_tree_item[8] eq "%s\"") {
418 #assume proto_tree_add_text will not be converted
419 $proto_tree_item[0] = 0;
420 $proto_tree_item[1] = 0;
421 $proto_tree_item[3] = sprintf("hf_%s_", $protabbrev);
422 $proto_tree_item[10] = sprintf("%s.", $protabbrev);
425 $proto_tree_item[3] = sprintf("hf_%s_%s", $protabbrev, lc($proto_tree_item[8]));
426 $proto_tree_item[3] =~ s/\s+|-|:/_/g;
428 #field abbreviated name
429 $proto_tree_item[10] = sprintf("%s.%s", $protabbrev, lc($proto_tree_item[8]));
430 $proto_tree_item[10] =~ s/\s+|-|:/_/g;
434 if ($str =~ /val_to_str(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
435 $proto_tree_item[12] = sprintf("VALS(%s)", trim($2));
436 } elsif ($str =~ /val_to_str(_const)?\([^\,]*\,([^\,]*)\,/) {
437 $proto_tree_item[12] = sprintf("VALS(%s)", trim($2));
438 } elsif ($str =~ /val_to_str_ext(_const)?\(\s*tvb_get_[^\(]*\([^\,]*,[^\)]*\)\s*\,\s*([^\,]*)\s*\,\s*([^\)]*)\)/) {
439 $proto_tree_item[12] = trim($2);
440 } elsif ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
441 $proto_tree_item[12] = trim($2);
445 if (scalar @args > 5) {
446 if ($args[5] =~ /tvb_get_guint8/) {
447 if ($args[4] =~ /%[0-9]*[i]/) {
448 $proto_tree_item[9] = "FT_INT8";
450 $proto_tree_item[9] = "FT_UINT8";
452 } elsif ($args[5] =~ /tvb_get_(n|"le")tohs/) {
453 if ($args[4] =~ /%[0-9]*[i]/) {
454 $proto_tree_item[9] = "FT_INT16";
456 $proto_tree_item[9] = "FT_UINT16";
458 } elsif ($args[5] =~ /tvb_get_(n|"le")toh24/) {
459 if ($args[4] =~ /%[0-9]*[i]/) {
460 $proto_tree_item[9] = "FT_INT24";
462 $proto_tree_item[9] = "FT_UINT24";
464 } elsif ($args[5] =~ /tvb_get_(n|"le")tohl/) {
465 if ($args[4] =~ /%[0-9]*[i]/) {
466 $proto_tree_item[9] = "FT_INT32";
468 $proto_tree_item[9] = "FT_UINT32";
470 } elsif ($args[5] =~ /tvb_get_(n|"le")toh("40"|"48"|"56"|"64")/) {
471 if ($args[4] =~ /%[0-9]*[i]/) {
472 $proto_tree_item[9] = "FT_INT64";
474 $proto_tree_item[9] = "FT_UINT64";
476 } elsif (($args[5] =~ /tvb_get_(n|"le")tohieee_float/) ||
477 ($args[4] =~ /%[0-9\.]*[fFeEgG]/)) {
478 $proto_tree_item[9] = "FT_FLOAT";
479 } elsif ($args[5] =~ /tvb_get_(n|"le")tohieee_double/) {
480 $proto_tree_item[9] = "FT_DOUBLE";
481 } elsif (($args[5] =~ /tvb_get_ipv4/) ||
482 ($args[5] =~ /tvb_ip_to_str/)) {
483 $proto_tree_item[9] = "FT_IPv4";
484 } elsif (($args[5] =~ /tvb_get_ipv6/) ||
485 ($args[5] =~ /tvb_ip6_to_str/)) {
486 $proto_tree_item[9] = "FT_IPv6";
487 } elsif ($args[5] =~ /tvb_get_(n|"le")tohguid/) {
488 $proto_tree_item[9] = "FT_GUID";
489 } elsif ($args[5] =~ /tvb_get_ephemeral_stringz/) {
490 $proto_tree_item[9] = "FT_STRINGZ";
491 } elsif (($args[5] =~ /tvb_get_ephemeral_string/) ||
492 ($args[5] =~ /tvb_format_text/)){
493 $proto_tree_item[9] = "FT_STRING";
494 } elsif (($args[5] =~ /tvb_bytes_to_str/)) {
495 $proto_tree_item[9] = "FT_BYTES";
496 } elsif ($args[5] =~ /tvb_ether_to_str/) {
497 $proto_tree_item[9] = "FT_ETHER";
500 #if we still can't determine type, assume a constant length
501 #value means we have an unsigned value
502 if ($proto_tree_item[9] eq "fieldtype") {
503 my $len_str = trim($args[3]);
504 if ($len_str eq "1") {
505 $proto_tree_item[9] = "FT_UINT8";
506 } elsif ($len_str eq "2") {
507 $proto_tree_item[9] = "FT_UINT16";
508 } elsif ($len_str eq "3") {
509 $proto_tree_item[9] = "FT_UINT24";
510 } elsif ($len_str eq "4") {
511 $proto_tree_item[9] = "FT_UINT32";
512 } elsif ($len_str eq "8") {
513 $proto_tree_item[9] = "FT_UINT64";
519 if ($args[4] =~ /%[0-9]*[xX]/) {
520 $proto_tree_item[11] = "BASE_HEX";
521 } elsif ($args[4] =~ /%[0-9]*[uld]/) {
522 $proto_tree_item[11] = "BASE_DEC";
523 } elsif ($args[4] =~ /%[0-9]*o/) {
524 $proto_tree_item[11] = "BASE_OCT";
526 if ($str =~ /val_to_str_ext(_const)?\([^\,]*\,([^\,]*)\,/) {
527 $proto_tree_item[11] .= "|BASE_EXT_STRING";
530 if (($proto_tree_item[7] eq "encoding") && ($proto_tree_item[9] eq "FT_BYTES")) {
531 $proto_tree_item[7] = "ENC_NA";
534 push(@proto_tree_list, \@proto_tree_item);
539 if ($num_items > 0) {
540 open(FCO, ">", $fileName . ".proto_tree_input");
541 for my $item (@proto_tree_list) {
542 print FCO join(";", @{$item}), "\n";
548 # ---------------------------------------------------------------------
549 # Find all proto_tree_add_text calls and replace them with the data
550 # found in proto_tree_list
551 sub fix_proto_tree_add_text {
552 my( $fileContentsRef, $fileName) = @_;
559 (?:proto_tree_add_text)\s* \(
568 (?:proto_tree_add_text)\s* \(
576 $$fileContentsRef =~ s/ $pat /patsub($found, $1)/xges;
579 # ---------------------------------------------------------------------
580 # Format proto_tree_add_item or expert info functions with proto_tree_list data
583 if ($proto_tree_list[$_[0]][0] eq "1") {
584 $item_str = sprintf("proto_tree_add_item(%s, %s, %s, %s, %s, %s);",
585 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
586 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
587 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][7]);
588 } elsif ($proto_tree_list[$_[0]][0] eq "10") {
589 $item_str = sprintf("expert_add_info(pinfo, %s, &%s);",
590 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3]);
591 } elsif ($proto_tree_list[$_[0]][0] eq "11") {
592 $item_str = sprintf("expert_add_info_format(pinfo, %s, &%s, \"%s\"",
593 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
594 $proto_tree_list[$_[0]][8]);
595 if ($proto_tree_list[$_[0]][11] ne "") {
596 $item_str .= ", $proto_tree_list[$_[0]][11]";
599 } elsif ($proto_tree_list[$_[0]][0] eq "12") {
600 $item_str = sprintf("proto_tree_add_expert(%s, pinfo, &%s, %s, %s, %s);",
601 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
602 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
603 $proto_tree_list[$_[0]][6]);
604 } elsif ($proto_tree_list[$_[0]][0] eq "13") {
605 $item_str = sprintf("proto_tree_add_expert_format(%s, pinfo, &%s, %s, %s, %s, \"%s\"",
606 $proto_tree_list[$_[0]][2], $proto_tree_list[$_[0]][3],
607 $proto_tree_list[$_[0]][4], $proto_tree_list[$_[0]][5],
608 $proto_tree_list[$_[0]][6], $proto_tree_list[$_[0]][8]);
609 if ($proto_tree_list[$_[0]][11] ne "") {
610 $item_str .= ", $proto_tree_list[$_[0]][11]";
622 # ---------------------------------------------------------------------
623 # Output the hf variable declarations. For now, write them to a file.
624 # XXX - Eventually find the right place to add it to the modified dissector file
632 open(FCO, ">", $fileName . ".hf");
634 print FCO "/* Generated from convert_proto_tree_add_text.pl */\n";
636 #add hfs to hash table to prevent against (accidental) duplicates
637 for ($index=0;$index<@proto_tree_list;$index++) {
638 if ($proto_tree_list[$index][1] eq "1") {
639 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
640 print FCO "static int $proto_tree_list[$index][3] = -1;\n";
641 } elsif ($proto_tree_list[$index][1] eq "2") {
642 $eis{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
646 if (scalar keys %hfs > 0) {
650 print FCO "/* Generated from convert_proto_tree_add_text.pl */\n";
652 foreach $key (keys %eis) {
653 print FCO "static expert_field $key = EI_INIT;\n";
659 # ---------------------------------------------------------------------
660 # Output the hf array items. For now, write them to a file.
661 # XXX - Eventually find the right place to add it to the modified dissector file
662 # (bonus points if formatting of hf array in dissector file is kept)
663 sub output_hf_array {
669 open(FCO, ">", $fileName . ".hf_array");
671 print FCO " /* Generated from convert_proto_tree_add_text.pl */\n";
673 for ($index=0;$index<@proto_tree_list;$index++) {
674 if ($proto_tree_list[$index][1] eq "1") {
675 if (exists($hfs{$proto_tree_list[$index][3]})) {
676 print "duplicate hf entry '$proto_tree_list[$index][3]' found! Aborting conversion.\n";
679 $hfs{$proto_tree_list[$index][3]} = $proto_tree_list[$index][3];
680 print FCO " { &$proto_tree_list[$index][3], { \"$proto_tree_list[$index][8]\", \"$proto_tree_list[$index][10]\", ";
681 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";
689 print FCO " /* Generated from convert_proto_tree_add_text.pl */\n";
690 for ($index=0;$index<@expert_list;$index++) {
691 if (exists($eis{$expert_list[$index][3]})) {
692 print "duplicate ei entry '$expert_list[$index][3]' found! Aborting conversion.\n";
695 $eis{$expert_list[$index][3]} = $expert_list[$index][3];
697 print FCO " { &$expert_list[$index][3], { \"$expert_list[$index][10]\", $expert_list[$index][7], ";
698 print FCO "$expert_list[$index][9], \"$expert_list[$index][8]\", EXPFILL }},\r\n";
704 # ---------------------------------------------------------------------
705 # Find all proto_tree_add_text calls that have parameters passed in them
706 # and output number found
709 my( $fileContentsRef, $fileName) = @_;
719 (?:proto_tree_add_text)\s* \(
728 (?:proto_tree_add_text)\s* \(
736 while ($$fileContentsRef =~ / $pat /xgso) {
738 my @args = split(/,/, ${1});
740 #cleanup whitespace to show proto_tree_add_text in single line (easier for seeing grep results)
741 $str =~ tr/\t\n\r/ /d;
742 $str =~ s/ \s+ / /xg;
743 #print "$fileName: $str\n";
745 #find all instances where proto_tree_add_text has a tvb_get (or similar) call, because
746 #convert_proto_tree_add_text.pl has an easier time determining hf_ field values with it
747 if (scalar @args > 5) {
748 my $tvb = trim($args[5]);
749 if ($tvb =~ /^tvb_/) {
758 if ($tvb_found > 0) {
759 $tvb_percent = 100*$tvb_found/$found;
761 printf "%s: Found %d proto_tree_add_text calls eligible for conversion, %d contain a \"tvb get\" call (%.2f%%).\n",
762 $fileName, $found, $tvb_found, $tvb_percent;
764 print "$fileName: Found $found proto_tree_add_text calls eligible for conversion, 0 \"tvb get\" calls.\n";