From 3e905b97ba3ce4aac2a7839e1af3e5a3ade40f08 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Fri, 14 Jun 2024 15:24:39 -0700 Subject: [PATCH] Parse script: check for unexpected data in known blank areas --- parse.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/parse.py b/parse.py index 9ffbc9f..7aa3c95 100644 --- a/parse.py +++ b/parse.py @@ -87,10 +87,12 @@ class Tag(): self.filename = filename self.blocks = list(data[0+i:BYTES_PER_BLOCK+i] for i in range(0, len(data), BYTES_PER_BLOCK)) + self.warnings = [] + # Check for blank blocks for bi in IMPORTANT_BLOCKS: if self.blocks[bi] == b'\x00' * BYTES_PER_BLOCK: - print(f"Warning! Block {bi} is blank!") + self.warnings.append(f"Block {bi} is blank!") # Parse the data self.data = { @@ -118,9 +120,26 @@ class Tag(): "production_date": bytes_to_date(self.blocks[12]), "unknown": bytes_to_string(self.blocks[13]), # Appears to be some sort of date -- on some tags, this is identical to the production date, but not always - } + # Check for any data in bits that are expected to be blank + expected_to_be_blank = { + 5: [*range(6,8),*range(12,16)], + 6: range(12,16), + 10: [*range(0,4), *range(6,16)], + 14: [*range(0,4), *range(6,16)] + } + for block in range(16,39): + if block % 4 == 3: + continue # Skip MIFARE encryption key blocks + expected_to_be_blank[block] = list(range(0,16)) + + for block in expected_to_be_blank: + for pos in expected_to_be_blank[block]: + byte = self.blocks[block][pos] + if byte != 0: + self.warnings.append(f"Data found in block {block}, position {pos} that was expected to be blank (received {byte})") + def __str__(self, blocks_to_output = IMPORTANT_BLOCKS): result = "" @@ -132,6 +151,11 @@ class Tag(): else: result += f"- {key}: {bytes_to_hex(self.data[key]) if type(self.data[key]) == bytes else self.data[key]}\n" + if len(self.warnings): + result += "- Warnings:\n" + for warning in self.warnings: + result += f" - {warning}\n" + return result[:-1] def print_blocks(self, blocks_to_output = IMPORTANT_BLOCKS):