diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-11-26 16:27:38 -0800 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-11-27 04:38:15 +0000 |
commit | 0b9810ab97165da6936df81934a9559b45c45bee (patch) | |
tree | ce080cb64758183b177a366f32c58235ef755b3c /tools/make-no-reassembly-profile.py | |
parent | fc1e2ac66d0fcd91e653d2bd71826dff60837cd2 (diff) |
Add a "No Reassembly" profile.
Add a script that disables all of our desegmentation and reassembly
preferences and use it to create a "No Reassembly" profile.
Change-Id: Icd0b72e9e271a511e637acde9018f3aae018e589
Reviewed-on: https://code.wireshark.org/review/30799
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'tools/make-no-reassembly-profile.py')
-rwxr-xr-x | tools/make-no-reassembly-profile.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/make-no-reassembly-profile.py b/tools/make-no-reassembly-profile.py new file mode 100755 index 0000000000..97f3ba98d7 --- /dev/null +++ b/tools/make-no-reassembly-profile.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Generate preferences for a "No Reassembly" profile. +# By Gerald Combs <gerald@wireshark.org> +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +'''Generate preferences for a "No Reassembly" profile.''' + +import argparse +import os.path +import re +import subprocess +import sys + +def main(): + if sys.version_info[0] < 3: + print("This requires Python 3") + sys.exit(2) + + parser = argparse.ArgumentParser(description='No reassembly profile generator') + parser.add_argument('-p', '--program-path', default=os.path.curdir, help='Path to TShark.') + parser.add_argument('-v', '--verbose', action='store_const', const=True, default=False, help='Verbose output.') + args = parser.parse_args() + + this_dir = os.path.dirname(__file__) + profile_path = os.path.join(this_dir, '..', 'profiles', 'No Reassembly', 'preferences') + + tshark_path = os.path.join(args.program_path, 'tshark') + if not os.path.isfile(tshark_path): + print('tshark not found at {}\n'.format(tshark_path)) + parser.print_usage() + sys.exit(1) + + rd_pref_re = re.compile('^#\s*(.*(reassembl|desegment)):') + nr_prefs = [] + prefs_changed = 0 + cp = subprocess.run([tshark_path, '-G', 'defaultprefs'], stdout=subprocess.PIPE, check=True, encoding='utf-8') + for pref_line in cp.stdout.split('\n'): + nr_prefs.append(pref_line) + m = rd_pref_re.search(pref_line) + if m: + pref = m.group(1) + ': FALSE' + if args.verbose is True: + print(pref_line + '\n' + pref) + nr_prefs.append(pref) + prefs_changed += 1 + + if len(nr_prefs) < 5000: + print("Too few preference lines.") + sys.exit(1) + + if len(nr_prefs) < 50: + print("Too few changed preferences.") + sys.exit(1) + + with open(profile_path, 'w') as profile_f: + for pref_line in nr_prefs: + profile_f.write(pref_line + '\n') + +if __name__ == '__main__': + main() |