summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.com>2020-05-25 14:47:25 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.com>2020-05-25 14:47:25 +0200
commitfc7f08460324a469273c6c80383220cad1b56adc (patch)
tree4c7dd7cbc130090424f166541963587e71beefc9
parentextract_freestyle: print metadata about messages outside of the message. (diff)
downloadglucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar.gz
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar.bz2
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar.lz
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar.xz
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.tar.zst
glucometerutils-fc7f08460324a469273c6c80383220cad1b56adc.zip
-rwxr-xr-xreversing_tools/abbott/extract_freestyle.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/reversing_tools/abbott/extract_freestyle.py b/reversing_tools/abbott/extract_freestyle.py
index e0ae66d..3efbc5a 100755
--- a/reversing_tools/abbott/extract_freestyle.py
+++ b/reversing_tools/abbott/extract_freestyle.py
@@ -10,6 +10,7 @@ import logging
import sys
import textwrap
+import construct
import usbmon
import usbmon.chatter
import usbmon.pcapng
@@ -35,6 +36,13 @@ _UNENCRYPTED_TYPES = (
_ABBOTT_VENDOR_ID = 0x1A61
_LIBRE2_PRODUCT_ID = 0x3950
+_ENCRYPTED_MESSAGE = construct.Struct(
+ message_type=construct.Byte,
+ encrypted_message=construct.Bytes(64 - 1 - 4 - 4),
+ sequence_number=construct.Int32ul,
+ mac=construct.Int32ul,
+)
+
def main():
if sys.version_info < (3, 7):
@@ -155,10 +163,16 @@ def main():
message_metadata = []
if args.encrypted_protocol and message_type not in _UNENCRYPTED_TYPES:
- # When expecting encrypted communication), we ignore the
- # message_length and we keep it with the whole message.
+ # With encrypted communication, the length of the message is also encrypted,
+ # and all the packets use the full 64 bytes. So instead, we extract what
+ # metadata we can.
+ parsed = _ENCRYPTED_MESSAGE.parse(packet.payload)
+ message_metadata.extend(
+ [f"SEQUENCE_NUMBER={parsed.sequence_number}", f"MAC={parsed.mac:04x}"]
+ )
+
message_type = f"x{message_type:02x}"
- message = packet.payload[1:]
+ message = parsed.encrypted_message
else:
message_length = packet.payload[1]
message_metadata.append(f"LENGTH={message_length}")