-
Notifications
You must be signed in to change notification settings - Fork 21
/
disassemble
executable file
·176 lines (144 loc) · 4.77 KB
/
disassemble
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash
calc_cache_hash() {
current_hash=$(find .tmp/ -maxdepth 1 -type f -name "*.apk" -exec sha256sum {} \; | awk '{print $1}' | sort -d | sha256sum | cut -d ' ' -f 1)
}
create_gitignore() {
cat << EOF > .gitignore &&
.gitignore
build
dist
lib
assets/bttv_contributors.json
smali*/androidx
smali_classes9/bttv
smali_classes9/com
EOF
find ../../mod/app/src/main/res -type f | sed "s/..\/..\/mod\/app\/src\/main\///" >> .gitignore &&
echo "" >> .gitignore
}
#
# gather variables
#
[ -z "$JAVA_PATH" ] && JAVA_PATH=java
[ -z "$APKTOOL_PATH" ] && APKTOOL_PATH=/opt/apktool/apktool.jar
[ -z "$BUILD_COMPANION" ] && BUILD_COMPANION=/opt/build-companion
[ -z "$UBER_APK_SIGNER_PATH" ] && UBER_APK_SIGNER_PATH=/opt/uber-apk-signer/uber-apk-signer-1.2.1.jar
[[ -f "twitch.zip" ]] && FILE=twitch.zip
[[ -f "twitch.apk" ]] && FILE=twitch.apk
[ -z "$FILE" ] && echo "neither twitch.zip or twitch.apk where found" && exit 1
echo "JAVA_PATH: $JAVA_PATH"
echo "APKTOOL_PATH: $APKTOOL_PATH"
echo "FILE: $FILE"
echo "BUILD_COMPANION: $BUILD_COMPANION"
echo "UBER_APK_SIGNER_PATH: $UBER_APK_SIGNER_PATH"
# remove old working space
rm -rf .tmp
#
# gather apk files
#
if [ "${FILE: -4}" = ".zip" ]; then
unzip $FILE -d .tmp
else
mkdir .tmp
cp twitch.apk .tmp/tv.twitch.android.app.apk
fi
#
# check if cache available
#
if [ -d ".bttv-cache" ] && [ -f ".bttv-cache/disass_hash" ] && [ -d ".bttv-cache/disass" ];
then
echo "found cache"
disass_cache_hash=$(<.bttv-cache/disass_hash)
calc_cache_hash
echo $disass_cache_hash
echo $current_hash
if [ $current_hash = $disass_cache_hash ]; then
cp -R .bttv-cache/disass disass
rm -rf .tmp
echo "used cache"
exit 0
else
echo "cache invalid, removing..."
rm -rf .bttv-cache/disass_hash .bttv-cache/disass
fi
fi
#
# Verify integrity
#
# compare with https://twitch.tv/.well-known/assetlinks.json
FMT_TWITCH_SHA="13:38:F9:B0:49:89:3C:C7:0B:78:43:2A:17:75:82:F9:0B:D4:BC:62:96:EA:4E:D3:5B:CC:7D:F5:96:87:AC:53"
TWITCH_SHA=$(echo $FMT_TWITCH_SHA | sed 's/\://g') # remove all ':'
echo "~~~ Print signatures ~~~" &&
$JAVA_PATH -jar $UBER_APK_SIGNER_PATH -y --verifySha256 $TWITCH_SHA -a .tmp/*.apk
# exit if verification failed
[ $? -eq 2 ] &&
echo "ERROR:
ERROR: One or more apk files where not signed by twitch!
ERROR: This most likely means you have downloaded a potentialy malicious zip archive!
ERROR: " &&
exit 1
#
# disassemble apk files
#
for file in .tmp/*.apk; do
echo $file
echo ====
$JAVA_PATH -Xmx256m -jar $APKTOOL_PATH d $file -o .tmp/disass/${file/.tmp\//} $file
done
# move base
[[ -d ".tmp/disass/tv.twitch.android.app.apk" ]] && echo "found tv.twitch.android.app.apk" && mv .tmp/disass/tv.twitch.android.app.apk .tmp/base
[[ -d ".tmp/disass/base.apk" ]] && echo "found base.apk" && mv .tmp/disass/base.apk .tmp/base
[[ -d ".tmp/base" ]] || (echo "could not identify base please file an issue!" && exit 1)
if [ $(find .tmp/disass | wc -l) != "1" ]; then
#
# copy all files to base (don't overwrite)
#
for dir in .tmp/disass/*; do
cp -r -n $dir/* .tmp/base
done
# fix public.xml
$BUILD_COMPANION fix .tmp/base .tmp/disass/*/res/values/public.xml
$BUILD_COMPANION yml .tmp/base .tmp/disass/*/apktool.yml
fi
# fix apktool's <annotation bug
sed -i 's/<annotation/<annotation/g; s/<\/annotation/<\/annotation/g' .tmp/base/res/values*/plurals.xml
# remove android:isSplitRequired="true"
sed -i 's/android:isSplitRequired="true"//' .tmp/base/AndroidManifest.xml
# remove vending data
sed -i '/android:name="com.android.dynamic.apk.fused.modules"/d' .tmp/base/AndroidManifest.xml
sed -i 's/com.android.vending.derived.apk.id" android:value="."/com.android.vending.derived.apk.id" android:value="1"/' .tmp/base/AndroidManifest.xml
sed -i '/android:name="com.android.vending.splits.required"/d' .tmp/base/AndroidManifest.xml
sed -i '/android:name="com.android.vending.splits"/d' .tmp/base/AndroidManifest.xml
sed -i '/android:name="com.android.vending.derived.apk.id"/d' .tmp/base/AndroidManifest.xml
# remove stamp data
sed -i '/android:name="com.android.stamp.source"/d' .tmp/base/AndroidManifest.xml
sed -i '/android:name="com.android.stamp.type"/d' .tmp/base/AndroidManifest.xml
# rename apk
sed -i "s/apkFileName: tv.twitch.android.app.apk/apkFileName: twitch.apk/" .tmp/base/apktool.yml
sed -i "s/apkFileName: base.apk/apkFileName: twitch.apk/" .tmp/base/apktool.yml
# fix full dex-files
mkdir .tmp/base/smali_classes9
# mv .tmp/base/smali_classes8/androidx .tmp/base/smali_classes9/.
#
# Create reference for diffs
#
cd .tmp/base &&
git init &&
create_gitignore &&
git add . &&
git commit --quiet -m "base" &&
git tag base &&
cd .. &&
cd ..
#
# cache
#
mkdir -p .bttv-cache
calc_cache_hash
echo $current_hash > .bttv-cache/disass_hash
cp -R .tmp/base .bttv-cache/disass
#
# clean up
#
mv .tmp/base disass
rm .tmp -rf