forked from BlissRoms-x86/vendor_foss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_perms.sh
executable file
·74 lines (64 loc) · 1.49 KB
/
generate_perms.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
#!/bin/bash
# Generate AOSP Premisisons.xml from folder of .apk files
# Change these if using outside this project
APK_FOLDER="bin"
PERMS_LOCATION="permissions"
PERMS_FILENAME="foss-permissions.xml"
# NO MORE EDITING BELOW HERE
PARSED_PERMS_PATH="$PERMS_LOCATION/$PERMS_FILENAME"
FILES="$APK_FOLDER/*.apk"
addPerms() {
perms_list=""
cat >> $PARSED_PERMS_PATH <<EOF
<privapp-permissions package="$2">
EOF
for i in "$@" ; do
perms_list+="$i "
done
echo ""
#~ echo -e "Prems List: $perms_list"
#~ echo ""
for i in $perms_list ; do
if [ "$i" == "uses-permission:" ]; then
echo -e "skipping meaningless line"
elif [[ "$i" == *"package:"* ]]; then
echo -e "skipping meaningless line"
elif [[ "$i" == *"name="* ]]; then
temp_str=$(echo "$i" | sed -e "s/'/\"/g")
cat >> $PARSED_PERMS_PATH <<EOF
<permission $temp_str/>
EOF
fi
done
cat >> $PARSED_PERMS_PATH <<EOF
</privapp-permissions>
EOF
}
echo -e "${LT_BLUE}# Generating Permissions XML ${NC}"
rm -Rf $PARSED_PERMS_PATH
mkdir -p permissions
cat > $PARSED_PERMS_PATH <<EOF
<permissions>
EOF
for f in $FILES
do
echo -e ""
echo "Processing $f file..."
cmd_list=""
argumentqa=$(aapt d permissions "$f")
echo ""
echo -e "Permissions for $argumentqa"
echo ""
for line in $argumentqa; do
read -a array <<< $line
echo ${array[index]}
cmd_list+="${array[index]} "
done
#~ echo -e "CMD_LIST: $cmd_list"
addPerms $cmd_list
done
cat >> $PARSED_PERMS_PATH <<EOF
</permissions>
EOF
echo ""
echo -e "All Set, permissions xml generated"