-
Notifications
You must be signed in to change notification settings - Fork 144
/
patch_apk.sh
executable file
·143 lines (125 loc) · 4.51 KB
/
patch_apk.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
#!/bin/bash
#
# Part of original RunMe.sh script that handles patching the apk found
# in subdirectory PutApkHere that have been decompiled
#
# script is modified to take 3 arguments
#
# First argument : name of the decompiled apk directory e.g. decompile_out
# Second argument : timestamp for generating the logs with autogeneration if empty
# Third argument : bool value if additional languages should be added or not
err=0
command -v dialog >/dev/null 2>&1 || { echo "I require dialog but it's not installed. Aborting." >&2; err=1; }
command -v bspatch >/dev/null 2>&1 || { echo "I require bspatch but it's not installed. Aborting." >&2; err=1; }
command -v patch >/dev/null 2>&1 || { echo "I require patch but it's not installed. Aborting." >&2; err=1; }
command -v dos2unix >/dev/null 2>&1 || { echo "I require dos2unix but it's not installed. Aborting." >&2; err=1; }
if [ $err = 1 ]
then
echo "Missing package"
exit 1
fi
ver=`cat version.txt`
outdir="__MODDED_APK_OUT__"
mkdir -p $outdir
if [ "$2" = "" ]
then
timestamp=$(date -u +"%Y-%M-%dT%R:%S")
else
timestamp=$2
fi
log_file="$outdir/log-cfg-${timestamp//:/_}.txt"
cd $1
apkver=`cat apktool.yml | grep versionName: | awk '{print $2}'`
apkvcode=`cat apktool.yml | grep versionCode: | awk '{print $2}'`
eval apkvcode=$apkvcode
cd ..
if [ ! -d "patches/$apkver-$apkvcode" ]
then
echo "Incompatible apk version!"
echo "ApkVersion: $apkver"
echo "ApkVersionCode: $apkvcode"
echo "Please take a look into the patches folder to see supported versions!"
read -p "Press a key"
echo "Exiting now"
exit 3
fi
options=()
i=1
cmd=(dialog --separate-output --checklist "Select patches for APK Version: $apkver-$apkvcode" 26 76 20)
for file in "patches/$apkver-$apkvcode/"*.patch; do
filename=$(basename "$file")
extension="${filename##*.}"
filename="${filename%.*}"
options+=($i "$filename" on)
((i++))
done
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
echo "deejayeye-modder version $ver" >> $log_file
echo " Command patch_apk.sh $1 $timestamp" >> $log_file
echo " ApkVersion : $apkver" >> $log_file
echo " ApkVersionCode : $apkvcode" >> $log_file
echo " Active patches : " >> $log_file
cd $1
for choice in $choices
do
let sel=$choice-1
let sel=$sel*3
let sel=$sel+1
patch=${options[$sel]}
dos2unix ../patches/$apkver-$apkvcode/$patch.patch
patch -l -p1 -N -r - < ../patches/$apkver-$apkvcode/$patch.patch
if [ "$patch" == "enableHereMaps" ]
then
echo -ne "Do you wish to input a new key for HERE Maps? [Y/n]: "
read choice
if [ "$choice" == "Y" ] || [ "$choice" = "y" ]
then
echo "Go to https://developer.here.com - login/sign-up"
echo "Then go to \"Premium SDKs - Offline functionality\" and click on Android SDK - Generate AppID and AppCode."
echo "VERY IMPORTANT: Enter dji.go.v4 as the package name. If you are cloning the APK put the chosen new package name."
echo "Enter the App ID: "
read HereMapsAppId
echo "Enter the App Code: "
read HereMapsAppCode
echo "Enter the License Key: "
read HereMapsLicenseKey
../patch_here_maps.sh $HereMapsAppId $HereMapsAppCode $HereMapsLicenseKey
fi
fi
if [ "$patch" == "removeOnlinefunction" ]
then
bspatch lib/armeabi-v7a/libSDKRelativeJNI.so lib/armeabi-v7a/libSDKRelativeJNI-n.so ../patches/$apkver-$apkvcode/so.bspatch
rm lib/armeabi-v7a/libSDKRelativeJNI.so
mv lib/armeabi-v7a/libSDKRelativeJNI-n.so lib/armeabi-v7a/libSDKRelativeJNI.so
fi
if [ "$patch" == "removeNFZ_ApplicationPart" ]
then
rm assets/expansion/internal/flysafe/dji.nfzdb.confumix
rm assets/expansion/internal/flysafe/dji.nfzdb.sig
rm assets/expansion/internal/flysafe/flysafe_areas_djigo.db
rm assets/expansion/internal/flysafe/flysafe_polygon_1860.db
rm assets/expansion/internal/flysafe/flyforbid_airmap/*.json
rm res/raw/flyforbid.json
touch res/raw/flyforbid.json
fi
echo " $patch" >> ../$log_file
done
if [ "$3" == "true" ]
then
if [ -d ../patches/$apkver-$apkvcode/lang ]
then
cp -rf ../patches/$apkver-$apkvcode/lang/. res/
fi
fi
dos2unix ../patches/$apkver-$apkvcode/origin
if [ -f ../patches/$apkver-$apkvcode/so2.bspatch ]
then
bspatch lib/armeabi-v7a/libFREncrypt.so lib/armeabi-v7a/libFREncrypt-n.so ../patches/$apkver-$apkvcode/so2.bspatch
rm lib/armeabi-v7a/libFREncrypt.so
mv lib/armeabi-v7a/libFREncrypt-n.so lib/armeabi-v7a/libFREncrypt.so
fi
patch -l -p1 -N -r - < ../patches/$apkver-$apkvcode/origin
cd ..
echo "========================================"
echo " Done patching "
echo "========================================"