dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / tools / checkfiltername.pl
blobf8725d7b40764e350d05d10f421b972ef157b2ef
1 #!/usr/bin/env perl
3 my $debug = 0;
4 # 0: off
5 # 1: specific debug
6 # 2: full debug
9 # verify that display filter names correspond with the PROTABBREV of
10 # of the dissector. Enforces the dissector to have a source
11 # filename of format packet-PROTABBREV.c
13 # Usage: checkfiltername.pl <file or files>
16 # Copyright 2011 Michael Mann (see AUTHORS file)
18 # Wireshark - Network traffic analyzer
19 # By Gerald Combs <gerald@wireshark.org>
20 # Copyright 1998 Gerald Combs
22 # SPDX-License-Identifier: GPL-2.0-or-later
25 # Example:
26 # ~/work/wireshark/trunk/epan/dissectors> ../../tools/checkfiltername.pl packet-3com-xns.c
27 # packet-3com-xns.c (2 (of 2) fields)
28 # 102 3comxns.type doesn't match PROTOABBREV of 3com-xns
29 # 106 3comxns.type doesn't match PROTOABBREV of 3com-xns
31 # or checkfiltername.pl packet-*.c, which will check all the dissector files.
35 use warnings;
36 use strict;
37 use Getopt::Long;
39 my @elements;
40 my @elements_dup;
41 my @protocols;
42 my %filters;
43 my %expert_filters;
44 my @acceptedprefixes = ("dcerpc-");
45 my @asn1automatedfilelist;
46 my @dcerpcautomatedfilelist;
47 my @idl2wrsautomatedfilelist;
48 my @filemanipulationfilelist;
49 my @prefixfilelist;
50 my @nofieldfilelist;
51 my %unique;
52 my @uniquefilelist;
53 my @noregprotocolfilelist;
54 my @periodinfilternamefilelist;
56 my $showlinenoFlag = '';
57 my $showautomatedFlag = '';
59 my $state = "";
60 # "s_unknown",
61 # "s_start",
62 # "s_in_hf_register_info",
63 # "s_hf_register_info_entry",
64 # "s_header_field_info_entry",
65 # "s_header_field_info_entry_start",
66 # "s_header_field_info_entry_name",
67 # "s_header_field_info_entry_abbrev",
68 # "s_header_field_info_entry_abbrev_end",
69 # "s_start_expert",
70 # "s_in_ei_register_info",
71 # "s_ei_register_info_entry",
72 # "s_ei_register_info_entry_start",
73 # "s_ei_register_info_entry_abbrev_end",
74 # "s_nofields"
76 my $restofline;
77 my $filecount = 0;
78 my $currfile = "";
79 my $protabbrev = "";
80 my $protabbrev_index;
81 my $PFNAME_value = "";
82 my $linenumber = 1;
83 my $totalerrorcount = 0;
84 my $errorfilecount = 0;
85 my $onefield = 0;
86 my $nofields = 0;
87 my $noperiod = 0;
88 my $noregprotocol = 1;
89 my $automated = 0;
90 my $more_tokens;
91 my $showall = 0;
93 my $comment = 0;
95 sub checkprotoabbrev {
96 my $abbrev = "";
97 my $abbrevpos;
98 my $proto_abbrevpos1;
99 my $proto_abbrevpos2;
100 my $afterabbrev = "";
101 my $check_dup_abbrev = "";
102 my $modprotabbrev = "";
103 my $errorline = 0;
104 my $prefix;
106 if (($automated == 0) || ($showall == 1)) {
107 $abbrevpos = index($_[0], ".");
108 if ($abbrevpos == -1) {
109 $abbrev = $_[0];
111 else {
112 $abbrev = substr($_[0], 0, $abbrevpos);
113 $afterabbrev = substr($_[0], $abbrevpos+1, length($_[0])-$abbrevpos);
114 $check_dup_abbrev = $afterabbrev;
115 $afterabbrev = substr($afterabbrev, 0, length($abbrev));
118 if ($abbrev ne $protabbrev) {
119 $errorline = 1;
121 #check if there is a supported protocol that matches the abbrev.
122 #This may be a case of filename != PROTOABBREV
123 foreach (@protocols) {
124 if ($abbrev eq $_) {
125 $errorline = 0;
126 } elsif (index($_, ".") != -1) {
128 #compare from start of string for each period found
129 $proto_abbrevpos1 = 0;
130 while ((($proto_abbrevpos2 = index($_, ".", $proto_abbrevpos1)) != -1) &&
131 ($errorline == 1)) {
132 if ($abbrev eq substr($_, 0, $proto_abbrevpos2)) {
133 $errorline = 0;
136 $proto_abbrevpos1 = $proto_abbrevpos2+1;
142 # find any underscores that preface or follow a period
143 if (((index($_[0], "._") >= 0) || (index($_[0], "_.") >= 0)) &&
144 #ASN.1 dissectors can intentionally generating this field name, so don't fault the dissector
145 (index($_[0], "_untag_item_element") < 0)) {
146 if ($showlinenoFlag) {
147 push(@elements, "$_[1] $_[0] contains an unnecessary \'_\'\n");
148 } else {
149 push(@elements, "$_[0] contains an unnecessary \'_\'\n");
153 if (($errorline == 1) && ($showall == 0)) {
154 #try some "accepted" variations of PROTOABBREV
156 #replace '-' with '_'
157 $modprotabbrev = $protabbrev;
158 $modprotabbrev =~ s/-/_/g;
159 if ($abbrev eq $modprotabbrev) {
160 $errorline = 0;
163 #remove '-'
164 if ($errorline == 1) {
165 $modprotabbrev = $protabbrev;
166 $modprotabbrev =~ s/-//g;
167 if ($abbrev eq $modprotabbrev) {
168 $errorline = 0;
172 #remove '_'
173 if ($errorline == 1) {
174 $modprotabbrev = $protabbrev;
175 $modprotabbrev =~ s/_//g;
176 if ($abbrev eq $modprotabbrev) {
177 $errorline = 0;
181 if ($errorline == 1) {
182 #remove any "accepted" prefix to see if there is still a problem
183 foreach (@acceptedprefixes) {
184 if ($protabbrev =~ /^$_/) {
185 $modprotabbrev = substr($protabbrev, length($_));
186 if ($abbrev eq $modprotabbrev) {
187 push(@prefixfilelist, "$currfile\n");
188 $errorline = 0;
193 else {
194 push(@filemanipulationfilelist, "$currfile\n");
197 #now check the acceptable "fields from a different protocol"
198 if ($errorline == 1) {
199 if (is_from_other_protocol_allowed($_[0], $currfile) == 1) {
200 $errorline = 0;
204 #now check the acceptable "fields that include a version number"
205 if ($errorline == 1) {
206 if (is_protocol_version_allowed($_[0], $currfile) == 1) {
207 $errorline = 0;
212 if ($errorline == 1) {
213 $debug>1 && print "$_[1] $_[0] doesn't match PROTOABBREV of $protabbrev\n";
214 if ($showlinenoFlag) {
215 push(@elements, "$_[1] $_[0] doesn't match PROTOABBREV of $protabbrev\n");
216 } else {
217 push(@elements, "$_[0] doesn't match PROTOABBREV of $protabbrev\n");
221 if (($abbrev ne "") && (lc($abbrev) eq lc($afterabbrev))) {
222 # Allow ASN.1 generated files to duplicate part of proto name
223 if ((!(grep {$currfile eq $_ } @asn1automatedfilelist)) &&
224 # Check allowed list
225 (is_proto_dup_allowed($abbrev, $check_dup_abbrev) == 0)) {
226 if ($showlinenoFlag) {
227 push(@elements_dup, "$_[1] $_[0] duplicates PROTOABBREV of $abbrev\n");
228 } else {
229 push(@elements_dup, "$_[0] duplicates PROTOABBREV of $abbrev\n");
236 sub printprevfile {
237 my $totalfields = keys(%filters);
238 my $count_ele;
239 my $count_dup;
240 my $total_count;
242 foreach (sort keys %filters) {
243 checkprotoabbrev ($filters{$_}, $_);
246 foreach (sort keys %expert_filters) {
247 checkprotoabbrev ($expert_filters{$_}, $_);
250 $count_ele = @elements;
251 $count_dup = @elements_dup;
252 $total_count = $count_ele+$count_dup;
254 if ($noregprotocol == 1) {
255 #if no protocol is registered, only worry about duplicates
256 if ($currfile ne "") {
257 push(@noregprotocolfilelist, "$currfile\n");
260 if ($count_dup > 0) {
261 $errorfilecount++;
262 $totalerrorcount += $count_dup;
265 if (($showall == 1) || ($count_dup > 0)) {
266 print "\n\n$currfile - NO PROTOCOL REGISTERED\n";
267 if ($showall == 1) {
268 #everything is included, so count all errors
269 $totalerrorcount += $count_ele;
270 if (($count_ele > 0) && ($count_dup == 0)) {
271 $errorfilecount++;
274 foreach (@elements) {
275 print $_;
278 foreach (@elements_dup) {
279 print $_;
282 } else {
283 if ($total_count > 0) {
284 $errorfilecount++;
285 $totalerrorcount += $total_count;
288 if (($automated == 0) || ($showall == 1)) {
289 if ($total_count > 0) {
290 if ($automated == 1) {
291 if ($showall == 1) {
292 print "\n\n$currfile - AUTOMATED ($total_count (of $totalfields) fields)\n";
294 } else {
295 print "\n\n$currfile ($total_count (of $totalfields) fields)\n";
298 foreach (@elements) {
299 print $_;
301 foreach (@elements_dup) {
302 print $_;
306 if ((($nofields) || ($totalfields == 0)) && ($currfile ne "")) {
307 if ($showall == 1) {
308 print "\n\n$currfile - NO FIELDS\n";
310 push(@nofieldfilelist, "$currfile\n");
316 #--------------------------------------------------------------------
317 # This is a list of dissectors that intentionally have filter names
318 # where the second segment duplicates (at least partially) the name
319 # of the first. The most common case is in ASN.1 dissectors, but
320 # those can be dealt with by looking at the first few lines of the
321 # dissector. This list has been vetted and justification will need
322 # to be provided to add to it. Acknowledge these dissectors aren't
323 # a problem for the pre-commit script
324 #--------------------------------------------------------------------
325 sub is_proto_dup_allowed {
326 if (($_[0] eq "amf") && (index($_[1], "amf0") >= 0)) {return 1;}
327 if (($_[0] eq "amf") && (index($_[1], "amf3") >= 0)) {return 1;}
328 if (($_[0] eq "amqp") && (index($_[1], "amqp") >= 0)) {return 1;}
329 if (($_[0] eq "bat") && (index($_[1], "batman") >= 0)) {return 1;}
330 if (($_[0] eq "browser") && (index($_[1], "browser_") >= 0)) {return 1;}
331 if (($_[0] eq "data") && (index($_[1], "data") >= 0)) {return 1;}
332 if (($_[0] eq "dlsw") && (index($_[1], "dlsw_version") >= 0)) {return 1;}
333 if (($_[0] eq "dns") && (index($_[1], "dnskey") >= 0)) {return 1;}
334 if (($_[0] eq "ecmp") && (index($_[1], "ecmp_") >= 0)) {return 1;}
335 if (($_[0] eq "exported_pdu") && (index($_[1], "exported_pdu") >= 0)) {return 1;}
336 if (($_[0] eq "fc") && (index($_[1], "fctl") >= 0)) {return 1;}
337 if (($_[0] eq "fcs") && (index($_[1], "fcsmask") >= 0)) {return 1;}
338 if (($_[0] eq "fmp") && (index($_[1], "fmp") >= 0)) {return 1;}
339 if (($_[0] eq "fr") && (index($_[1], "frame_relay") >= 0)) {return 1;}
340 if (($_[0] eq "lustre") && (index($_[1], "lustre_") >= 0)) {return 1;}
341 if (($_[0] eq "mac") && (index($_[1], "macd") >= 0)) {return 1;}
342 if (($_[0] eq "mac") && (index($_[1], "macis") >= 0)) {return 1;}
343 if (($_[0] eq "mih") && (index($_[1], "mihf") >= 0)) {return 1;}
344 if (($_[0] eq "mih") && (index($_[1], "mihcap") >= 0)) {return 1;}
345 if (($_[0] eq "ncp") && (index($_[1], "ncp") >= 0)) {return 1;}
346 if (($_[0] eq "nfs") && (index($_[1], "nfs") >= 0)) {return 1;}
347 if (($_[0] eq "oxid") && (index($_[1], "oxid") >= 0)) {return 1;}
348 if (($_[0] eq "rquota") && (index($_[1], "rquota") >= 0)) {return 1;}
349 if (($_[0] eq "pfcp") && (index($_[1], "pfcp") >= 0)) {return 1;}
350 if (($_[0] eq "sm") && (index($_[1], "sm_") >= 0)) {return 1;}
351 if (($_[0] eq "smpp") && (index($_[1], "smppplus") >= 0)) {return 1;}
352 if (($_[0] eq "spray") && (index($_[1], "sprayarr") >= 0)) {return 1;}
353 if (($_[0] eq "stat") && (index($_[1], "stat_") >= 0)) {return 1;}
354 if (($_[0] eq "stat") && (index($_[1], "state") >= 0)) {return 1;}
355 if (($_[0] eq "tds") && (index($_[1], "tds_") >= 0)) {return 1;}
356 if (($_[0] eq "time") && (index($_[1], "time") >= 0)) {return 1;}
357 if (($_[0] eq "tn3270") && (index($_[1], "tn3270e") >= 0)) {return 1;}
358 if (($_[0] eq "usb") && (index($_[1], "usb") >= 0)) {return 1;}
359 if (($_[0] eq "xml") && (index($_[1], "xml") >= 0)) {return 1;}
360 if (($_[0] eq "dns") && (index($_[1], "dnscrypt") >= 0)) {return 1;}
362 return 0;
365 #--------------------------------------------------------------------
366 # This is a list of dissectors that intentionally have filter names
367 # shared with other dissectors. This list has been vetted and
368 # justification will need to be provided to add to it.
369 # Acknowledge these dissectors aren't a problem for the pre-commit script
370 #--------------------------------------------------------------------
371 sub is_from_other_protocol_allowed {
372 my $proto_filename;
373 my $dir_index = rindex($_[1], "\\");
375 #handle directory names on all platforms
376 if ($dir_index < 0) {
377 $dir_index = rindex($_[1], "/");
380 if ($dir_index < 0) {
381 $proto_filename = $_[1];
383 else {
384 $proto_filename = substr($_[1], $dir_index+1);
387 # XXX - may be faster to hash this (note 1-many relationship)?
388 if (($proto_filename eq "packet-atalk.c") && (index($_[0], "llc") >= 0)) {return 1;}
389 if (($proto_filename eq "packet-awdl.c") && (index($_[0], "llc") >= 0)) {return 1;}
390 if (($proto_filename eq "packet-bpdu.c") && (index($_[0], "mstp") >= 0)) {return 1;}
391 if (($proto_filename eq "packet-bssap.c") && (index($_[0], "bsap") >= 0)) {return 1;}
392 if (($proto_filename eq "packet-caneth.c") && (index($_[0], "can") >= 0)) {return 1;}
393 if (($proto_filename eq "packet-cimetrics.c") && (index($_[0], "llc") >= 0)) {return 1;}
394 if (($proto_filename eq "packet-cipsafety.c") && (index($_[0], "cip") >= 0)) {return 1;}
395 if (($proto_filename eq "packet-cipsafety.c") && (index($_[0], "enip") >= 0)) {return 1;}
396 if (($proto_filename eq "packet-dcerpc-netlogon.c") && (index($_[0], "ntlmssp") >= 0)) {return 1;}
397 if (($proto_filename eq "packet-dcom-oxid.c") && (index($_[0], "dcom") >= 0)) {return 1;}
398 if (($proto_filename eq "packet-dvb-data-mpe.c") && (index($_[0], "mpeg_sect") >= 0)) {return 1;}
399 if (($proto_filename eq "packet-dvb-ipdc.c") && (index($_[0], "ipdc") >= 0)) {return 1;}
400 if (($proto_filename eq "packet-enip.c") && (index($_[0], "cip") >= 0)) {return 1;}
401 if (($proto_filename eq "packet-extreme.c") && (index($_[0], "llc") >= 0)) {return 1;}
402 if (($proto_filename eq "packet-fmp_notify.c") && (index($_[0], "fmp") >= 0)) {return 1;}
403 if (($proto_filename eq "packet-foundry.c") && (index($_[0], "llc") >= 0)) {return 1;}
404 if (($proto_filename eq "packet-glusterfs.c") && (index($_[0], "gluster") >= 0)) {return 1;}
405 if (($proto_filename eq "packet-h248_annex_e.c") && (index($_[0], "h248") >= 0)) {return 1;}
406 if (($proto_filename eq "packet-h248_q1950.c") && (index($_[0], "h248") >= 0)) {return 1;}
407 if (($proto_filename eq "packet-ieee1722.c") && (index($_[0], "can") >= 0)) {return 1;}
408 if (($proto_filename eq "packet-ieee80211.c") && (index($_[0], "eapol") >= 0)) {return 1;}
409 if (($proto_filename eq "packet-ieee80211-radio.c") && (index($_[0], "wlan") >= 0)) {return 1;}
410 if (($proto_filename eq "packet-ieee80211-wlancap.c") && (index($_[0], "wlan") >= 0)) {return 1;}
411 if (($proto_filename eq "packet-ieee802154.c") && (index($_[0], "wpan") >= 0)) {return 1;}
412 if (($proto_filename eq "packet-isup.c") && (index($_[0], "ansi_isup") >= 0)) {return 1;}
413 if (($proto_filename eq "packet-isup.c") && (index($_[0], "bat_ase") >= 0)) {return 1;}
414 if (($proto_filename eq "packet-isup.c") && (index($_[0], "nsap") >= 0)) {return 1;}
415 if (($proto_filename eq "packet-isup.c") && (index($_[0], "x213") >= 0)) {return 1;}
416 if (($proto_filename eq "packet-iwarp-ddp-rdmap.c") && (index($_[0], "iwarp_ddp") >= 0)) {return 1;}
417 if (($proto_filename eq "packet-iwarp-ddp-rdmap.c") && (index($_[0], "iwarp_rdma") >= 0)) {return 1;}
418 if (($proto_filename eq "packet-k12.c") && (index($_[0], "aal2") >= 0)) {return 1;}
419 if (($proto_filename eq "packet-k12.c") && (index($_[0], "atm") >= 0)) {return 1;}
420 if (($proto_filename eq "packet-m3ua.c") && (index($_[0], "mtp3") >= 0)) {return 1;}
421 if (($proto_filename eq "packet-mle.c") && (index($_[0], "wpan") >= 0)) {return 1;}
422 if (($proto_filename eq "packet-mpeg-dsmcc.c") && (index($_[0], "mpeg_sect") >= 0)) {return 1;}
423 if (($proto_filename eq "packet-mpeg-dsmcc.c") && (index($_[0], "etv.dsmcc") >= 0)) {return 1;}
424 if (($proto_filename eq "packet-mpeg1.c") && (index($_[0], "rtp.payload_mpeg_") >= 0)) {return 1;}
425 if (($proto_filename eq "packet-mysql.c") && (index($_[0], "mariadb") >= 0)) {return 1;}
426 if (($proto_filename eq "packet-ndps.c") && (index($_[0], "spx.ndps_") >= 0)) {return 1;}
427 if (($proto_filename eq "packet-pw-atm.c") && (index($_[0], "atm") >= 0)) {return 1;}
428 if (($proto_filename eq "packet-pw-atm.c") && (index($_[0], "pw") >= 0)) {return 1;}
429 if (($proto_filename eq "packet-scsi.c") && (index($_[0], "scsi_sbc") >= 0)) {return 1;}
430 if (($proto_filename eq "packet-sndcp-xid.c") && (index($_[0], "llcgprs") >= 0)) {return 1;}
431 if (($proto_filename eq "packet-wlccp.c") && (index($_[0], "llc") >= 0)) {return 1;}
432 if (($proto_filename eq "packet-wps.c") && (index($_[0], "eap") >= 0)) {return 1;}
433 if (($proto_filename eq "packet-wsp.c") && (index($_[0], "wap") >= 0)) {return 1;}
434 if (($proto_filename eq "packet-xot.c") && (index($_[0], "x25") >= 0)) {return 1;}
435 if (($proto_filename eq "packet-zbee-zcl-misc.c") && (index($_[0], "zbee_zcl_hvac") >= 0)) {return 1;}
436 if (($proto_filename eq "packet-zbee-zcl-misc.c") && (index($_[0], "zbee_zcl_ias") >= 0)) {return 1;}
438 #Understand why, but I think it could be prefixed with "dissector"
439 #prefix (which isn't necessarily "protocol")
440 if (($proto_filename eq "packet-rtcp.c") && (index($_[0], "srtcp") >= 0)) {return 1;}
441 if (($proto_filename eq "packet-rtp.c") && (index($_[0], "srtp") >= 0)) {return 1;}
442 if (($proto_filename eq "packet-dcom-cba-acco.c") && (index($_[0], "cba") >= 0)) {return 1;}
443 if (($proto_filename eq "packet-dcom-cba.c") && (index($_[0], "cba") >= 0)) {return 1;}
445 #XXX - HACK to get around nested "s in field name
446 if (($proto_filename eq "packet-gsm_sim.c") && (index($_[0], "e\\") >= 0)) {return 1;}
448 return 0;
451 #--------------------------------------------------------------------
452 # This is a list of dissectors that use their (protocol) version number
453 # as part of the first display filter segment, which checkfiltername
454 # usually complains about. Manually allow them so that they can pass
455 # pre-commit script
456 #--------------------------------------------------------------------
457 sub is_protocol_version_allowed {
458 my $proto_filename;
459 my $dir_index = rindex($_[1], "\\");
461 #handle directory names on all platforms
462 if ($dir_index < 0) {
463 $dir_index = rindex($_[1], "/");
466 if ($dir_index < 0) {
467 $proto_filename = $_[1];
469 else {
470 $proto_filename = substr($_[1], $dir_index+1);
473 # XXX - may be faster to hash this?
474 if (($proto_filename eq "packet-ehs.c") && (index($_[0], "ehs2") >= 0)) {return 1;}
475 if (($proto_filename eq "packet-hsrp.c") && (index($_[0], "hsrp2") >= 0)) {return 1;}
476 if (($proto_filename eq "packet-ipv6.c") && (index($_[0], "ip") >= 0)) {return 1;}
477 if (($proto_filename eq "packet-openflow_v1.c") && (index($_[0], "openflow") >= 0)) {return 1;}
478 if (($proto_filename eq "packet-rtnet.c") && (index($_[0], "tdma-v1") >= 0)) {return 1;}
479 if (($proto_filename eq "packet-scsi-osd.c") && (index($_[0], "scsi_osd2") >= 0)) {return 1;}
480 if (($proto_filename eq "packet-sflow.c") && (index($_[0], "sflow_5") >= 0)) {return 1;}
481 if (($proto_filename eq "packet-sflow.c") && (index($_[0], "sflow_245") >= 0)) {return 1;}
482 if (($proto_filename eq "packet-tipc.c") && (index($_[0], "tipcv2") >= 0)) {return 1;}
483 if (($proto_filename eq "packet-bluetooth.c") && (index($_[0], "llc.bluetooth_pid") >= 0)) {return 1;}
485 return 0;
488 # ---------------------------------------------------------------------
490 # MAIN
492 GetOptions(
493 'showlineno' => \$showlinenoFlag,
494 'showautomated' => \$showautomatedFlag,
497 while (<>) {
498 if ($currfile !~ /$ARGV/) {
499 &printprevfile();
501 # New file - reset array and state
502 $filecount++;
503 $currfile = $ARGV;
505 #determine PROTABBREV for dissector based on file name format of (dirs)/packet-PROTABBREV.c or (dirs)/file-PROTABBREV.c
506 $protabbrev_index = rindex($currfile, "packet-");
507 if ($protabbrev_index == -1) {
508 $protabbrev_index = rindex($currfile, "file-");
509 if ($protabbrev_index == -1) {
510 #ignore "non-dissector" files
511 next;
514 $protabbrev = substr($currfile, $protabbrev_index+length("file-"));
515 $protabbrev_index = rindex($protabbrev, ".");
516 if ($protabbrev_index == -1) {
517 print "$currfile doesn't fit format of file-PROTABBREV.c\n";
518 next;
520 } else {
521 $protabbrev = substr($currfile, $protabbrev_index+length("packet-"));
522 $protabbrev_index = rindex($protabbrev, ".");
523 if ($protabbrev_index == -1) {
524 print "$currfile doesn't fit format of packet-PROTABBREV.c\n";
525 next;
528 $protabbrev = substr($protabbrev, 0, $protabbrev_index);
530 $PFNAME_value = "";
531 $noregprotocol = 1;
532 $automated = 0;
533 $nofields = 0;
534 $onefield = 0;
535 $noperiod = 0;
536 $linenumber = 1;
537 %filters = ( );
538 %expert_filters = ( );
539 @protocols = ( );
540 @elements = ( );
541 @elements_dup = ( );
542 $state = "s_unknown";
545 if (($automated == 0) && ($showautomatedFlag eq "")) {
546 #DCERPC automated files
547 if ($_ =~ "DO NOT EDIT") {
548 push(@dcerpcautomatedfilelist, "$currfile\n");
549 $automated = 1;
550 next;
552 #ASN.1 automated files
553 elsif ($_ =~ "Generated automatically by the ASN.1 to Wireshark dissector compiler") {
554 push(@asn1automatedfilelist, "$currfile\n");
555 $automated = 1;
556 next;
558 #idl2wrs automated files
559 elsif ($_ =~ "Autogenerated from idl2wrs") {
560 push(@idl2wrsautomatedfilelist, "$currfile\n");
561 $automated = 1;
562 next;
566 # opening then closing comment
567 if (/(.*?)\/\*.*\*\/(.*)/) {
568 $comment = 0;
569 $_ = "$1$2";
570 # closing then opening comment
571 } elsif (/.*?\*\/(.*?)\/\*/) {
572 $comment = 1;
573 $_ = "$1";
574 # opening comment
575 } elsif (/(.*?)\/\*/) {
576 $comment = 1;
577 $_ = "$1";
578 # closing comment
579 } elsif (/\*\/(.*?)/) {
580 $comment = 0;
581 $_ = "$1";
582 } elsif ($comment == 1) {
583 $linenumber++;
584 next;
586 # unhandled: more than one complete comment per line
588 chomp;
590 #proto_register_protocol state machine
591 $restofline = $_;
592 $more_tokens = 1;
594 #PFNAME is a popular #define for the proto filter name, so use it for testing
595 if ($restofline =~ /#define\s*PFNAME\s*\"([^\"]*)\"/) {
596 $PFNAME_value = $1;
597 $debug>1 && print "PFNAME: '$1'\n";
600 until ($more_tokens == 0) {
601 if (($restofline =~ /proto_register_protocol\s*\((.*)/) ||
602 ($restofline =~ /proto_register_protocol_in_name_only\s*\((.*)/)) {
603 $noregprotocol = 0;
604 $restofline = $1;
605 $state = "s_proto_start";
606 } elsif (($state eq "s_proto_start") && ($restofline =~ /^(\s*\"([^\"]*)\"\s*,)\s*(.*)/)) {
607 $restofline = $3;
608 $state = "s_proto_long_name";
609 $debug>1 && print "proto long name: '$2'\n";
610 } elsif (($state eq "s_proto_start") && ($restofline =~ /^(\s*(([\w\d])+)\s*,)\s*(.*)/)) {
611 $restofline = $4;
612 $state = "s_proto_long_name";
613 $debug>1 && print "proto long name: '$2'\n";
614 } elsif (($state eq "s_proto_long_name") && ($restofline =~ /^(\s*\"([^\"]*)\"\s*,)\s*(.*)/)) {
615 $restofline = $3;
616 $state = "s_proto_short_name";
617 $debug>1 && print "proto short name: '$2'\n";
618 } elsif (($state eq "s_proto_long_name") && ($restofline =~ /^(\s*(([\w\d])+)\s*,)\s*(.*)/)) {
619 $restofline = $4;
620 $state = "s_proto_short_name";
621 $debug>1 && print "proto short name: '$2'\n";
622 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*PFNAME\s*(.*)/)) {
623 $more_tokens = 0;
624 $state = "s_proto_filter_name";
625 if ((index($PFNAME_value, ".") != -1) && ($noperiod == 0)) {
626 push(@periodinfilternamefilelist, "$currfile\n");
627 $noperiod = 1;
629 push(@protocols, $PFNAME_value);
630 $debug>1 && print "proto filter name: '$PFNAME_value'\n";
631 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*\"([^\"]*)\"\s*(.*)/)) {
632 $more_tokens = 0;
633 $state = "s_proto_filter_name";
634 if ((index($1, ".") != -1) && ($noperiod == 0)) {
635 push(@periodinfilternamefilelist, "$currfile\n");
636 $noperiod = 1;
638 push(@protocols, $1);
639 $debug>1 && print "proto filter name: '$1'\n";
640 } elsif (($state eq "s_proto_short_name") && ($restofline =~ /\s*(([\w\d])+)\s*(.*)/)) {
641 $more_tokens = 0;
642 $state = "s_proto_filter_name";
643 $debug>1 && print "proto filter name: '$1'\n";
644 } else {
645 $more_tokens = 0;
649 #retrieving display filters state machine
650 $restofline = $_;
651 $more_tokens = 1;
652 until ($more_tokens == 0) {
653 if ($restofline =~ /\s*static\s*hf_register_info\s*(\w+)\[\](.*)/) {
654 $restofline = $2;
655 $state = "s_start";
656 $debug>1 && print "$linenumber $state\n";
657 } elsif ($restofline =~ /\s*static\s*ei_register_info\s*(\w+)\[\](.*)/) {
658 $restofline = $2;
659 $state = "s_start_expert";
660 $debug>1 && print "$linenumber $state\n";
661 } elsif (($state eq "s_start") && ($restofline =~ /\W+{(.*)/)) {
662 $restofline = $1;
663 $state = "s_in_hf_register_info";
664 $debug>1 && print "$linenumber $state\n";
665 } elsif (($state eq "s_in_hf_register_info") && ($restofline =~ /\W+{(.*)/)) {
666 $restofline = $1;
667 $state = "s_hf_register_info_entry";
668 $debug>1 && print "$linenumber $state\n";
669 $onefield = 1;
670 } elsif (($state eq "s_in_hf_register_info") && ($restofline =~ /\s*};(.*)/)) {
671 $restofline = $1;
672 if ($onefield == 0) {
673 $debug && print "$linenumber NO FIELDS!!!\n";
674 $nofields = 1;
675 $state = "s_nofields";
676 $more_tokens = 0;
677 } else {
678 $state = "s_unknown";
680 } elsif (($state eq "s_hf_register_info_entry") && ($restofline =~ /\s*&\s*(hf_\w*(\[w*\])?)\s*,?(.*)/)) {
681 $restofline = $3;
682 $debug>1 && print "$linenumber hf_register_info_entry: $1\n";
683 $state = "s_header_field_info_entry";
684 } elsif (($state eq "s_header_field_info_entry") && ($restofline =~ /\s*{(.*)/)) {
685 $restofline = $1;
686 $state = "s_header_field_info_entry_start";
687 $debug>1 && print "$linenumber $state\n";
688 } elsif (($state eq "s_header_field_info_entry_start") && ($restofline =~ /((\"([^\"]*)\")|(\w+))\s*,(.*)/)) {
689 $restofline = $5;
690 $debug>1 && print "$linenumber header_field_info_entry_name: $1\n";
691 $state = "s_header_field_info_entry_name";
692 } elsif (($state eq "s_header_field_info_entry_name") && ($restofline =~ /\"([^\"]*)\"\s*,?(.*)/)) {
693 $restofline = $2;
694 $debug>1 && print "$linenumber header_field_info_entry_abbrev: $1\n";
695 $state = "s_header_field_info_entry_abbrev";
696 $filters{$linenumber} = $1;
697 } elsif (($state eq "s_header_field_info_entry_abbrev") && ($restofline =~ /[^}]*}(.*)/)) {
698 $restofline = $1;
699 $state = "s_header_field_info_entry_abbrev_end";
700 $debug>1 && print "$linenumber $state\n";
701 } elsif (($state eq "s_header_field_info_entry_abbrev_end") && ($restofline =~ /[^}]*}(.*)/)) {
702 $restofline = $1;
703 $state = "s_in_hf_register_info";
704 $debug>1 && print "$linenumber $state\n";
705 } elsif (($state eq "s_start_expert") && ($restofline =~ /\W+{(.*)/)) {
706 $restofline = $1;
707 $state = "s_in_ei_register_info";
708 $debug>1 && print "$linenumber $state\n";
709 } elsif (($state eq "s_in_ei_register_info") && ($restofline =~ /\W+{(.*)/)) {
710 $restofline = $1;
711 $state = "s_ei_register_info_entry";
712 $debug>1 && print "$linenumber $state\n";
713 } elsif (($state eq "s_in_ei_register_info") && ($restofline =~ /\s*};(.*)/)) {
714 $restofline = $1;
715 $state = "s_unknown";
716 } elsif (($state eq "s_ei_register_info_entry") && ($restofline =~ /\s*{(.*)/)) {
717 $restofline = $1;
718 $state = "s_ei_register_info_entry_start";
719 $debug>1 && print "$linenumber $state\n";
720 } elsif (($state eq "s_ei_register_info_entry_start") && ($restofline =~ /\"([^\"]*)\"\s*,(.*)/)) {
721 $restofline = $2;
722 $debug>1 && print "$linenumber ei_register_info_entry_abbrev: $1\n";
723 $expert_filters{$linenumber} = $1;
724 $state = "s_ei_register_info_entry_abbrev_end";
725 } elsif (($state eq "s_ei_register_info_entry_abbrev_end") && ($restofline =~ /[^}]*}(.*)/)) {
726 $restofline = $1;
727 $state = "s_in_ei_register_info";
728 $debug>1 && print "$linenumber $state\n";
729 } else {
730 $more_tokens = 0;
734 $linenumber++;
737 &printprevfile();
739 if ($totalerrorcount > 0) {
740 print "\n\nTOTAL ERRORS: $totalerrorcount";
742 if ($filecount > 1) {
743 print " ($errorfilecount files)\n";
745 print "NO FIELDS: " . scalar(@nofieldfilelist) . "\n";
746 print "AUTOMATED: " . (scalar(@asn1automatedfilelist) + scalar(@dcerpcautomatedfilelist) + scalar(@idl2wrsautomatedfilelist)) . "\n";
747 print "NO PROTOCOL: " . scalar(@noregprotocolfilelist) . "\n";
749 print "\nASN.1 AUTOMATED FILE LIST\n";
750 foreach (@asn1automatedfilelist) {
751 print $_;
753 print "\nDCE/RPC AUTOMATED FILE LIST\n";
754 foreach (@dcerpcautomatedfilelist) {
755 print $_;
757 print "\nIDL2WRS AUTOMATED FILE LIST\n";
758 foreach (@idl2wrsautomatedfilelist) {
759 print $_;
761 print "\n\"FILE MANIPULATION\" FILE LIST\n";
762 @uniquefilelist = grep{ not $unique{$_}++} @filemanipulationfilelist;
763 foreach (@uniquefilelist) {
764 print $_;
766 print "\nREMOVE PREFIX FILE LIST\n";
767 @uniquefilelist = grep{ not $unique{$_}++} @prefixfilelist;
768 foreach (@uniquefilelist) {
769 print $_;
771 print "\nNO PROTOCOL REGISTERED FILE LIST\n";
772 foreach (@noregprotocolfilelist) {
773 print $_;
775 print "\nNO FIELDS FILE LIST\n";
776 foreach (@nofieldfilelist) {
777 print $_;
780 print "\nPERIOD IN PROTO FILTER NAME FILE LIST\n";
781 foreach (@periodinfilternamefilelist) {
782 print $_;
784 } else {
785 print "\n";
788 exit(1); # exit 1 if ERROR
791 __END__