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