forked from levyitay/AddSecurityExceptionAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddSecurityExceptions.sh
More file actions
executable file
·43 lines (36 loc) · 1.32 KB
/
addSecurityExceptions.sh
File metadata and controls
executable file
·43 lines (36 loc) · 1.32 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
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied"
echo "Usage: ./addSecurityExceptions.sh <APK_filename>"
exit -1
fi
if [ ! -z "$2" ]
then
debugKeystore=$2
else
if [ ! -f ~/.android/debug.keystore ]; then
keytool -genkey -v -keystore ~/.android/debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000
fi
debugKeystore=~/.android/debug.keystore
fi
fullfile=$1
filename=$(basename "$fullfile")
extension="${filename##*.}"
filename="${filename%.*}"
new="_resign.apk"
newFileName=$filename$new
tmpDir=/tmp/$filename
java -jar apktool.jar d -f -o $tmpDir $fullfile
if [ ! -d "$tmpDir/res/xml" ]; then
mkdir $tmpDir/res/xml
fi
cp ./network_security_config.xml $tmpDir/res/xml/.
if ! grep -q "networkSecurityConfig" $tmpDir/AndroidManifest.xml; then
sed -E "s/(<application.*)(>)/\1 android\:networkSecurityConfig=\"@xml\/network_security_config\" \2 /" $tmpDir/AndroidManifest.xml > $tmpDir/AndroidManifest.xml.new
mv $tmpDir/AndroidManifest.xml.new $tmpDir/AndroidManifest.xml
fi
java -jar apktool.jar empty-framework-dir --force $tmpDir
echo "Building new APK $newFileName"
java -jar apktool.jar b -o ./$newFileName $tmpDir
jarsigner -verbose -keystore $debugKeystore -storepass android -keypass android ./$newFileName androiddebugkey