forked from MiCode/patchrom_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_rom.sh
executable file
·116 lines (95 loc) · 3.25 KB
/
change_rom.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
#!/bin/bash
# $1: the old smali code $2: the new smali code $3: the destination smali code
if [ $# -ne 5 ];then
echo "Usage: change_rom.sh APP|JAR APP_NAME SUFFIX old_rom.zip new_rom.zip"
exit
fi
# todo run me under product dir, such as i9100
WS_DIR=`pwd`
APKTOOL=$PORT_ROOT/tools/apktool
# such as app/Phone (no .apk here)
APPFRM=$1
appname=$4
suffix=$5
app=$APPFRM/$appname.$suffix
temp_dir=$WS_DIR/temp
old_smali_dir=$WS_DIR/temp_old
dst_smali_dir=$WS_DIR/temp_dst
new_smali_dir=$WS_DIR
echo ">>> Extract $app from ROM_ZIP file..."
unzip $2 system/$app -d $old_smali_dir
$APKTOOL d $old_smali_dir/system/$app $old_smali_dir/$appname
unzip $3 system/$app -d $dst_smali_dir
$APKTOOL d $dst_smali_dir/system/$app $dst_smali_dir/$appname
echo "<<< Done!"
temp_old_smali_dir=$temp_dir/old_smali
temp_new_smali_dir=$temp_dir/new_smali
temp_dst_smali_orig_dir=$temp_dir/dst_smali_orig
temp_dst_smali_patched_dir=$temp_dir/dst_smali_patched
reject_dir=$temp_dir/reject
rm -rf $temp_dir
echo ">>> create temp directory to store the old, new source and destination smali code with .line removed"
mkdir -p $temp_old_smali_dir
mkdir -p $temp_new_smali_dir
mkdir -p $temp_dst_smali_orig_dir
mkdir -p $temp_dst_smali_patched_dir
mkdir -p $reject_dir
cp -r $old_smali_dir/$appname $temp_old_smali_dir
cp -r $dst_smali_dir/$appname $temp_dst_smali_orig_dir
if [ "$suffix" = "jar" ];then
cp -r $new_smali_dir/$appname.jar.out $temp_new_smali_dir/$appname
else
cp -r $new_smali_dir/$appname $temp_new_smali_dir
fi
$PORT_ROOT/tools/rmline.sh $temp_dir
function apply_miui_patch() {
old_code_noline=$temp_old_smali_dir/$1
new_code_noline=$temp_new_smali_dir/$1
dst_code_noline=$temp_dst_smali_orig_dir/$1
dst_code=$dst_smali_dir/$1
dst_code_orig=$dst_code.orig
echo ">>> compute the difference between $old_code_noline and $new_code_noline"
cd $old_code_noline
for file in `find ./ -name "*.[sx]*"`
do
if [ -f $new_code_noline/$file ]
then
diff $file $new_code_noline/$file > /dev/null || {
diff -B -c $file $new_code_noline/$file > $file.diff
}
else
echo "$file does not exist at $new_code_noline"
fi
done
cd $dst_smali_dir
mv $dst_code $dst_code_orig
cp -r $dst_code_noline $dst_code
echo ">>> apply the patch into the $dst_code"
cd $old_code_noline
for file in `find ./ -name "*.diff"`
do
mkdir -p $reject_dir/$1/`dirname $file`
patch $dst_code/${file%.diff} -r $reject_dir/$1/${file%.diff}.rej < $file
done
cp -r $dst_code $temp_dst_smali_patched_dir
cd $dst_code_noline
for file in `find ./ -name "*.smali"`
do
rm -f $file.diff
diff -B -c $file $dst_code_orig/$file > $file.diff
patch -f $dst_code/$file -r /dev/null < $file.diff >/dev/null 2>&1
rm -f $file.diff
done
find $dst_code -name "*.smali.orig" -exec rm {} \;
find $temp_dst_smali_patched_dir -name "*.smali.orig" -exec rm {} \;
rm -rf $dst_code_orig
}
apply_miui_patch $appname
echo ">>> copy out the result smali files and clean the workspace"
mv $new_smali_dir/$appname $new_smali_dir/$appname-old
mv $dst_smali_dir/$appname $new_smali_dir/$appname
rm -rf $old_smali_dir
rm -rf $dst_smali_dir
echo "<<< patch miui into target $app is done."
echo "Please look at $reject_dir to resolve any conflicts!"
tree -f $reject_dir