From a0e903495cbcfd2dfe9152774454683be4d714cb Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Thu, 30 Apr 2020 23:37:27 -0400 Subject: [PATCH 1/8] Added compatibility for 306 firmware --- patch-airsense | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/patch-airsense b/patch-airsense index b0e58d4..6f33f68 100755 --- a/patch-airsense +++ b/patch-airsense @@ -20,9 +20,15 @@ patch() { dd bs=1 seek=$offset conv=notrunc of="$OUT" status=none } -echo "533b91127aa22e05b933db203ad56c449dc12a8c3fd62f57bd88c472a8061775 $IN"\ -| sha256sum --check \ -|| die "$IN: wrong hash" +shasum=$( sha256sum $IN | cut -f 1 -d " " ) +if [ $shasum = "533b91127aa22e05b933db203ad56c449dc12a8c3fd62f57bd88c472a8061775" ]; then + version="401" +elif [ $shasum = "363a204ba217f31223e929365d58b8f5ce038a7681e362fe157e190c2eacbd30" ]; then + version="306" +else + die "$IN: incompatible firmware version." +fi +echo "Found firmware version: $version" cp "$IN" "$OUT" || die "$OUT: copy failed" @@ -40,10 +46,12 @@ BUILD_FLAGS=0 patch_code() { #if you want to add the extra breath mode BUILD_FLAGS=$(( BUILD_FLAGS | (1 << 0) )) - - if [ -r breath.bin ] ; then + if [ -r breath.bin ] && [ $version = "401" ] ; then echo "Including breath.bin" cat breath.bin | patch 0xbb734 || die "binary patch failed" + elif [ -r breath.bin ] && [ $version = "401" ] ; then + echo "Including breath.bin" + cat breath.bin | patch 0xbb4d4 || die "binary patch failed" else die "breath.bin not found, did you run make?" fi From 4dff567a2770ab8b882a5e53d56029b07952ff0c Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Thu, 30 Apr 2020 23:43:01 -0400 Subject: [PATCH 2/8] Update patch-airsense --- patch-airsense | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patch-airsense b/patch-airsense index 6f33f68..524388f 100755 --- a/patch-airsense +++ b/patch-airsense @@ -49,7 +49,7 @@ patch_code() { if [ -r breath.bin ] && [ $version = "401" ] ; then echo "Including breath.bin" cat breath.bin | patch 0xbb734 || die "binary patch failed" - elif [ -r breath.bin ] && [ $version = "401" ] ; then + elif [ -r breath.bin ] && [ $version = "306" ] ; then echo "Including breath.bin" cat breath.bin | patch 0xbb4d4 || die "binary patch failed" else From e9aa0bad8b4ec3c3eef436253894be19ecedd342 Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sat, 2 May 2020 20:04:18 -0400 Subject: [PATCH 3/8] Calculate the differences between two hex files Useful for comparing the different firmware versions --- offset_diff.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 offset_diff.py diff --git a/offset_diff.py b/offset_diff.py new file mode 100644 index 0000000..6cdd26e --- /dev/null +++ b/offset_diff.py @@ -0,0 +1,31 @@ +import sys + +def comparer(file1, file2): + content1 = file1.readlines() + content2 = file2.readlines() + if len(content1) != len(content2): + print("Something went wrong. Length mismatch") + exit(1) + output = open("offset_differences.csv", "w") + # Looks weird, but just doing some CSV formatting + output.write("offset, " + str(file1).split("name='")[1].split("'")[0] + ", " + + str(file2).split("name='")[1].split("'")[0] + "\n") + for counter in range(len(content1)): + offset1, hexvalue1 = content1[counter].split(":")[0], content1[counter].split(" ")[1] + offset2, hexvalue2 = content2[counter].split(":")[0], content2[counter].split(" ")[1] + if offset1 != offset2: + print("Offset mismatch. Please run 'xxd -c 1 > .hex on both files again") + exit(1) + if hexvalue1 != hexvalue2: + output.write(""+offset1+", "+hexvalue1+", "+hexvalue2+"\n") + + +if len(sys.argv) == 3 and sys.argv[1][-3:] != "bin" and sys.argv[2][-3:] != "bin": + + with open(sys.argv[1],"r") as file1, open(sys.argv[2],"r") as file2: + comparer(file1,file2) +else: + print("This program will compare two hex dumps and will output non-matching offsets") + print("Run 'xxd -c 1 > .hex' on both files first.") + print("Usage: python offset_diff.py hexfile1 hexfile2") + sys.exit(1) From 0d61c37dcc24e752fe281fb3104b1c7fd0a815ec Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sat, 2 May 2020 20:25:48 -0400 Subject: [PATCH 4/8] CSV Formatting --- offset_diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/offset_diff.py b/offset_diff.py index 6cdd26e..2068f8c 100644 --- a/offset_diff.py +++ b/offset_diff.py @@ -17,11 +17,11 @@ def comparer(file1, file2): print("Offset mismatch. Please run 'xxd -c 1 > .hex on both files again") exit(1) if hexvalue1 != hexvalue2: - output.write(""+offset1+", "+hexvalue1+", "+hexvalue2+"\n") + output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+hexvalue1+"\"\"\""+", \"=\"\""+hexvalue2+"\"\"\"""\n") + # "=""123""" if len(sys.argv) == 3 and sys.argv[1][-3:] != "bin" and sys.argv[2][-3:] != "bin": - with open(sys.argv[1],"r") as file1, open(sys.argv[2],"r") as file2: comparer(file1,file2) else: From 57dfc618764f83c0339e2684859c3b5b5513ce7b Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sat, 2 May 2020 20:26:23 -0400 Subject: [PATCH 5/8] Update offset_diff.py --- offset_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/offset_diff.py b/offset_diff.py index 2068f8c..0e4db0d 100644 --- a/offset_diff.py +++ b/offset_diff.py @@ -17,7 +17,7 @@ def comparer(file1, file2): print("Offset mismatch. Please run 'xxd -c 1 > .hex on both files again") exit(1) if hexvalue1 != hexvalue2: - output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+hexvalue1+"\"\"\""+", \"=\"\""+hexvalue2+"\"\"\"""\n") + output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+hexvalue1+"\"\"\""+", \"=\"\""+hexvalue2+"\"\"\"\n") # "=""123""" From c1bae696a8ba7ffcf533c2411a7ca07e7a591647 Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sat, 2 May 2020 20:49:58 -0400 Subject: [PATCH 6/8] Updating comments --- offset_diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/offset_diff.py b/offset_diff.py index 0e4db0d..a75955c 100644 --- a/offset_diff.py +++ b/offset_diff.py @@ -7,7 +7,7 @@ def comparer(file1, file2): print("Something went wrong. Length mismatch") exit(1) output = open("offset_differences.csv", "w") - # Looks weird, but just doing some CSV formatting + # Grabbing the filename. It's weird, but it works output.write("offset, " + str(file1).split("name='")[1].split("'")[0] + ", " + str(file2).split("name='")[1].split("'")[0] + "\n") for counter in range(len(content1)): @@ -17,6 +17,7 @@ def comparer(file1, file2): print("Offset mismatch. Please run 'xxd -c 1 > .hex on both files again") exit(1) if hexvalue1 != hexvalue2: + # Looks weird, but just doing some CSV formatting output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+hexvalue1+"\"\"\""+", \"=\"\""+hexvalue2+"\"\"\"\n") # "=""123""" From cedfa36f564e7dea9c8a9a93c2aac495ea2ad96e Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sun, 3 May 2020 02:02:41 -0400 Subject: [PATCH 7/8] Finds where unmatching offsets could be located at Between different firmwares --- offset_locator.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 offset_locator.py diff --git a/offset_locator.py b/offset_locator.py new file mode 100644 index 0000000..150093c --- /dev/null +++ b/offset_locator.py @@ -0,0 +1,36 @@ +import sys + +def comparer(file1, file2): + content1 = file1.readlines() + content2 = file2.readlines() + if len(content1) != len(content2): + print("Something went wrong. Length mismatch") + exit(1) + output = open("offset_locator.csv", "w") + # Looks weird, but just doing some CSV formatting + output.write(str(file1).split("name='")[1].split("'")[0] + ", " + + str(file2).split("name='")[1].split("'")[0] + "\n") + for counter1 in range(len(content1)): + offset1, hexvalue1 = content1[counter1][0:8], content1[counter1][10:49] + offset2, hexvalue2 = content2[counter1][0:8], content2[counter1][10:49] + if hexvalue1 == "0000 0000 0000 0000 0000 0000 0000 0000": + output.write(offset1+" is 0's, \"\"\n") + elif hexvalue1 == "FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF": + output.write(offset2+" is F's, \"\"") + elif hexvalue2 != hexvalue1: + for counter2 in range(len(content2)): + offset2, hexvalue2 = content2[counter2][0:8], content2[counter2][10:49] + if hexvalue1 == hexvalue2: + output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+offset2+"\"\"\"\n") + if counter2 == len(content2)-1 and hexvalue1 != hexvalue2: + output.write("\"=\"\""+offset1+"\"\"\""+", No Match\n") + + +if len(sys.argv) == 3 and sys.argv[1][-3:] != "bin" and sys.argv[2][-3:] != "bin": + with open(sys.argv[1],"r") as file1, open(sys.argv[2],"r") as file2: + comparer(file1,file2) +else: + print("This program will compare two hex dumps and will output matching possible offsets") + print("Run 'xxd > .hex' on both files first.") + print("Usage: python offset_diff.py hexfile1 hexfile2") + sys.exit(1) From 59e23aa2580a1d5379f9083519f064ce90529924 Mon Sep 17 00:00:00 2001 From: dblunk88 <39381389+dblunk88@users.noreply.github.com> Date: Sun, 3 May 2020 02:14:34 -0400 Subject: [PATCH 8/8] Bugfixed No Match --- offset_locator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/offset_locator.py b/offset_locator.py index 150093c..c54fd76 100644 --- a/offset_locator.py +++ b/offset_locator.py @@ -13,6 +13,7 @@ def comparer(file1, file2): for counter1 in range(len(content1)): offset1, hexvalue1 = content1[counter1][0:8], content1[counter1][10:49] offset2, hexvalue2 = content2[counter1][0:8], content2[counter1][10:49] + matched = False if hexvalue1 == "0000 0000 0000 0000 0000 0000 0000 0000": output.write(offset1+" is 0's, \"\"\n") elif hexvalue1 == "FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF": @@ -21,8 +22,9 @@ def comparer(file1, file2): for counter2 in range(len(content2)): offset2, hexvalue2 = content2[counter2][0:8], content2[counter2][10:49] if hexvalue1 == hexvalue2: + matched = True output.write("\"=\"\""+offset1+"\"\"\""+", \"=\"\""+offset2+"\"\"\"\n") - if counter2 == len(content2)-1 and hexvalue1 != hexvalue2: + if counter2 == len(content2)-1 and not matched: output.write("\"=\"\""+offset1+"\"\"\""+", No Match\n")