mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-11 22:06:20 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce78b245d1 | ||
|
|
d7cffea99c | ||
|
|
9331594706 | ||
|
|
07f6bdf330 | ||
|
|
a48c0860e3 | ||
|
|
4d5efab8bd | ||
|
|
b30c7375a7 | ||
|
|
f694542d64 | ||
|
|
6f54af5963 | ||
|
|
0a52180431 | ||
|
|
af32572f29 | ||
|
|
e126436f3d | ||
|
|
80c11fef73 |
30
CHANGELOG.md
30
CHANGELOG.md
@@ -1,3 +1,33 @@
|
||||
# [1.8.0](https://github.com/revanced/revanced-cli/compare/v1.7.1...v1.8.0) (2022-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add option to specify keystore file path ([9331594](https://github.com/revanced/revanced-cli/commit/9331594706404df871d170110da753cde5058d02))
|
||||
* use of `java.util.logging.Logger` ([07f6bdf](https://github.com/revanced/revanced-cli/commit/07f6bdf33069da4e11fc40090feb726433de703e))
|
||||
|
||||
## [1.7.1](https://github.com/revanced/revanced-cli/compare/v1.7.0...v1.7.1) (2022-06-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* migrate to changes of patcher ([b30c737](https://github.com/revanced/revanced-cli/commit/b30c7375a7ea61184be5dca19062ee74d1f97692))
|
||||
* wrong variable inverted ([f694542](https://github.com/revanced/revanced-cli/commit/f694542d64ccb06bfa4d042f26b6b7192d1e912e))
|
||||
|
||||
# [1.7.0](https://github.com/revanced/revanced-cli/compare/v1.6.3...v1.7.0) (2022-06-21)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* show description when listing patches ([af32572](https://github.com/revanced/revanced-cli/commit/af32572f29d0f0a45ee5c3e01ba4cf1f91fe2f10))
|
||||
|
||||
## [1.6.3](https://github.com/revanced/revanced-cli/compare/v1.6.2...v1.6.3) (2022-06-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update patcher version ([80c11fe](https://github.com/revanced/revanced-cli/commit/80c11fef734bdba9026e91f95ee0a4a522cbefab))
|
||||
|
||||
## [1.6.2](https://github.com/revanced/revanced-cli/compare/v1.6.1...v1.6.2) (2022-06-21)
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ dependencies {
|
||||
implementation(kotlin("stdlib"))
|
||||
implementation(kotlin("reflect"))
|
||||
|
||||
implementation("app.revanced:revanced-patcher:1.3.3")
|
||||
implementation("app.revanced:revanced-patcher:1.6.0")
|
||||
implementation("info.picocli:picocli:4.6.3")
|
||||
implementation("com.android.tools.build:apksig:7.2.1")
|
||||
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
kotlin.code.style = official
|
||||
version = 1.6.2
|
||||
version = 1.8.0
|
||||
|
||||
@@ -2,20 +2,25 @@ package app.revanced.cli.command
|
||||
|
||||
import app.revanced.cli.patcher.Patcher
|
||||
import app.revanced.cli.signing.Signing
|
||||
import app.revanced.cli.signing.SigningOptions
|
||||
import app.revanced.patcher.PatcherOptions
|
||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
|
||||
import app.revanced.utils.adb.Adb
|
||||
import picocli.CommandLine.*
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.logging.Logger
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.name
|
||||
|
||||
@Command(
|
||||
name = "ReVanced-CLI",
|
||||
version = ["1.0.0"],
|
||||
mixinStandardHelpOptions = true
|
||||
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
|
||||
|
||||
@@ -60,6 +65,9 @@ internal object MainCommand : Runnable {
|
||||
@Option(names = ["--cn"], description = ["Overwrite the default CN for the signed file"])
|
||||
var cn = "ReVanced"
|
||||
|
||||
@Option(names = ["--keystore"], description = ["File path to your keystore"])
|
||||
var keystorePath: String? = null
|
||||
|
||||
@Option(names = ["-p", "--password"], description = ["Overwrite the default password for the signed file"])
|
||||
var password = "ReVanced"
|
||||
|
||||
@@ -77,15 +85,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}")
|
||||
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
|
||||
@@ -98,32 +110,28 @@ internal object MainCommand : Runnable {
|
||||
Adb(outputFile, patcher.data.packageMetadata.packageName, args.deploy!!, !args.mount)
|
||||
}
|
||||
|
||||
val patchedFile = if (args.mount) {
|
||||
File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
||||
} else outputFile
|
||||
val patchedFile = if (args.mount) outputFile
|
||||
else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
||||
|
||||
Patcher.start(patcher, patchedFile)
|
||||
|
||||
println("[aligning & signing]")
|
||||
|
||||
if (!args.mount) {
|
||||
Signing.start(
|
||||
patchedFile,
|
||||
outputFile,
|
||||
args.cn,
|
||||
args.password,
|
||||
patchedFile, outputFile, SigningOptions(
|
||||
args.cn,
|
||||
args.password,
|
||||
args.keystorePath
|
||||
?: Path(outputFile.parent).resolve("${outputFile.nameWithoutExtension}.keystore").name
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
fileSystem.write(it.name, it.memoryDataStore.data)
|
||||
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
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
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
|
||||
|
||||
object Signing {
|
||||
fun start(inputFile: File, outputFile: File, cn: String, password: String) {
|
||||
fun start(inputFile: File, outputFile: File, signingOptions: SigningOptions) {
|
||||
val cacheDirectory = File(args.pArgs!!.cacheDirectory)
|
||||
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
|
||||
val keyStore = Signer(cn, password).signApk(alignedOutput, signedOutput)
|
||||
val keyStore = Signer(signingOptions).signApk(alignedOutput, signedOutput)
|
||||
|
||||
// afterwards copy over the file and the keystore to the output
|
||||
signedOutput.copyTo(outputFile, true)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package app.revanced.cli.signing
|
||||
|
||||
data class SigningOptions(
|
||||
val cn: String,
|
||||
val password: String,
|
||||
val keyStoreFilePath: String
|
||||
)
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package app.revanced.utils.signature
|
||||
|
||||
import app.revanced.patcher.Patcher
|
||||
import org.jf.dexlib2.iface.Method
|
||||
|
||||
object Signature {
|
||||
|
||||
@@ -49,7 +48,7 @@ object Signature {
|
||||
*/
|
||||
}
|
||||
|
||||
private fun Method.toStr(): String {
|
||||
return "${this.name}(${this.parameterTypes.joinToString("")})${this.returnType}"
|
||||
}
|
||||
//private fun Method.toStr(): String {
|
||||
// return "${this.name}(${this.parameterTypes.joinToString("")})${this.returnType}"
|
||||
//}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package app.revanced.utils.signing
|
||||
|
||||
import app.revanced.cli.command.MainCommand.logger
|
||||
import app.revanced.cli.signing.SigningOptions
|
||||
import com.android.apksig.ApkSigner
|
||||
import org.bouncycastle.asn1.x500.X500Name
|
||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
|
||||
@@ -17,9 +19,9 @@ import java.security.cert.X509Certificate
|
||||
import java.util.*
|
||||
|
||||
internal class Signer(
|
||||
private val cn: String, password: String
|
||||
private val signingOptions: SigningOptions
|
||||
) {
|
||||
private val passwordCharArray = password.toCharArray()
|
||||
private val passwordCharArray = signingOptions.password.toCharArray()
|
||||
private fun newKeystore(out: File) {
|
||||
val (publicKey, privateKey) = createKey()
|
||||
val privateKS = KeyStore.getInstance("BKS", "BC")
|
||||
@@ -34,7 +36,7 @@ internal class Signer(
|
||||
val pair = gen.generateKeyPair()
|
||||
var serialNumber: BigInteger
|
||||
do serialNumber = BigInteger.valueOf(SecureRandom().nextLong()) while (serialNumber < BigInteger.ZERO)
|
||||
val x500Name = X500Name("CN=$cn")
|
||||
val x500Name = X500Name("CN=${signingOptions.cn}")
|
||||
val builder = X509v3CertificateBuilder(
|
||||
x500Name,
|
||||
serialNumber,
|
||||
@@ -52,21 +54,21 @@ internal class Signer(
|
||||
Security.addProvider(BouncyCastleProvider())
|
||||
|
||||
// TODO: keystore should be saved securely
|
||||
val ks = File(input.parent, "${output.nameWithoutExtension}.keystore")
|
||||
if (!ks.exists()) newKeystore(ks)
|
||||
val ks = File(signingOptions.keyStoreFilePath)
|
||||
if (!ks.exists()) newKeystore(ks) else logger.info("Found existing keystore ${ks.nameWithoutExtension}")
|
||||
|
||||
val keyStore = KeyStore.getInstance("BKS", "BC")
|
||||
FileInputStream(ks).use { fis -> keyStore.load(fis, null) }
|
||||
val alias = keyStore.aliases().nextElement()
|
||||
|
||||
val config = ApkSigner.SignerConfig.Builder(
|
||||
cn,
|
||||
signingOptions.cn,
|
||||
keyStore.getKey(alias, passwordCharArray) as PrivateKey,
|
||||
listOf(keyStore.getCertificate(alias) as X509Certificate)
|
||||
).build()
|
||||
|
||||
val signer = ApkSigner.Builder(listOf(config))
|
||||
signer.setCreatedBy(cn)
|
||||
signer.setCreatedBy(signingOptions.cn)
|
||||
signer.setInputApk(input)
|
||||
signer.setOutputApk(output)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user