forked from Apollo-Reborn/Apollo-Reborn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.sh
More file actions
executable file
·326 lines (276 loc) · 11.2 KB
/
Copy pathpatch.sh
File metadata and controls
executable file
·326 lines (276 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
LIQUID_GLASS_ASSETS_CAR="${SCRIPT_DIR}/liquid-glass/prebuilt/Assets.car"
LIQUID_GLASS_ICONS_REGISTRY="${SCRIPT_DIR}/liquid-glass/icons.json"
LIQUID_GLASS_ICON_NAME="AppIcon"
LIQUID_GLASS_IPAD_ICON_FILES=("AppIcon60x60" "AppIcon76x76")
LIQUID_GLASS_IPHONE_ICON_FILES=("AppIcon60x60")
load_liquid_glass_alternate_icons() {
# Register every icon from icons.json as a CFBundleAlternateIcons entry
# (including the primary, so setAlternateIconName:<primary> is a valid
# no-op switch back to the primary asset).
local i=0 id
while id=$(plutil -extract "icons.${i}.id" raw -o - "$LIQUID_GLASS_ICONS_REGISTRY" 2>/dev/null); do
echo "$id"
((i++))
done
}
LIQUID_GLASS_ALTERNATE_ICONS=()
while IFS= read -r line; do
[[ -n "$line" ]] && LIQUID_GLASS_ALTERNATE_ICONS+=("$line")
done < <(load_liquid_glass_alternate_icons)
plist_set_string() {
local path="$1"
local value="$2"
if /usr/libexec/PlistBuddy -c "Print :${path}" "Info.plist" &>/dev/null; then
/usr/libexec/PlistBuddy -c "Set :${path} ${value}" "Info.plist"
else
/usr/libexec/PlistBuddy -c "Add :${path} string ${value}" "Info.plist"
fi
}
plist_ensure_dict() {
local path="$1"
if ! /usr/libexec/PlistBuddy -c "Print :${path}" "Info.plist" &>/dev/null; then
/usr/libexec/PlistBuddy -c "Add :${path} dict" "Info.plist"
fi
}
plist_replace_string_array() {
local path="$1"
shift
if /usr/libexec/PlistBuddy -c "Print :${path}" "Info.plist" &>/dev/null; then
/usr/libexec/PlistBuddy -c "Delete :${path}" "Info.plist"
fi
/usr/libexec/PlistBuddy -c "Add :${path} array" "Info.plist"
for value in "$@"; do
/usr/libexec/PlistBuddy -c "Add :${path}: string ${value}" "Info.plist"
done
}
ensure_liquid_glass_icon_metadata() {
plist_ensure_dict "CFBundleIcons"
plist_ensure_dict "CFBundleIcons:CFBundlePrimaryIcon"
plist_ensure_dict "CFBundleIcons:CFBundleAlternateIcons"
plist_ensure_dict "CFBundleIcons~ipad"
plist_ensure_dict "CFBundleIcons~ipad:CFBundlePrimaryIcon"
plist_ensure_dict "CFBundleIcons~ipad:CFBundleAlternateIcons"
plist_set_string "CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconName" "${LIQUID_GLASS_ICON_NAME}"
plist_set_string "CFBundleIcons~ipad:CFBundlePrimaryIcon:CFBundleIconName" "${LIQUID_GLASS_ICON_NAME}"
plist_replace_string_array "CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles" "${LIQUID_GLASS_IPHONE_ICON_FILES[@]}"
plist_replace_string_array "CFBundleIcons~ipad:CFBundlePrimaryIcon:CFBundleIconFiles" "${LIQUID_GLASS_IPAD_ICON_FILES[@]}"
for icon_name in "${LIQUID_GLASS_ALTERNATE_ICONS[@]}"; do
plist_ensure_dict "CFBundleIcons:CFBundleAlternateIcons:${icon_name}"
plist_ensure_dict "CFBundleIcons~ipad:CFBundleAlternateIcons:${icon_name}"
plist_set_string "CFBundleIcons:CFBundleAlternateIcons:${icon_name}:CFBundleIconName" "${icon_name}"
plist_set_string "CFBundleIcons~ipad:CFBundleAlternateIcons:${icon_name}:CFBundleIconName" "${icon_name}"
done
}
# Cleanup on exit (success or failure)
cleanup() {
if [ -d "extract_temp" ]; then
rm -rf extract_temp
fi
}
trap cleanup EXIT
# Generic IPA patching script (DOES NOT inject the tweak)
# Supports:
# - Liquid Glass patch for iOS 26 (credit: @ryannair05)
# - Custom URL schemes injection
# --- Argument Parsing ---
INPUT_IPA=""
OUTPUT_IPA="Apollo-Patched.ipa"
REMOVE_CODE_SIGNATURE="false"
LIQUID_GLASS="false"
URL_SCHEMES=""
OUTPUT_IPA_PATH=""
print_usage() {
echo "Usage: $0 <path_to_ipa> [options]"
echo ""
echo "Options:"
echo " -o, --output <file> Output IPA filename (default: Apollo-Patched.ipa)"
echo " --remove-code-signature Remove code signature from the binary"
echo " --liquid-glass Apply Liquid Glass patch for iOS 26"
echo " --url-schemes <schemes> Comma-separated list of URL schemes to add"
echo " (e.g., 'custom,test,myapp')"
echo ""
echo "Examples:"
echo " $0 Apollo.ipa --liquid-glass"
echo " $0 Apollo.ipa --url-schemes 'custom,test'"
echo " $0 Apollo.ipa --liquid-glass --url-schemes 'custom' -o MyApp.ipa"
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-o|--output)
OUTPUT_IPA="$2"
shift; shift
;;
--remove-code-signature)
REMOVE_CODE_SIGNATURE="true"
shift
;;
--liquid-glass)
LIQUID_GLASS="true"
shift
;;
--url-schemes)
URL_SCHEMES="$2"
shift; shift
;;
-h|--help)
print_usage
exit 0
;;
-*)
echo "Error: Unknown option $1"
print_usage
exit 1
;;
*)
INPUT_IPA="$1"
shift
;;
esac
done
# Input validation
if [ -z "$INPUT_IPA" ]; then
print_usage
exit 1
fi
if [ ! -f "$INPUT_IPA" ]; then
echo "Error: Input IPA file not found: $INPUT_IPA"
exit 1
fi
echo "Starting IPA patch process..."
echo "Input IPA: ${INPUT_IPA}"
echo "Output IPA: ${OUTPUT_IPA}"
echo "Remove code signature: ${REMOVE_CODE_SIGNATURE}"
echo "Liquid Glass patch: ${LIQUID_GLASS}"
echo "URL schemes: ${URL_SCHEMES:-none}"
if [[ "${OUTPUT_IPA}" = /* ]]; then
OUTPUT_IPA_PATH="${OUTPUT_IPA}"
else
OUTPUT_IPA_PATH="$(pwd)/${OUTPUT_IPA}"
fi
# --- 1. Extract IPA ---
echo "Extracting ${INPUT_IPA}..."
rm -rf extract_temp
unzip -q "${INPUT_IPA}" -d extract_temp
cd extract_temp
if [ ! -d "Payload" ]; then
echo "Error: Invalid IPA structure - Payload directory not found"
exit 1
fi
# Find the app bundle dynamically
app_bundle=$(ls Payload/ | grep '\.app$' | head -1)
if [ -z "$app_bundle" ]; then
echo "Error: No .app bundle found in Payload directory"
exit 1
fi
echo "Found app bundle: ${app_bundle}"
# Get the executable name from Info.plist
PLIST_PATH="Payload/${app_bundle}/Info.plist"
EXECUTABLE_NAME=$(/usr/libexec/PlistBuddy -c "Print :CFBundleExecutable" "$PLIST_PATH")
echo "Executable name: ${EXECUTABLE_NAME}"
# --- 2. Apply Modifications ---
echo "Applying modifications..."
cd "Payload/${app_bundle}"
# --- 2a. Liquid Glass Patch ---
if [ "${LIQUID_GLASS}" == "true" ]; then
echo "Applying Liquid Glass patch for iOS 26..."
# Install vtool if not available
if ! command -v vtool &> /dev/null; then
echo "Installing vtool..."
brew install vtool
fi
# Apply vtool modifications for iOS 26 compatibility
echo "Running vtool to set build version for iOS 26..."
vtool -set-build-version ios 15.0 19.0 -replace -output "${EXECUTABLE_NAME}" "${EXECUTABLE_NAME}"
# Check for duplicate @executable_path/Frameworks LC_RPATH entries
echo "Checking for duplicate LC_RPATH entries..."
executable_path_count=$(otool -l "${EXECUTABLE_NAME}" | grep -A 2 LC_RPATH | grep "@executable_path/Frameworks" | wc -l | tr -d ' ')
echo "Found $executable_path_count @executable_path/Frameworks LC_RPATH entries"
if [ "$executable_path_count" -gt 1 ]; then
echo "Removing duplicate @executable_path/Frameworks LC_RPATH entry..."
install_name_tool -delete_rpath "@executable_path/Frameworks" "${EXECUTABLE_NAME}"
echo "Duplicate LC_RPATH entry removed"
fi
if [ ! -f "${LIQUID_GLASS_ASSETS_CAR}" ]; then
echo "Error: Liquid Glass asset catalog not found at ${LIQUID_GLASS_ASSETS_CAR}"
exit 1
fi
echo "Replacing Assets.car with prebuilt Liquid Glass asset catalog..."
cp "${LIQUID_GLASS_ASSETS_CAR}" "Assets.car"
echo "Updating app icon metadata for Liquid Glass multi-icon catalog..."
ensure_liquid_glass_icon_metadata
fi
# --- 2b. URL Schemes Patch ---
if [ -n "$URL_SCHEMES" ]; then
echo "Adding custom URL schemes..."
# Check if CFBundleURLTypes exists and find entry with CFBundleURLSchemes
url_type_index=0
found_schemes=false
if /usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes" "Info.plist" &>/dev/null; then
# CFBundleURLTypes exists, find entry with CFBundleURLSchemes
while /usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes:${url_type_index}" "Info.plist" &>/dev/null; do
if /usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes:${url_type_index}:CFBundleURLSchemes" "Info.plist" &>/dev/null; then
found_schemes=true
break
fi
url_type_index=$((url_type_index + 1))
done
if [ "$found_schemes" == "false" ]; then
# CFBundleURLTypes exists but no entry has CFBundleURLSchemes, add to first entry
echo "Adding CFBundleURLSchemes to existing URL type entry..."
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "Info.plist"
url_type_index=0
found_schemes=true
fi
else
# CFBundleURLTypes doesn't exist, create it
echo "Creating CFBundleURLTypes array..."
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes array" "Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0 dict" "Info.plist"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:0:CFBundleURLSchemes array" "Info.plist"
url_type_index=0
found_schemes=true
fi
# Get current schemes for display
echo "Current URL schemes:"
/usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes:${url_type_index}:CFBundleURLSchemes" "Info.plist" 2>/dev/null || echo " (none)"
# Parse comma-separated schemes, trim whitespace, and add each one
IFS=',' read -ra SCHEMES <<< "$URL_SCHEMES"
for scheme in "${SCHEMES[@]}"; do
# Trim leading and trailing whitespace
scheme=$(echo "$scheme" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -n "$scheme" ]; then
# Check if scheme already exists (use grep -F for literal match)
# PlistBuddy output format has leading spaces, so we check if the scheme appears as a word
existing=$(/usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes:${url_type_index}:CFBundleURLSchemes" "Info.plist" 2>/dev/null | grep -cxF " ${scheme}" || true)
if [ "$existing" -eq 0 ]; then
echo "Adding URL scheme: ${scheme}"
/usr/libexec/PlistBuddy -c "Add :CFBundleURLTypes:${url_type_index}:CFBundleURLSchemes: string ${scheme}" "Info.plist"
else
echo "URL scheme already exists, skipping: ${scheme}"
fi
fi
done
echo "Updated URL schemes:"
/usr/libexec/PlistBuddy -c "Print :CFBundleURLTypes:${url_type_index}:CFBundleURLSchemes" "Info.plist"
fi
# --- 2c. Remove Code Signature ---
if [ "${REMOVE_CODE_SIGNATURE}" == "true" ]; then
echo "Removing code signature..."
codesign --remove-signature "${EXECUTABLE_NAME}" || true
else
echo "Keeping code signature."
fi
cd ../.. # Back to extract_temp directory
# --- 3. Repackage IPA ---
echo "Repackaging modified IPA..."
zip -qr "${OUTPUT_IPA_PATH}" Payload/
cd .. # Back to original directory
# Note: Cleanup handled by trap on EXIT
# --- 5. Final Verification ---
file_size=$(wc -c < "${OUTPUT_IPA_PATH}")
echo "Patched IPA created: ${OUTPUT_IPA_PATH} (Size: ${file_size} bytes)"
# Output the name for the workflow
echo "${OUTPUT_IPA_PATH}"