From d924c6b94e8336be270021cb4c88ae772c485ad4 Mon Sep 17 00:00:00 2001
From: Markus Birth <mbirth@gmail.com>
Date: Sat, 21 Nov 2020 22:11:17 +0100
Subject: [PATCH] Added script to search hw_ids in firmware files.

---
 find_hwids.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100755 find_hwids.py

diff --git a/find_hwids.py b/find_hwids.py
new file mode 100755
index 0000000..8e4070d
--- /dev/null
+++ b/find_hwids.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+Parses a binary file for 006-Bxxxx-xx or 006Bxxxxxx occurrances.
+"""
+
+import os.path
+import re
+import sys
+from grmn import devices
+
+FILE = sys.argv[1]
+
+pattern = re.compile(rb"006-?B\d\d\d\d-?\d\d")
+
+print("Reading {} ...".format(FILE))
+with open(FILE, "rb") as f:
+    data = f.read()
+    f.close()
+
+matches = pattern.findall(data)
+results = []
+
+for i in matches:
+    i = i.decode("utf-8")
+    if len(i) == 10:
+        i = "{}-{}-{}".format(i[0:3], i[3:8], i[8:])
+    results.append(i)
+
+results = sorted(set(results))
+
+for r in results:
+    print(r, end="")
+    hw_id = int(r[5:9])
+    if hw_id in devices.DEVICES:
+        print(" - {}".format(devices.DEVICES[hw_id]), end="")
+    print()