Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Last active July 9, 2026 03:51
Show Gist options
  • Select an option

  • Save uyjulian/ecdd5029c8235e02921b0879516c96a4 to your computer and use it in GitHub Desktop.

Select an option

Save uyjulian/ecdd5029c8235e02921b0879516c96a4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
import sys
with open(sys.argv[1], "rb") as f:
a = f.read()
with open(sys.argv[2], "rb") as f:
b = f.read()
if len(a) != len(b):
raise Exception("invalid size")
if (a[0] != 0xFF and b[0] == 0xFF) or (a[0] == 0x6F and b[0] == 0x74):
tmp = b
b = a
a = tmp
needs_byteswap = a[0] == 0x74 and b[0] == 0x6F
c = bytearray(len(a) + len(b))
for i in range(0, len(c), 2):
c[i] = a[i // 2]
c[i + 1] = b[i // 2]
if needs_byteswap:
for i in range(0, len(c), 4):
tmp = c[i]
c[i] = c[i + 3]
c[i + 3] = tmp
tmp = c[i + 1]
c[i + 1] = c[i + 2]
c[i + 2] = tmp
with open(sys.argv[3], "wb") as wf:
wf.write(c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment