forked from DavidSkrundz/sdks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_patched_sdk.sh
executable file
·182 lines (137 loc) · 6.05 KB
/
create_patched_sdk.sh
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
#!/bin/sh
function print_usage {
printf 'Usage: %s {use_simulator} {sdks_output_path} {overwrite_existing} {no_warnings} {tbd_tool_path} {xcode_installation_path} \n' "$(basename "$0")"
printf "{} options are optional to provide, and can be ignored with a '-'\n"
}
if [ "$1" == "-h" ]; then
print_usage
exit 0
fi
sdks_output_path="$2"
if [ $# -lt 2 ] || [ "$sdks_output_path" == "-" ]; then
sdks_output_path="$THEOS/sdks"
if [ "$sdks_output_path" == "/sdks" ]; then
printf 'No Theos installation found. Please either install Theos or provide a path to an sdks directory\n\n'
print_usage
exit 1
fi
fi
if [ ! -d "$sdks_output_path" ]; then
mkdir -p "$sdks_output_path"
fi
# tbd info
version="v1"
archs_option=("--replace-archs" armv7 armv7s arm64)
tbd_options=("--allow-private-objc-symbols" "--ignore-missing-exports")
write_options=("--maintain-directories" "--replace-path-extension")
no_overwrite="--no-overwrite"
if [ $# -gt 2 ] && [ "$3" != '-' ]; then
no_overwrite=""
fi
no_warnings=""
if [ $# -gt 3 ] && [ "$4" != '-' ]; then
no_warnings="--dont-print-warnings"
fi
tbd_tool="$5"
if [ $# -lt 5 ] || [ "$tbd_tool" == "-" ]; then
tbd_tool="tbd"
tbd_exists=$(command -v $tbd_tool)
if [ -z $tbd_exists ]; then
printf 'No installation of tbd found. Please install the latest release of tbd v2.0.0 from here; https://github.com/inoahdev/tbd/releases, or provide a path to a tbd installation\n\n'
print_usage
exit 1
fi
else
tbd_exists=$(command -v "$tbd_tool")
if [ -z $tbd_exists ]; then
printf "Provided tbd-tool (%s) doesn't exist\n" "$tbd_tool"
exit 1
fi
fi
use_simulator="$1"
device_support_dir="$HOME/Library/Developer/Xcode/iOS DeviceSupport/"
if [ $# -lt 1 ]; then
use_simulator="-"
fi
xcode_developer_path="$6/Contents/Developer"
if [ $# -lt 6 ] || [ "$xcode_developer_path" == "-" ]; then
xcode_developer_path=$(xcode-select -p)
fi
if [ -z "$xcode_developer_path" ]; then
printf 'No Xcode installation found. Please either install Xcode or provide a path to an Xcode installation\n\n'
print_usage
exit 1
fi
xcode_sim_runtime_path="$xcode_developer_path/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot"
xcode_default_sdk_path="$xcode_developer_path/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
xcode_sdk_paths="$xcode_developer_path/Platforms/iPhoneOS.platform/Developer/SDKs/*"
preferred_xcode_sdk_path=""
for xcode_sdk_path in $xcode_sdk_paths; do
xcode_sdk_real=$(realpath $xcode_sdk_path)
if [ "$xcode_sdk_real" == "$xcode_default_sdk_path" ]; then
preferred_xcode_sdk_path=$xcode_sdk_path
fi
done
if [ -z "$preferred_xcode_sdk_path" ]; then
printf 'Failed to find sdk for simulator runtime\n'
exit 1
fi
preferred_xcode_sdk_name=$(basename $preferred_xcode_sdk_path)
xcode_sdk_ios_version=${preferred_xcode_sdk_name:8} # Remove 'iPhoneOS' in front of sdk name
xcode_sdk_ios_version=${xcode_sdk_ios_version%????} # Remove '.sdk' at back of sdk name
sdks_output_path_single_sdk_path=""
if [ -d "$device_support_dir" ] && [ "$use_simulator" == "-" ]; then
for symbols_path in "$device_support_dir"*; do
if [ ! -d "$symbols_path" ]; then
continue
fi
symbols_path_basename=$(basename "$symbols_path")
symbols_path_basename_array=($symbols_path_basename)
ios_version=${symbols_path_basename_array[0]}
sdk_name=$(printf "iPhoneOS%s.sdk" $ios_version)
symbols_actual_path="$symbols_path/Symbols/System"
if [ ! -d "$symbols_actual_path" ]; then
printf "Symbols for iOS %s don't exist\n" "$ios_version"
continue
fi
sdks_output_path_single_sdk_path="$sdks_output_path/$sdk_name"
if [ -d "$sdks_output_path_single_sdk_path" ]; then
printf 'SDK for iOS %s already exists\n' "$ios_version"
continue
fi
printf 'Creating SDK for iOS %s ...\n' "$ios_version"
if [ "$xcode_sdk_ios_version" != "$ios_version" ]; then
printf "Warning: Xcode SDK for iOS %s will be used as a base for sdk for iOS %s\n" $xcode_sdk_ios_version "$ios_version"
fi
mkdir -p "$sdks_output_path_single_sdk_path"
cp -R "$xcode_default_sdk_path/"* "$sdks_output_path_single_sdk_path"
"$tbd_tool" -p -r "$symbols_actual_path" \
-o "${write_options[@]}" $no_overwrite "$sdks_output_path_single_sdk_path/System" \
$no_warnings "${tbd_options[@]}" "${archs_option[@]}" -v $version
if [ $? -ne 0 ]; then
printf 'Failed to create tbds from Symbols directory for iOS %s\n' $ios_version
fi
done
else
if [ "$use_simulator" == "-" ]; then
printf 'No DeviceSupport binaries found, falling back to dumping from simulator runtime binaries\n'
fi
sdks_output_path_single_sdk_path="$sdks_output_path/$preferred_xcode_sdk_name"
if [ -d "$sdks_output_path_single_sdk_path" ]; then
printf 'SDK for iOS %s already exists\n' $xcode_sdk_ios_version
exit 1
fi
printf 'Creating sdk for iOS %s ...\n' "$xcode_sdk_ios_version"
mkdir -p "$sdks_output_path_single_sdk_path"
cp -R "$xcode_default_sdk_path/"* "$sdks_output_path_single_sdk_path"
parse_paths=("-p" "-r" "$xcode_sim_runtime_path/Developer"
"-p" "-r" "$xcode_sim_runtime_path/System"
"-p" "-r" "$xcode_sim_runtime_path/Library")
write_paths=("-o" "${write_options[@]}" $no_overwrite "$sdks_output_path_single_sdk_path/Developer"
"-o" "${write_options[@]}" $no_overwrite "$sdks_output_path_single_sdk_path/System"
"-o" "${write_options[@]}" $no_overwrite "$sdks_output_path_single_sdk_path/Library")
"$tbd_tool" "${parse_paths[@]}" "${write_paths[@]}" $no_warnings "${tbd_options[@]}" "${archs_option[@]}" -v $version
if [ $? -ne 0 ]; then
printf 'Failed to create tbds from iPhoneSimulator runtime for iOS %s\n' $xcode_sdk_ios_version
fi
fi