Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save linw1995/7b1b8e88159f18ed18f46629e35ba423 to your computer and use it in GitHub Desktop.
Save linw1995/7b1b8e88159f18ed18f46629e35ba423 to your computer and use it in GitHub Desktop.
Packaging fonts in configuration profiles for installing on iOS
# coding: utf-8
import re
import hashlib
import sys
from base64 import b64encode
from random import choice
items = ['8', '9', 'a', 'b']
names = sys.argv
assert len(names) > 1
def replace(m):
return "-".join([m.group(1), m.group(2), '5' + m.group(3), choice(items) + m.group(5), m.group(5)])
for name in names[1:]:
with open(name, "rb") as f:
font_data = f.read()
sha1_font_data = hashlib.sha1(font_data).hexdigest()
UUID = replace(re.search("([a-f0-9]{8})([a-f0-9]{4})([a-f0-9]{3})([a-f0-9]{3})([a-f0-9]{12})", sha1_font_data))
encoded_font_data = b64encode(font_data)
xml = f"""<?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>PayloadUUID</key>
<string>{ UUID }</string>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadIdentifier</key>
<string>geniuscqy.font-{ UUID }</string>
<key>PayloadDisplayName</key>
<string>{ name }</string>
<key>PayloadOrganization</key>
<string>Font Profile</string>
<key>PayloadDescription</key>
<string>Make the font available to iOS applications.</string>
<key>PayloadContent</key>
<array>
<dict>
<key>PayloadVersion</key>
<integer>1</integer>
<key>PayloadUUID</key>
<string>{ UUID }</string>
<key>Font</key>
<data>{ encoded_font_data.decode() }</data>
<key>PayloadType</key>
<string>com.apple.font</string>
<key>PayloadIdentifier</key>
<string>LoggingPayload</string>
</dict>
</array>
<key>PayloadType</key>
<string>Configuration</string>
<key>PayloadRemovalDisallowed</key>
<false/>
</dict>
</plist>"""
with open(name+".mobileconfig", "w", encoding="utf-8") as f:
f.write(xml)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment