sedbgmux-dump.py: automatic dump format detection

This commit is contained in:
Vadim Yanitskiy 2023-01-16 01:40:53 +06:00
parent a378018178
commit e0538ea1c3
1 changed files with 12 additions and 2 deletions

View File

@ -26,8 +26,18 @@ from sedbgmux.io import *
from sedbgmux import DbgMuxFrame
def dumpio_auto(fname: str, *args, **kw) -> DumpIO:
''' Detect dump format automatically '''
if fname.endswith('.socat.dump'):
return DumpIOSocat(fname, *args, **kw)
elif fname.endswith('.dump'):
return DumpIONative(fname, *args, **kw)
raise DumpIOError('Automatic format detection failed')
class SEDbgMuxDumpApp:
FORMATS = {
'auto' : (dumpio_auto, 'Automatic dump format detection (by filename)'),
'native' : (DumpIONative, 'Native binary dump format for this package'),
'socat' : (DumpIOSocat, 'ASCII hexdump generated by socat (-x option)'),
}
@ -93,8 +103,8 @@ ap.add_argument('-v', '--verbose', action='count', default=0,
parse = sp.add_parser('parse', help='parse a dump file')
parse.add_argument('input', metavar='INPUT', type=str,
help='input file to be parsed')
parse.add_argument('-f', '--format', type=str,
choices=SEDbgMuxDumpApp.FORMATS.keys(), default='native',
parse.add_argument('-f', '--format', type=str, default='auto',
choices=SEDbgMuxDumpApp.FORMATS.keys(),
help='input file format (default: %(default)s)')
parse.add_argument('-dp', '--decode-payload', action='store_true',
help='decode DebugMux frame contents')