diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-01-24 15:41:19 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2020-01-24 15:41:19 +0100 |
commit | 3d283209fb1825adea967f612e4b69478b574545 (patch) | |
tree | be95f0937a75906a7b6114e2415d281fbb1e066e | |
parent | Add a tool to extract a FreeStyle protocol chatter from an usbmon capture. (diff) | |
download | glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar.gz glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar.bz2 glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar.lz glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar.xz glucometerutils-3d283209fb1825adea967f612e4b69478b574545.tar.zst glucometerutils-3d283209fb1825adea967f612e4b69478b574545.zip |
Diffstat (limited to '')
-rwxr-xr-x | reversing_tools/abbott/extract_freestyle.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/reversing_tools/abbott/extract_freestyle.py b/reversing_tools/abbott/extract_freestyle.py index 019b23b..39c52ad 100755 --- a/reversing_tools/abbott/extract_freestyle.py +++ b/reversing_tools/abbott/extract_freestyle.py @@ -25,10 +25,8 @@ import usbmon import usbmon.chatter import usbmon.pcapng -HID_XFER_TYPES = ( - usbmon.constants.XferType.INTERRUPT, - usbmon.constants.XferType.CONTROL, -) +_UNENCRYPTED_TYPES = ( + 0x01, 0x04, 0x05, 0x06, 0x0c, 0x0d, 0x14, 0x15, 0x33, 0x34, 0x35, 0x71,) def main(): if sys.version_info < (3, 7): @@ -49,6 +47,12 @@ def main(): 'https://docs.python.org/3/library/logging.html#logging-levels')) parser.add_argument( + '--libre2', action='store_true', + help=('Whether to expect the capture coming from a Libre 2 device. ' + 'Libre 2 devices encrypt some of the messages, and as such they ' + 'will be dumped with the undecoded length as well.')) + + parser.add_argument( 'pcap_file', action='store', type=str, help='Path to the pcapng file with the USB capture.') @@ -85,16 +89,16 @@ def main(): assert len(packet.payload) >= 2 - message_length = packet.payload[1] + message_type = packet.payload[0] - # This is the case on Libre 2 (expected encrypted communication), in - # which case we ignore the message_length and we keep the whole message - # together. - if message_length > 62: - message_type = 'xx' - message = packet.payload + if args.libre2 and message_type not in _UNENCRYPTED_TYPES: + # On Libre 2 (expected encrypted communication), we ignore the + # message_length and we keep it with the whole message. + message_type = f'x{message_type:02x}' + message = packet.payload[1:] else: - message_type = f'{packet.payload[0]:02x}' + message_length = packet.payload[1] + message_type = f' {message_type:02x}' message = packet.payload[2:2+message_length] print(usbmon.chatter.dump_bytes( |