diff --git a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt index f507845a..19ebef68 100644 --- a/src/main/kotlin/app/revanced/cli/command/MainCommand.kt +++ b/src/main/kotlin/app/revanced/cli/command/MainCommand.kt @@ -10,11 +10,14 @@ import app.revanced.utils.adb.Adb import picocli.CommandLine.* import java.io.File import java.nio.file.Files +import java.util.logging.Logger @Command( name = "ReVanced-CLI", version = ["1.0.0"], mixinStandardHelpOptions = true ) internal object MainCommand : Runnable { + val logger: Logger = Logger.getLogger(MainCommand.javaClass.name) + @ArgGroup(exclusive = false, multiplicity = "1") lateinit var args: Args @@ -76,15 +79,19 @@ internal object MainCommand : Runnable { } override fun run() { + System.setProperty("java.util.logging.SimpleFormatter.format", "%4\$s: %5\$s %n") + if (args.lArgs?.listOnly == true) { for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle(patchBundlePath).loadPatches()) { - println("[available] ${patch.patchName}: ${patch.description}") + logger.info("${patch.patchName}: ${patch.description}") } return } val args = args.pArgs ?: return + logger.info("Initialize patcher") + val patcher = app.revanced.patcher.Patcher( PatcherOptions( args.inputFile, args.cacheDirectory, !args.disableResourcePatching @@ -102,8 +109,6 @@ internal object MainCommand : Runnable { Patcher.start(patcher, patchedFile) - println("[aligning & signing]") - if (!args.mount) { Signing.start( patchedFile, @@ -115,13 +120,10 @@ internal object MainCommand : Runnable { if (args.clean) File(args.cacheDirectory).deleteRecursively() - adb?.let { - println("[deploying]") - it.deploy() - } + adb?.deploy() if (args.clean && args.deploy != null) Files.delete(outputFile.toPath()) - println("[done]") + logger.info("Done") } } diff --git a/src/main/kotlin/app/revanced/cli/patcher/Patcher.kt b/src/main/kotlin/app/revanced/cli/patcher/Patcher.kt index 7962788e..ce4f6582 100644 --- a/src/main/kotlin/app/revanced/cli/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/cli/patcher/Patcher.kt @@ -1,6 +1,7 @@ package app.revanced.cli.patcher import app.revanced.cli.command.MainCommand.args +import app.revanced.cli.command.MainCommand.logger import app.revanced.utils.filesystem.ZipFileSystemUtils import app.revanced.utils.patcher.addPatchesFiltered import app.revanced.utils.patcher.applyPatchesVerbose @@ -30,9 +31,13 @@ internal object Patcher { ZipFileSystemUtils(inputFile, output).use { fileSystem -> // replace all dex files result.dexFiles.forEach { + logger.info("Write ${it.name}") + fileSystem.write(it.name, it.dexFileInputStream.readAllBytes()) } + logger.info("Write resources") + // inputFile being null implies resource patching being disabled if (inputFile != null) { // write resources diff --git a/src/main/kotlin/app/revanced/cli/signing/Signing.kt b/src/main/kotlin/app/revanced/cli/signing/Signing.kt index c0ed8930..4a6d1fd7 100644 --- a/src/main/kotlin/app/revanced/cli/signing/Signing.kt +++ b/src/main/kotlin/app/revanced/cli/signing/Signing.kt @@ -1,6 +1,7 @@ package app.revanced.cli.signing import app.revanced.cli.command.MainCommand.args +import app.revanced.cli.command.MainCommand.logger import app.revanced.utils.signing.Signer import app.revanced.utils.signing.align.ZipAligner import java.io.File @@ -11,8 +12,13 @@ object Signing { val alignedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_aligned.apk") val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk") + logger.info("Align zip entries") + // align the inputFile and write to alignedOutput ZipAligner.align(inputFile, alignedOutput) + + logger.info("Sign zip file") + // sign the alignedOutput and write to signedOutput // the reason is, in case the signer fails // it does not damage the output file diff --git a/src/main/kotlin/app/revanced/utils/adb/Adb.kt b/src/main/kotlin/app/revanced/utils/adb/Adb.kt index 95339943..e21630f1 100644 --- a/src/main/kotlin/app/revanced/utils/adb/Adb.kt +++ b/src/main/kotlin/app/revanced/utils/adb/Adb.kt @@ -1,5 +1,6 @@ package app.revanced.utils.adb +import app.revanced.cli.command.MainCommand.logger import se.vidstige.jadb.JadbConnection import se.vidstige.jadb.JadbDevice import se.vidstige.jadb.managers.PackageManager @@ -29,8 +30,12 @@ internal class Adb( internal fun deploy() { if (modeInstall) { + logger.info("Install without mount") + PackageManager(device).install(file) } else { + logger.info("Install by mount") + // push patched file device.copy(Constants.PATH_INIT_PUSH, file) diff --git a/src/main/kotlin/app/revanced/utils/patcher/Patcher.kt b/src/main/kotlin/app/revanced/utils/patcher/Patcher.kt index b78858ba..f286dcad 100644 --- a/src/main/kotlin/app/revanced/utils/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/utils/patcher/Patcher.kt @@ -2,6 +2,7 @@ package app.revanced.utils.patcher import app.revanced.cli.command.MainCommand import app.revanced.cli.command.MainCommand.args +import app.revanced.cli.command.MainCommand.logger import app.revanced.patcher.Patcher import app.revanced.patcher.data.base.Data import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages @@ -22,33 +23,34 @@ fun Patcher.addPatchesFiltered( val compatiblePackages = patch.compatiblePackages val patchName = patch.patchName - val prefix = "[skipped] $patchName" + val prefix = "Skip $patchName" val args = MainCommand.args.pArgs!! if (excludePatches && args.excludedPatches.contains(patchName)) { - println("$prefix: Explicitly excluded.") + logger.info("$prefix: Explicitly excluded") return@patch } else if (!patch.include) { - println("$prefix: Implicitly excluded.") + logger.info("$prefix: Implicitly excluded") return@patch } - if (compatiblePackages == null) println("$prefix: Missing compatibility annotation. Continuing.") + if (compatiblePackages == null) logger.warning("$prefix: Missing compatibility annotation. Continuing.") else { if (!compatiblePackages.any { it.name == packageName }) { - println("$prefix: Incompatible package.") + logger.info("$prefix: Incompatible package") return@patch } if (!(args.experimental || compatiblePackages.any { it.versions.isEmpty() || it.versions.any { version -> version == packageVersion } })) { - println("$prefix: The package version is $packageVersion and is incompatible.") + logger.info("$prefix: The package version is $packageVersion and is incompatible") return@patch } } + logger.info("Add $patchName") + includedPatches.add(patch) - println("[added] $patchName") } this.addPatches(includedPatches) } @@ -57,10 +59,12 @@ fun Patcher.addPatchesFiltered( fun Patcher.applyPatchesVerbose() { this.applyPatches().forEach { (patch, result) -> if (result.isSuccess) { - println("[success] $patch") + logger.info("Success: $patch") + return@forEach } - println("[error] $patch:") + logger.severe("Error: $patch") + result.exceptionOrNull()!!.printStackTrace() } }