-
Notifications
You must be signed in to change notification settings - Fork 7
/
replace_smali_method.sh
executable file
·50 lines (39 loc) · 1.12 KB
/
replace_smali_method.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
#!/bin/bash
action=$1
file=$2
method=$3
OUT=out
function get_method_content() {
dir=$1
file=$2
method=$3
number=`find $dir -name $file.smali | wc -l`
if [ ! "$number" == 1 ]; then
echo "no or more than one file named $file.smali!"
exit -1
fi
file=`find $dir -name $file.smali`
patchfile=`basename $file`.method
patchdir=`dirname $file`
patchdir=`echo $patchdir | sed -e "s/$dir\///"`
echo patch $file at $patchdir/$patchfile
mkdir -p $patchdir
cat $file | sed -n -e "/^\.method.*$method/,/^\.end method/p" > $patchdir/$patchfile
}
function apply_method() {
dir=$1
patch=$2
to=$dir/`echo $patch | sed -e "s/.method//"`
# now only support one method in one file
method=`cat $patch | grep "^.method" | sed -e "s/^.* //" -e "s/(.*$//"`
echo patch method $method to file $to
cat $to | sed -e "/^\.method.*$method/,/^\.end method/d" > $to.patched
cat $patch >> $to.patched
mv $to.patched $to
}
if [ "$action" == "patch" ]; then
get_method_content $OUT $file $method
fi
if [ "$action" == "apply" ]; then
apply_method $OUT $file
fi