Skip to content

Commit 4df1e5e

Browse files
committed
优化 apktool 反编译和回编译的路径处理
1 parent f037be2 commit 4df1e5e

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

shell/reverse-tools/apktool/DecompileApk.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,29 @@ waitUserInputParameter() {
3737
read -r apkDecompileDirPath
3838
apkDecompileDirPath=$(parseComputerFilePath "${apkDecompileDirPath}")
3939

40-
decompileDirNameSuffix="-decompile-$(date "+%Y%m%d%H%M%S")"
4140
if [[ -z "${apkDecompileDirPath}" ]]; then
42-
apkDecompileDirPath="${sourceApkFilePath%.*}${decompileDirNameSuffix}"
41+
apkDecompileDirPath="${sourceApkFilePath%.*}"
4342
else
44-
apkDecompileDirPath="${apkDecompileDirPath}$(getFileSeparator)$(basename "${sourceApkFilePath%.*}")${decompileDirNameSuffix}"
43+
apkDecompileDirPath="${apkDecompileDirPath}$(getFileSeparator)$(basename "${sourceApkFilePath%.*}")"
44+
fi
45+
46+
decompileDirNameSuffix="-decompile-$(date "+%Y%m%d%H%M%S")"
47+
if [[ -f "${apkDecompileDirPath}" ]]; then
48+
apkDecompileDirPath="${apkDecompileDirPath}${decompileDirNameSuffix}"
49+
elif [[ -d "${apkDecompileDirPath}" && "$(find "${apkDecompileDirPath}" -mindepth 1 | head -1)" ]]; then
50+
echo "该目录已经存在且不为空,是否覆盖原有内容?(y/n)"
51+
while true; do
52+
read -r rewriteConfirm
53+
if [[ "${rewriteConfirm}" =~ ^[yY]$ ]]; then
54+
break
55+
elif [[ "${rewriteConfirm}" =~ ^[nN]$ ]]; then
56+
apkDecompileDirPath="${apkDecompileDirPath}${decompileDirNameSuffix}"
57+
break
58+
else
59+
echo "👻 输入不正确,请输入正确的选项(y/n)"
60+
continue
61+
fi
62+
done
4563
fi
4664

4765
local apktoolJarFileName="apktool-2.12.1.jar"

shell/reverse-tools/apktool/RecompileApk.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,30 @@ waitUserInputParameter() {
3333
outputApkFilePath=$(parseComputerFilePath "${outputApkFilePath}")
3434

3535
if [[ -z "${outputApkFilePath}" ]]; then
36-
base="${sourceDirPath%/}"
37-
outputApkFilePath="${base}-recompile-$(date "+%Y%m%d%H%M%S").apk"
36+
outputApkFilePath="${sourceDirPath%/}.apk"
37+
fi
38+
39+
recompileApkNameSuffix="-recompile-$(date "+%Y%m%d%H%M%S").apk"
40+
if [[ -f "${outputApkFilePath}" ]]; then
41+
echo "该文件已经存在,是否覆盖原有内容?(y/n)"
42+
while true; do
43+
read -r rewriteConfirm
44+
if [[ "${rewriteConfirm}" =~ ^[yY]$ ]]; then
45+
break
46+
elif [[ "${rewriteConfirm}" =~ ^[nN]$ ]]; then
47+
outputApkFilePath="${outputApkFilePath%.*}${recompileApkNameSuffix}"
48+
break
49+
else
50+
echo "👻 输入不正确,请输入正确的选项(y/n)"
51+
continue
52+
fi
53+
done
54+
elif [[ -d "${outputApkFilePath}" ]]; then
55+
if [[ "$(find "${outputApkFilePath}" -mindepth 1 | head -1)" ]]; then
56+
outputApkFilePath="${outputApkFilePath%.*}${recompileApkNameSuffix}"
57+
else
58+
rmdir "${outputApkFilePath}"
59+
fi
3860
fi
3961

4062
local apktoolJarFileName="apktool-2.12.1.jar"

0 commit comments

Comments
 (0)