-
Notifications
You must be signed in to change notification settings - Fork 126
/
deoat.sh
executable file
·88 lines (82 loc) · 2.5 KB
/
deoat.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
#!/bin/bash
#
# Copyright (C) 2016, Miui Patchrom
#
TARGET_DIR=$1
function removeDuplicateFiles() {
local bootOat64Path=$(find $TARGET_DIR -name "boot.oat" | grep "64\/")
if [ -n $bootOat64Path ];then
rm -rf ${bootOat64Path/64\///}
rm -rf ${bootOat64Path/64\/boot.oat//boot.art}
fi
local odex
for odex in $(find $TARGET_DIR -name "*.odex" | grep "64\/")
do
echo "rm -rf ${odex/64\///}"
rm -rf ${odex/64\///}
done
}
function zipDex() {
local zipDir=$1
local dexPath=$2
local suffix=$3
local dexName=$(basename $dexPath .dex)
local zipName=${dexName%%-classes*}
if [ $dexName = $zipName ];then
local zipDexName=classes.dex
else
local zipDexName=classes${dexName##*-classes}.dex
fi
mv $dexPath $zipDexName
if [ -f $zipDir/$zipName.$suffix ];then
zip -m $zipDir/$zipName.$suffix $zipDexName > /dev/null
fi
}
function decodeBootOat() {
BOOTOAT_PATH=$(find $TARGET_DIR -name "boot.oat")
if [ -z $BOOTOAT_PATH ];then
return
fi
BOOTOAT_DIR=$(dirname $BOOTOAT_PATH)
echo "Decoding $BOOTOAT_PATH"
oat2dex boot $BOOTOAT_PATH > /dev/null
local bootDex
for bootDex in $(find $BOOTOAT_DIR/dex -name "*.dex")
do
zipDex $(dirname $BOOTOAT_DIR) $bootDex jar
done
}
function decodeOdex() {
local suffix=$1
local zipPath
for zipPath in $(find $TARGET_DIR -name "*.$suffix")
do
local zipDir=$(dirname $zipPath)
local zipName=$(basename $zipPath)
local odexPath=$(find $zipDir -name ${zipName/.$suffix/.odex})
if [ -z $odexPath ];then
continue
fi
echo "Decoding $odexPath"
local bootClassPath=$BOOTOAT_DIR/odex
if [ "$suffix" = "apk" ];then
bootClassPath=$(dirname $BOOTOAT_DIR)
fi
local ret=$(oat2dex -o $zipDir $odexPath $bootClassPath)
if [ -n "$(echo $ret | grep -i "failed")" -a -f $PORT_ROOT/tools/oat2dex-0.86.jar ];then
echo "Decoding $odexPath failed, try to use old version oat2dex"
java -jar $PORT_ROOT/tools/oat2dex-0.86.jar -o $zipDir $odexPath $bootClassPath > /dev/null
fi
rm -rf $odexPath
local dexPath
for dexPath in $(find $zipDir -maxdepth 1 -name "*.dex")
do
zipDex $zipDir $dexPath $suffix
done
done
}
removeDuplicateFiles
decodeBootOat
decodeOdex jar
decodeOdex apk
rm -rf $BOOTOAT_DIR/boot.oat $BOOTOAT_DIR/boot.art $BOOTOAT_DIR/odex $BOOTOAT_DIR/dex