Skip to content

Instantly share code, notes, and snippets.

@dlevi309
Last active March 26, 2024 16:57
Show Gist options
  • Save dlevi309/0274792c28ebe65995fb9a851efd6335 to your computer and use it in GitHub Desktop.
Save dlevi309/0274792c28ebe65995fb9a851efd6335 to your computer and use it in GitHub Desktop.
script to switch between iOS13 (00000002) and iOS14 (80000002) arm64e ABI
import sys
from pathlib import Path
MH_MAGIC_64 = b'\xcf\xfa\xed\xfe'
CPU_TYPE_ARM64 = b'\x0c\x00\x00\x01'
CPU_SUBTYPE_IOS13 = b'\x02\x00\x00\x00'
CPU_SUBTYPE_IOS14 = b'\x02\x00\x00\x80'
IOS13_HEADER = MH_MAGIC_64 + CPU_TYPE_ARM64 + CPU_SUBTYPE_IOS13
IOS14_HEADER = MH_MAGIC_64 + CPU_TYPE_ARM64 + CPU_SUBTYPE_IOS14
HEADER_LEN = len(IOS13_HEADER)
def handle_file(file):
buf = file.read_bytes()
if len(buf) < HEADER_LEN:
return
header = buf[:HEADER_LEN]
buf = buf[HEADER_LEN:]
if header == IOS13_HEADER:
print(f'converting "{file.name}" CPU Subtype from iOS13 (00000002) to iOS14 (80000002)')
file.write_bytes(IOS14_HEADER + buf)
elif header == IOS14_HEADER:
print(f'converting "{file.name}" CPU Subtype from iOS14 (80000002) to iOS13 (00000002)')
file.write_bytes(IOS13_HEADER + buf)
def main():
if len(sys.argv) != 2:
print(f'USAGE: {sys.argv[0]} <path>')
return
path = sys.argv[1]
path = Path(path)
handle_file(path)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment