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.'''
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
))
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
))
41 rd_pref_re
= re
.compile(r
'^#\s*(.*(reassembl|desegment)\S*):\s*TRUE')
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
)
51 rd_pref
= m
.group(1) + ': FALSE'
52 if args
.verbose
is True:
54 out_prefs
.append(rd_pref
)
56 if len(pref_lines
) < 5000:
57 print("Too few preference lines.")
60 if len(out_prefs
) < 150:
61 print("Too few changed preferences.")
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__':