-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathadd_miui_methods_and_variables.sh
executable file
·74 lines (66 loc) · 2.55 KB
/
add_miui_methods_and_variables.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
#
# Copyright 2016 Miui Patchrom
#
BASE_DIR=$1
MOD_DIR=$2
TARGET_DIR=$3
IFS=$'\x0A'
tmp_fifo_file="/tmp/$$.fifo"
mkfifo $tmp_fifo_file
exec 9<>$tmp_fifo_file
# 8 threads
for((i=0;i<8;i++))
do
echo ""
done >&9
for modSmaliFile in $(find $MOD_DIR -name "*.smali" ! -name "*\$[0-9]*.smali" ! -name "R\$*.smali")
do
baseSmaliFile=${modSmaliFile/$MOD_DIR/$BASE_DIR}
targetSmaliFile=${modSmaliFile/$MOD_DIR/$TARGET_DIR}
read -u9
{
if [ -f $baseSmaliFile ];then
if [ "$(diff $baseSmaliFile $modSmaliFile)" == "" ];then
echo "" >&9
continue
fi
methodBeginLines=($(grep -n "^.method " $modSmaliFile))
methodEndLines=($(grep -n "^.end method" $modSmaliFile))
for((i=0;i<${#methodBeginLines[@]};i++))
do
if [ "$(echo ${methodBeginLines[$i]} | grep -E 'static synthetic|clinit')" == "" ];then
grepPattern="[^->]$(echo ${methodBeginLines[$i]##* } | sed 's/\[/\\\[/g')"
if [ "$(grep $grepPattern $baseSmaliFile)" == "" ];then
beginLineNum=$(echo ${methodBeginLines[$i]} | cut -d ':' -f1)
endLineNum=$(echo ${methodEndLines[$i]} | cut -d ':' -f1)
echo "Add method ${methodBeginLines[$i]##* } into $targetSmaliFile"
sed -n ${beginLineNum},${endLineNum}p $modSmaliFile >> $targetSmaliFile
fi
fi
done
fieldLines=($(grep -En "^.field |^.end field" $modSmaliFile))
linesCount=${#fieldLines[@]}
for ((i=0;i<$linesCount;i++))
do
beginLine=${fieldLines[$i]%% =*}
grepPattern="[^->]$(echo ${beginLine##* } | sed 's/\[/\\\[/g')"
if [ "$(grep $grepPattern $baseSmaliFile)" == "" ];then
echo "Add field ${beginLine##* } into $targetSmaliFile"
beginLineNum=$(echo $beginLine | cut -d ":" -f1)
if [ $(($linesCount-$i)) -ne 1 -a "$(echo ${fieldLines[$i+1]} | grep ".end field")" != "" ];then
endLineNum=$(echo ${fieldLines[$i+1]} | cut -d ":" -f1)
sed -n ${beginLineNum},${endLineNum}p $modSmaliFile >> $targetSmaliFile
i=$(($i+1))
else
sed -n ${beginLineNum}p $modSmaliFile >> $targetSmaliFile
fi
fi
done
fi
echo "" >&9
}&
done
wait
exec 9>&-
exit 0