Imports a tcpdump like hexadecimal view e.g: exported via hexdump() or tcpdump or wireshark's "export as hex" :param input_string: String containing the hexdump input to parse. If None, read from standard input.
(input_string=None)
| 2892 | |
| 2893 | @conf.commands.register |
| 2894 | def import_hexcap(input_string=None): |
| 2895 | # type: (Optional[str]) -> bytes |
| 2896 | """Imports a tcpdump like hexadecimal view |
| 2897 | |
| 2898 | e.g: exported via hexdump() or tcpdump or wireshark's "export as hex" |
| 2899 | |
| 2900 | :param input_string: String containing the hexdump input to parse. If None, |
| 2901 | read from standard input. |
| 2902 | """ |
| 2903 | re_extract_hexcap = re.compile(r"^((0x)?[0-9a-fA-F]{2,}[ :\t]{,3}|) *(([0-9a-fA-F]{2} {,2}){,16})") # noqa: E501 |
| 2904 | p = "" |
| 2905 | try: |
| 2906 | if input_string: |
| 2907 | input_function = StringIO(input_string).readline |
| 2908 | else: |
| 2909 | input_function = input |
| 2910 | while True: |
| 2911 | line = input_function().strip() |
| 2912 | if not line: |
| 2913 | break |
| 2914 | try: |
| 2915 | p += re_extract_hexcap.match(line).groups()[2] # type: ignore |
| 2916 | except Exception: |
| 2917 | warning("Parsing error during hexcap") |
| 2918 | continue |
| 2919 | except EOFError: |
| 2920 | pass |
| 2921 | |
| 2922 | p = p.replace(" ", "") |
| 2923 | return hex_bytes(p) |
| 2924 | |
| 2925 | |
| 2926 | @conf.commands.register |
no test coverage detected