fix: align every file

This commit is contained in:
Canny 2022-07-21 17:26:23 +03:00 committed by oSumAtrIX
parent 1cd0976415
commit 96ec6a0384
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 29 additions and 7 deletions

View File

@ -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)
}
}

View File

@ -1,5 +1,6 @@
package app.revanced.cli.command package app.revanced.cli.command
import app.revanced.cli.aligning.Aligning
import app.revanced.cli.logging.impl.DefaultCliLogger import app.revanced.cli.logging.impl.DefaultCliLogger
import app.revanced.cli.patcher.Patcher import app.revanced.cli.patcher.Patcher
import app.revanced.cli.patcher.logging.impl.PatcherLogger import app.revanced.cli.patcher.logging.impl.PatcherLogger
@ -162,8 +163,7 @@ internal object MainCommand : Runnable {
val adb: Adb? = _args.deploy?.let { val adb: Adb? = _args.deploy?.let {
Adb(outputFile, patcher.data.packageMetadata.packageName, _args.deploy!!, !args.mount) Adb(outputFile, patcher.data.packageMetadata.packageName, _args.deploy!!, !args.mount)
} }
val patchedFile = if (args.mount) outputFile val patchedFile = File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
Patcher.start(patcher, patchedFile) Patcher.start(patcher, patchedFile)
@ -180,6 +180,9 @@ internal object MainCommand : Runnable {
) )
) )
} }
else {
Aligning.align(patchedFile, outputFile)
}
if (args.clean) File(args.cacheDirectory).deleteRecursively() if (args.clean) File(args.cacheDirectory).deleteRecursively()

View File

@ -7,14 +7,14 @@ import app.revanced.utils.signing.align.ZipAligner
import java.io.File import java.io.File
object Signing { 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 cacheDirectory = File(args.sArgs?.pArgs?.cacheDirectory)
val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk")
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.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 // sign the alignedOutput and write to signedOutput
// the reason is, in case the signer fails // the reason is, in case the signer fails
// it does not damage the output file // it does not damage the output file