dcerpc-nt: add UNION_ALIGN_TO... helpers
[wireshark-sm.git] / tools / make-no-reassembly-profile.py
blob25ae0153fe757718638edbeffdcd19469bb79406
1 #!/usr/bin/env python3
3 # Generate preferences for a "No Reassembly" profile.
4 # By Gerald Combs <gerald@wireshark.org>
6 # SPDX-License-Identifier: GPL-2.0-or-later
8 '''Generate preferences for a "No Reassembly" profile.'''
10 import argparse
11 import os.path
12 import re
13 import subprocess
14 import sys
16 MIN_PLUGINS = 10
18 def main():
19 parser = argparse.ArgumentParser(description='No reassembly profile generator')
20 parser.add_argument('-p', '--program-path', default=os.path.curdir, help='Path to TShark.')
21 parser.add_argument('-v', '--verbose', action='store_const', const=True, default=False, help='Verbose output.')
22 args = parser.parse_args()
24 this_dir = os.path.dirname(__file__)
25 profile_path = os.path.join(this_dir, '..', 'resources', 'share', 'wireshark', 'profiles', 'No Reassembly', 'preferences')
27 tshark_path = os.path.join(args.program_path, 'tshark')
28 if not os.path.isfile(tshark_path):
29 print('tshark not found at {}\n'.format(tshark_path))
30 parser.print_usage()
31 sys.exit(1)
33 # Make sure plugin prefs are present.
34 cp = subprocess.run([tshark_path, '-G', 'plugins'], stdout=subprocess.PIPE, check=True, encoding='utf-8')
35 plugin_lines = cp.stdout.splitlines()
36 dissector_count = len(tuple(filter(lambda p: re.search(r'\sdissector\s', p), plugin_lines)))
37 if dissector_count < MIN_PLUGINS:
38 print('Found {} plugins but require {}.'.format(dissector_count, MIN_PLUGINS))
39 sys.exit(1)
41 rd_pref_re = re.compile(r'^#\s*(.*(reassembl|desegment)\S*):\s*TRUE')
42 out_prefs = [
43 '# Generated by ' + os.path.basename(__file__), '',
44 '####### Protocols ########', '',
46 cp = subprocess.run([tshark_path, '-G', 'defaultprefs'], stdout=subprocess.PIPE, check=True, encoding='utf-8')
47 pref_lines = cp.stdout.splitlines()
48 for pref_line in pref_lines:
49 m = rd_pref_re.search(pref_line)
50 if m:
51 rd_pref = m.group(1) + ': FALSE'
52 if args.verbose is True:
53 print(rd_pref)
54 out_prefs.append(rd_pref)
56 if len(pref_lines) < 5000:
57 print("Too few preference lines.")
58 sys.exit(1)
60 if len(out_prefs) < 150:
61 print("Too few changed preferences.")
62 sys.exit(1)
64 with open(profile_path, 'w') as profile_f:
65 for pref_line in out_prefs:
66 profile_f.write(pref_line + '\n')
68 if __name__ == '__main__':
69 main()