Skip to content

Commit 7a16a36

Browse files
committed
Don’t replace classes.dex by unvdex’ed one if it’s already present.
Tested with talkback.apk.
1 parent 8d455d0 commit 7a16a36

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

unpack-apk

+8-7
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ tmpdir="$(mktemp -d)"
7171
trap "rm -rf '$tmpdir'" EXIT
7272
cd "$tmpdir"
7373

74-
# .apk for apktool and dex2jar to work with.
74+
# Temporary .apk for apktool and dex2jar to work with, potentially updated with a classes.dex.
7575
tmpapk="${tmpdir}/$(basename "$apk")"
7676
cp -v "$apk" "$tmpapk"
7777

78-
# Add classes.dex from .vdex, if present.
79-
apkdir="$(dirname "$apk")"
80-
vdex="$(find "$apkdir" -type f -name '*.vdex')"
81-
if [[ "$vdex" ]]; then
82-
# If there is more than one match from find, the -f will test for "foo.vdex bar.vdex" and fail.
78+
# Generate classes.dex from .vdex, if necessary.
79+
if ! zipinfo "$tmpapk" classes.dex >/dev/null 2>&1; then
80+
apkdir="$(dirname "$apk")" # look next to original .apk
81+
vdex="$(find "$apkdir" -type f -name '*.vdex')"
82+
# If there is not exactly one match from find, the -f will test for "foo.vdex bar.vdex" (or "")
83+
# and fail.
8384
if [[ ! -f "$vdex" ]]; then
84-
echo "Multiple *.vdex files found in $apkdir, can't continue." >&2
85+
echo "Not exactly one *.vdex file found in $apkdir and APK has no classes.dex, can't continue." >&2
8586
exit 1
8687
fi
8788

0 commit comments

Comments
 (0)