-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathpatchapp.sh
executable file
·158 lines (124 loc) · 3.23 KB
/
patchapp.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
OPTOOL="./optool"
IPA=$1
DYLIB_FOLDER=$2
TMPDIR=".patchapp.cache"
#
# Usage / syntax
#
function usage {
if [ "$2" == "" -o "$1" == "" ]; then
cat <<USAGE
Syntax: $0 <command> </path/to/your/ipa/file.ipa> [/path/to/your/file.mobileprovision]"
Where 'command' is one of:"
info - Show the information required to create a Provisioning Profile
that matches the specified .ipa file
patch - Inject the current Theos tweak into the specified .ipa file.
Requires that you specify a .mobileprovision file.
USAGE
fi
}
#
#
#
function copy_library_and_load {
# copy the files into the .app folder
echo '[+] Copying .dylib dependences into "'$TMPDIR/Payload/$APP'"'
cp -rf $DYLIB_FOLDER "$TMPDIR/Payload/$APP/Dylibs"
# re-sign Frameworks, too
echo "APPDIR=$APPDIR"
for file in `ls -1 "$APPDIR"/Dylibs`; do
if [[ "$file" == *.framework ]]
then
copy_framework_and_load "$file"
else
copy_dylib_and_load "$file"
fi
done
#--------
if [ "$?" != "0" ]; then
echo "Failed to inject "${DYLIB##*/}" into $APPDIR/${APP_BINARY}. Can I interest you in debugging the problem?"
exit 1
fi
chmod +x "$APPDIR/$APP_BINARY"
}
function copy_framework_and_load {
framework=$1
frameworkDylib=${framework%.framework}
copy_dylib_and_load "$framework/$frameworkDylib"
}
function copy_dylib_and_load {
dylib=$1
echo -n ' '
echo "Install Load: $file -> @executable_path/Dylibs/$dylib"
$OPTOOL install -c load -p "@executable_path/Dylibs/$dylib" -t "$APPDIR/$APP_BINARY" >& /dev/null
}
#
# Setup all the things.
#
function setup_environment {
if [ "$IPA" == "" ]; then
usage
exit 1
fi
if [ ! -r "$IPA" ]; then
echo "$IPA not found or not readable"
exit 1
fi
# setup
rm -rf "$TMPDIR" >/dev/null 2>&1
mkdir "$TMPDIR"
SAVED_PATH=`pwd`
# uncompress the IPA into tmpdir
echo '[+] Unpacking the .ipa file ('"`pwd`/$IPA"')...'
unzip -o -d "$TMPDIR" "$IPA" >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "Couldn't unzip the IPA file."
exit 1
fi
cd "$TMPDIR"
cd Payload/*.app
if [ "$?" != "0" ]; then
echo "Couldn't change into Payload folder. Wat."
exit 1
fi
APP=`pwd`
APP=${APP##*/}
APPDIR=$TMPDIR/Payload/$APP
cd "$SAVED_PATH"
BUNDLE_ID=`plutil -convert xml1 -o - $APPDIR/Info.plist|grep -A1 CFBundleIdentifier|tail -n1|cut -f2 -d\>|cut -f1 -d\<`-patched
APP_BINARY=`plutil -convert xml1 -o - $APPDIR/Info.plist|grep -A1 Exec|tail -n1|cut -f2 -d\>|cut -f1 -d\<`
}
#
# Zip folder back into Ipa
#
function repack_ipa {
echo '[+] Repacking the .ipa'
rm -f "${IPA%*.ipa}-patched.ipa" >/dev/null 2>&1
zip -9r "${IPA%*.ipa}-patched.ipa" Payload/ >/dev/null 2>&1
if [ "$?" != "0" ]; then
echo "Failed to compress the app into an .ipa file."
exit 1
fi
IPA=${IPA#../*}
mv "${IPA%*.ipa}-patched.ipa" ..
echo "[+] Wrote \"${IPA%*.ipa}-patched.ipa\""
echo "[+] Great success!"
}
#
# Inject the current Theos tweak into the specified .ipa file
#
function ipa_patch {
setup_environment
if [ ! -x "$OPTOOL" ]; then
echo "You need to install optool from here: https://github.com/alexzielenski/optool"
echo "Then update OPTOOL variable in '$0' to reflect the correct path to the optool binary."
exit 1
fi
copy_library_and_load
cd $TMPDIR
repack_ipa
cd - >/dev/null 2>&1
}
ipa_patch
# success!
exit 0