Last active
August 13, 2023 08:16
-
-
Save ohaiibuzzle/e7eba9c4b19319644a2528d951059aff to your computer and use it in GitHub Desktop.
Script to convert decrypted iOS apps to iOS Simulator (arm64 Macs only)
This file contains 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
# Script to recursively find mach-o binaries in a directory | |
# and convert the buildtools using vtool to IOSSIMULATOR | |
import os | |
import subprocess | |
# Path to the vtool | |
vtool_path = "/usr/bin/vtool" | |
codesign_path = "/usr/bin/codesign" | |
xattr_path = "/usr/bin/xattr" | |
# Path to the directory containing the binaries | |
bin_path = input("Drag and drop the .app file here: ").strip('"').strip() | |
machO_files = [] | |
frameworks = [] | |
# Recursively find all the mach-o binaries in the directory | |
for root, dirs, files in os.walk(bin_path): | |
for file in files: | |
# print("Checking " + file) | |
# Check the magic number of the file | |
# Mach-o binaries start with 0xfeedface on 32-bit and 0xfeedfacf on 64-bit | |
# LITTLE ENDIAN | |
with open(os.path.join(root, file), "rb") as f: | |
magic = f.read(4) | |
if magic == b"\xce\xfa\xed\xfe" or magic == b"\xcf\xfa\xed\xfe": | |
machO_files.append(os.path.join(root, file)) | |
for dir in dirs: | |
if dir.endswith(".framework"): | |
frameworks.append(os.path.join(root, dir)) | |
print("Found " + str(len(machO_files)) + " mach-o binaries") | |
# Convert the binaries using vtool -set-build-version | |
for file in machO_files: | |
print("Converting " + file) | |
subprocess.call( | |
[ | |
vtool_path, | |
"-set-build-version", | |
"iossim", | |
"14.0", | |
"14.0", | |
"-replace", | |
"-output", | |
file, | |
file, | |
] | |
) | |
print("Done") | |
# dummy entitlement with app sandbox enabled | |
DUMMY_ENTITLEMENT = """ | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>com.apple.security.app-sandbox</key> | |
<true/> | |
</dict> | |
</plist> | |
""" | |
# Create a dummy entitlements file | |
with open("entitlements.plist", "w") as f: | |
f.write(DUMMY_ENTITLEMENT) | |
# Re-sign the entire app with a local certificate | |
print("Re-signing the app") | |
subprocess.call( | |
[ | |
codesign_path, | |
"-f", | |
"-s-", | |
"--deep", | |
"--entitlements", | |
"entitlements.plist", | |
bin_path, | |
] | |
) | |
# Re-sign the frameworks | |
for framework in frameworks: | |
print("Re-signing " + framework) | |
subprocess.call( | |
[ | |
codesign_path, | |
"-f", | |
"-s-", | |
"--entitlements", | |
"entitlements.plist", | |
"--deep", | |
framework, | |
] | |
) | |
# Remove the dummy entitlements file | |
os.remove("entitlements.plist") | |
# Remove all the extended attributes | |
print("Removing extended attributes") | |
subprocess.call([xattr_path, "-rc", bin_path]) | |
print("Done") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment