From 96ec6a0384e4c710c36b99ccf88bb14c5addc7af Mon Sep 17 00:00:00 2001 From: Canny Date: Thu, 21 Jul 2022 17:26:23 +0300 Subject: [PATCH] fix: align every file --- .../app/revanced/cli/aligning/Aligning.kt | 19 +++++++++++++++++++ .../app/revanced/cli/command/MainCommand.kt | 7 +++++-- .../app/revanced/cli/signing/Signing.kt | 10 +++++----- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/app/revanced/cli/aligning/Aligning.kt diff --git a/src/main/kotlin/app/revanced/cli/aligning/Aligning.kt b/src/main/kotlin/app/revanced/cli/aligning/Aligning.kt new file mode 100644 index 00000000..da85fc2d --- /dev/null +++ b/src/main/kotlin/app/revanced/cli/aligning/Aligning.kt @@ -0,0 +1,19 @@ +package app.revanced.cli.aligning + +import app.revanced.cli.command.MainCommand +import app.revanced.cli.command.MainCommand.logger +import app.revanced.utils.signing.align.ZipAligner +import java.io.File + +object Aligning { + fun align(inputFile: File, outputFile: File) { + val cacheDirectory = File(MainCommand.args.sArgs?.pArgs?.cacheDirectory) + val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk") + + logger.info("Aligning ${inputFile.name}") + ZipAligner.align(inputFile, alignedOutput) + + logger.info("Copying ${alignedOutput.name} to ${outputFile.name}") + alignedOutput.copyTo(outputFile, true) + } + } diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index 0616a4a2..d0b057b3 100644 --- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt @@ -1,5 +1,6 @@ package app.revanced.cli.command +import app.revanced.cli.aligning.Aligning import app.revanced.cli.logging.impl.DefaultCliLogger import app.revanced.cli.patcher.Patcher import app.revanced.cli.patcher.logging.impl.PatcherLogger @@ -162,8 +163,7 @@ internal object MainCommand : Runnable { val adb: Adb? = _args.deploy?.let { Adb(outputFile, patcher.data.packageMetadata.packageName, _args.deploy!!, !args.mount) } - val patchedFile = if (args.mount) outputFile - else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk") + val patchedFile = File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk") Patcher.start(patcher, patchedFile) @@ -180,6 +180,9 @@ internal object MainCommand : Runnable { ) ) } + else { + Aligning.align(patchedFile, outputFile) + } if (args.clean) File(args.cacheDirectory).deleteRecursively() diff --git a/src/main/kotlin/app/revanced/cli/signing/Signing.kt b/src/main/kotlin/app/revanced/cli/signing/Signing.kt index 677316ff..2d441996 100644 --- a/src/main/kotlin/app/revanced/cli/signing/Signing.kt +++ b/src/main/kotlin/app/revanced/cli/signing/Signing.kt @@ -7,14 +7,14 @@ import app.revanced.utils.signing.align.ZipAligner import java.io.File object Signing { - fun start(inputFile: File, outputFile: File, signingOptions: SigningOptions) { + fun start(patchedFile: File, outputFile: File, signingOptions: SigningOptions) { val cacheDirectory = File(args.sArgs?.pArgs?.cacheDirectory) - val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk") val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk") + val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk") + + // align the patchedFile and write to alignedFile + ZipAligner.align(patchedFile, alignedOutput) - // align the inputFile and write to alignedOutput - logger.info("Aligning ${inputFile.name}") - ZipAligner.align(inputFile, alignedOutput) // sign the alignedOutput and write to signedOutput // the reason is, in case the signer fails // it does not damage the output file