Last active
May 3, 2025 15:25
-
-
Save doronz88/8f787600a0111044839fa3ad0dd56585 to your computer and use it in GitHub Desktop.
Convert between ios14 and ios13 arm64e cpu subtypes for all mach-o in a given directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" from ios13 arm64e subtype to ios14') | |
file.write_bytes(IOS14_HEADER + buf) | |
elif header == IOS14_HEADER: | |
print(f'converting "{file.name}" from ios14 arm64e subtype to ios13') | |
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) | |
if path.is_dir(): | |
for file in path.glob('**/*'): | |
if not file.is_file(): | |
continue | |
handle_file(file) | |
else: | |
handle_file(path) | |
print('done.') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment