Fix Global Status patch and verification for MeshOS and Ultra

This commit is contained in:
sapient
2026-03-27 19:34:03 -07:00
parent f0c104d77b
commit 2b72c0ad7f
2 changed files with 66 additions and 2 deletions

View File

@@ -32,16 +32,57 @@ def patch_binary(file_path, offset, expected_bytes, patch_bytes):
return True
def apply_global_status_patch(file_path, offset, expected_bytes, patch_bytes):
if not os.path.exists(file_path):
return False
with open(file_path, "rb") as f:
data = bytearray(f.read())
if offset + len(expected_bytes) > len(data):
return False
current_bytes = data[offset : offset + len(expected_bytes)]
if current_bytes != expected_bytes:
print(
f"Skipping Global Status patch for {file_path} at {hex(offset)}: mismatch."
)
print(f"Expected: {expected_bytes.hex()}")
print(f"Found: {current_bytes.hex()}")
return False
print(f"Applying Global Status patch to {file_path} at {hex(offset)}...")
data[offset : offset + len(patch_bytes)] = patch_bytes
# Overwrite the file since it's already a patched version or we want to update it
with open(file_path, "wb") as f:
f.write(data)
return True
if __name__ == "__main__":
ultra_original = bytes.fromhex("26153c")
ultra_patch = bytes.fromhex("060f00")
ultra_global_original = bytes.fromhex("040242")
ultra_global_patch = bytes.fromhex("221000")
patch_binary(
"/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/Ultra-TDeck-v9.2.bin",
0xBA62D,
ultra_original,
ultra_patch,
)
# Also apply global status patch to Ultra
apply_global_status_patch(
"/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/Ultra-TDeck-v9.2.patched.bin",
0xBA6AD,
ultra_global_original,
ultra_global_patch,
)
patch_binary(
"/home/sapient/Public/esp32-analysis/firmware/Ultra-TDeck-v9.2-merged.bin",
0xCA62D,
@@ -49,9 +90,19 @@ if __name__ == "__main__":
ultra_patch,
)
apply_global_status_patch(
"/home/sapient/Public/esp32-analysis/firmware/Ultra-TDeck-v9.2-merged.patched.bin",
0xCA6AD,
ultra_global_original,
ultra_global_patch,
)
meshos_original = bytes.fromhex("26193c")
meshos_patch = bytes.fromhex("060f00")
meshos_global_original = bytes.fromhex("84210040")
meshos_global_patch = bytes.fromhex("221000")
patch_binary(
"/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/MeshOS-TDeck-1.1.8.bin",
0xB99ED,
@@ -59,8 +110,21 @@ if __name__ == "__main__":
meshos_patch,
)
apply_global_status_patch(
"/home/sapient/Public/03_Projects_and_Dev/Meshcore_TDECK/MeshOS-TDeck-1.1.8.patched.bin",
0xB9A54,
meshos_global_original,
meshos_global_patch,
)
merged_path = (
"/home/sapient/Public/esp32-analysis/firmware/MeshOS-TDeck-1.1.8-merged.bin"
)
if os.path.exists(merged_path):
patch_binary(merged_path, 0xC99ED, meshos_original, meshos_patch)
apply_global_status_patch(
merged_path.replace(".bin", ".patched.bin"),
0xC9A54,
meshos_global_original,
meshos_global_patch,
)

View File

@@ -26,12 +26,12 @@ if __name__ == "__main__":
ultra_patches = [
("UI Branch", 0xBA62D, bytes.fromhex("26153c"), bytes.fromhex("060f00")),
("Global Status (Round 2)", 0xBA6AD, bytes.fromhex("040242"), bytes.fromhex("221000"))
("Global Status (Round 2)", 0xBA6AD, bytes.fromhex("040242"), bytes.fromhex("221000ec"))
]
meshos_patches = [
("UI Branch", 0xB99ED, bytes.fromhex("26193c"), bytes.fromhex("060f00")),
("Global Status (Round 2)", 0xB9A54, bytes.fromhex("84210040"), bytes.fromhex("221000"))
("Global Status (Round 2)", 0xB9A54, bytes.fromhex("84210040"), bytes.fromhex("22100040"))
]
targets = [