Skip to content

Commit 0850438

Browse files
committed
优化逆向文件格式互转脚本生成的文件名称
1 parent 984fa36 commit 0850438

File tree

6 files changed

+66
-18
lines changed

6 files changed

+66
-18
lines changed

shell/reverse-tools/convert/dex-class/ClassToDex.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ main() {
6565
fi
6666

6767
if [[ -d "${inputPath}" ]]; then
68-
outputDex="${classesDirPath%/}-class2dex-$(date "+%Y%m%d%H%M%S").dex"
68+
outputDex="${classesDirPath%/}.dex"
6969
else
70-
outputDex="${inputPath%.*}-class2dex-$(date "+%Y%m%d%H%M%S").dex"
70+
outputDex="${inputPath%.*}.dex"
71+
fi
72+
class2dexNameSuffix="-$(date "+%Y%m%d%H%M%S")"
73+
if [[ -f "${outputDex}" ]]; then
74+
outputDex="${outputDex%.*}${class2dexNameSuffix}.dex"
75+
elif [[ -d "${outputDex}" ]]; then
76+
if [[ "$(find "${outputDex}" -mindepth 1 | head -1)" ]]; then
77+
outputDex="${outputDex%.*}${class2dexNameSuffix}.dex"
78+
else
79+
rmdir "${outputDex}"
80+
fi
7181
fi
7282
outputPrint="$("${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-jar2dex.sh" -f -o "${outputDex}" "${tempJar}" 2>&1)"
7383
exitCode=$?

shell/reverse-tools/convert/dex-class/DexToClass.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,19 @@ main() {
4141
fi
4242

4343
tempJar="${inputFilePath%.*}.jar"
44-
classesDirPath="${inputFilePath%.*}-dex2class-$(date "+%Y%m%d%H%M%S")"
4544
echo "中间 jar 路径:${tempJar}"
45+
46+
classesDirPath="${inputFilePath%.*}"
47+
dex2classDirSuffix="-$(date "+%Y%m%d%H%M%S")"
48+
if [[ -f "${classesDirPath}" ]]; then
49+
classesDirPath="${classesDirPath}${dex2classDirSuffix}"
50+
elif [[ -d "${classesDirPath}" ]]; then
51+
if [[ "$(find "${classesDirPath}" -mindepth 1 | head -1)" ]]; then
52+
classesDirPath="${classesDirPath}${dex2classDirSuffix}"
53+
else
54+
rmdir "${classesDirPath}"
55+
fi
56+
fi
4657
echo "classes 输出目录:${classesDirPath}"
4758

4859
outputPrint="$("${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-dex2jar.sh" -f -o "${tempJar}" "${inputFilePath}" 2>&1)"

shell/reverse-tools/convert/dex-smali/DexToSmali.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ main() {
4040
exit 1
4141
fi
4242

43-
echo "请输入 smali 输出目录(可空,默认为同名 -dex2smali 目录)"
44-
read -r outputSmaliDirPath
45-
outputSmaliDirPath=$(parseComputerFilePath "${outputSmaliDirPath}")
46-
47-
if [[ -z "${outputSmaliDirPath}" ]]; then
48-
base="${inputDexFilePath%.*}"
49-
outputSmaliDirPath="${base}-dex2smali-$(date "+%Y%m%d%H%M%S")"
43+
outputSmaliDirPath="${inputDexFilePath%.*}"
44+
dex2smaliDirSuffix="-$(date "+%Y%m%d%H%M%S")"
45+
if [[ -f "${outputSmaliDirPath}" ]]; then
46+
outputSmaliDirPath="${outputSmaliDirPath}${dex2smaliDirSuffix}"
47+
elif [[ -d "${outputSmaliDirPath}" ]]; then
48+
if [[ "$(find "${outputSmaliDirPath}" -mindepth 1 | head -1)" ]]; then
49+
outputSmaliDirPath="${outputSmaliDirPath}${dex2smaliDirSuffix}"
50+
else
51+
rmdir "${outputSmaliDirPath}"
52+
fi
5053
fi
5154

5255
outputPrint="$(java -jar "${resourcesDirPath}$(getFileSeparator)baksmali-2.5.2.jar" d "${inputDexFilePath}" -o "${outputSmaliDirPath}" 2>&1)"

shell/reverse-tools/convert/dex-smali/SmaliToDex.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ main() {
3535
exit 1
3636
fi
3737

38-
echo "请输入生成的 dex 文件路径(可空,默认同名 .dex):"
39-
read -r outputDexFilePath
40-
outputDexFilePath=$(parseComputerFilePath "${outputDexFilePath}")
41-
42-
if [[ -z "${outputDexFilePath}" ]]; then
43-
outputDexFilePath="${inputSmaliDirPath}-smali2dex-$(date "+%Y%m%d%H%M%S").dex"
38+
outputDexFilePath="${inputSmaliDirPath%/}.dex"
39+
smali2dexNameSuffix="-$(date "+%Y%m%d%H%M%S")"
40+
if [[ -f "${outputDexFilePath}" ]]; then
41+
outputDexFilePath="${outputDexFilePath%.*}${smali2dexNameSuffix}.dex"
42+
elif [[ -d "${outputDexFilePath}" ]]; then
43+
if [[ "$(find "${outputDexFilePath}" -mindepth 1 | head -1)" ]]; then
44+
outputDexFilePath="${outputDexFilePath%.*}${smali2dexNameSuffix}.dex"
45+
else
46+
rmdir "${outputDexFilePath}"
47+
fi
4448
fi
4549

4650
outputPrint="$(java -jar "${resourcesDirPath}$(getFileSeparator)smali-2.5.2.jar" a "${inputSmaliDirPath}" -o "${outputDexFilePath}" 2>&1)"

shell/reverse-tools/convert/jar-dex/DexToJar.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,17 @@ main() {
4040
exit 1
4141
fi
4242

43-
outputFilePath="${inputFilePath%.*}-dex2jar-$(date "+%Y%m%d%H%M%S").jar"
43+
outputFilePath="${inputFilePath%.*}.jar"
44+
dex2jarNameSuffix="-$(date "+%Y%m%d%H%M%S")"
45+
if [[ -f "${outputFilePath}" ]]; then
46+
outputFilePath="${outputFilePath%.*}${dex2jarNameSuffix}.jar"
47+
elif [[ -d "${outputFilePath}" ]]; then
48+
if [[ "$(find "${outputFilePath}" -mindepth 1 | head -1)" ]]; then
49+
outputFilePath="${outputFilePath%.*}${dex2jarNameSuffix}.jar"
50+
else
51+
rmdir "${outputFilePath}"
52+
fi
53+
fi
4454
echo "输出的 jar 文件路径:${outputFilePath}"
4555

4656
outputPrint="$("${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-dex2jar.sh" -f -o "${outputFilePath}" "${inputFilePath}" 2>&1)"

shell/reverse-tools/convert/jar-dex/JarToDex.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,17 @@ main() {
3939
exit 1
4040
fi
4141

42-
outputFilePath="${inputFilePath%.*}-jar2dex-$(date "+%Y%m%d%H%M%S").dex"
42+
outputFilePath="${inputFilePath%.*}.dex"
43+
jar2dexNameSuffix="-$(date "+%Y%m%d%H%M%S")"
44+
if [[ -f "${outputFilePath}" ]]; then
45+
outputFilePath="${outputFilePath%.*}${jar2dexNameSuffix}.dex"
46+
elif [[ -d "${outputFilePath}" ]]; then
47+
if [[ "$(find "${outputFilePath}" -mindepth 1 | head -1)" ]]; then
48+
outputFilePath="${outputFilePath%.*}${jar2dexNameSuffix}.dex"
49+
else
50+
rmdir "${outputFilePath}"
51+
fi
52+
fi
4353
echo "输出的 dex 文件路径:${outputFilePath}"
4454

4555
outputPrint="$("${resourcesDirPath}$(getFileSeparator)dex2jar-2.4$(getFileSeparator)d2j-jar2dex.sh" -f -o "${outputFilePath}" "${inputFilePath}" 2>&1)"

0 commit comments

Comments
 (0)