forked from kam800/MachObfuscator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obfuscate.sh
executable file
·87 lines (63 loc) · 1.67 KB
/
obfuscate.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
#!/bin/bash
set -e
# Arguments
if [ "$#" -lt 2 ] ; then
cat <<USAGE
Obfuscates, resigns and repacks IPA file.
$0 path_to_ipa developer_certificate [obfuscator parameters]
Notes:
- path_to_ipa must be absolute
- developer_certificate may be NO_RESIGN which disables resigning
- path to obfuscator binary may be overridden using MACH_OBFUSCATOR environment variable
USAGE
exit
fi
if [ -z "$MACH_OBFUSCATOR" ] ; then
MACH_OBFUSCATOR=./MachObfuscator.exe
fi
XRESIGN=XReSign/XReSign/Scripts/xresign.sh
# src path must be absolute!
SRC_APP=$1
CERT=$2
shift
shift
if ! [ -f "$SRC_APP" ] ; then
echo "$SRC_APP does not exist!" >&2
exit 1
fi
# Paths
APP_FILENAME=`basename "$SRC_APP"`
APP_DIR=`dirname "$SRC_APP"`
OBF_APP_FILENAME="${APP_FILENAME}_obf.ipa"
OBF_APP="$APP_DIR/$OBF_APP_FILENAME"
TMP_DIR=/tmp/obf
UNPACKED="$TMP_DIR/Payload"
rm -rf "$TMP_DIR" || true
mkdir -p "$TMP_DIR"
rm "$OBF_APP" || true
echo "Unzipping..."
unzip -qd "$TMP_DIR" "$SRC_APP"
echo "Obfuscating..."
ls -Ll "$MACH_OBFUSCATOR"
time "$MACH_OBFUSCATOR" -m realWords "$@" "$UNPACKED"
echo "Zipping..."
(cd "$TMP_DIR" && zip -qr "$OBF_APP_FILENAME" .)
mv "$TMP_DIR/$OBF_APP_FILENAME" "$APP_DIR"
if [ "$CERT" != "NO_RESIGN" ] ; then
echo "Resigning..."
if [ -f "$XRESIGN" ]; then
echo "XReSign exists"
#git pull
else
git clone https://github.com/xndrs/XReSign.git
#fix permissions
chmod +x "$XRESIGN"
fi
#Xresign has problems with relative paths, only absolute work well,
#but still, tmp directory is not deleted afterwards.
#This means that this script must be given an absolute path
"$XRESIGN" -s "$OBF_APP" -c "$CERT"
else
echo "Not resigning app"
fi
echo "Done."