mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-18 17:03:58 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61d3b99313 | ||
|
|
5b8537e6b7 | ||
|
|
7d8a61c3ba | ||
|
|
1dcdbc9fe9 | ||
|
|
4cc2f5269f | ||
|
|
46056956fe | ||
|
|
8e3d147690 | ||
|
|
87ffaa4bdb | ||
|
|
8a49dcc110 | ||
|
|
4a23cb69bc | ||
|
|
8c325af0f9 | ||
|
|
a26ab2a2c3 | ||
|
|
d335846202 | ||
|
|
6fc3ae67c8 | ||
|
|
0df936e99b | ||
|
|
83743929c8 | ||
|
|
51e091ce40 | ||
|
|
e5a37e0a5f | ||
|
|
c94471f464 | ||
|
|
bfd50a43b9 | ||
|
|
2c8a106151 | ||
|
|
ea7efd2afc | ||
|
|
6c4c1924ee | ||
|
|
ce78b245d1 | ||
|
|
d7cffea99c | ||
|
|
9331594706 | ||
|
|
07f6bdf330 | ||
|
|
a48c0860e3 |
68
CHANGELOG.md
68
CHANGELOG.md
@@ -1,3 +1,71 @@
|
|||||||
|
## [1.10.2](https://github.com/revanced/revanced-cli/compare/v1.10.1...v1.10.2) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* keystore file not found exception ([#57](https://github.com/revanced/revanced-cli/issues/57)) ([5b8537e](https://github.com/revanced/revanced-cli/commit/5b8537e6b7922f1b44058c3a4fc2f56cb4e15e89))
|
||||||
|
|
||||||
|
## [1.10.1](https://github.com/revanced/revanced-cli/compare/v1.10.0...v1.10.1) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* show actual version in CLI ([1dcdbc9](https://github.com/revanced/revanced-cli/commit/1dcdbc9fe9e3ad2fe232ad3baa76d186817532a4))
|
||||||
|
|
||||||
|
# [1.10.0](https://github.com/revanced/revanced-cli/compare/v1.9.3...v1.10.0) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add callback for addFiles ([87ffaa4](https://github.com/revanced/revanced-cli/commit/87ffaa4bdb25cb85c6ba7195f5d3b13b09a5f912))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add logging back ([4a23cb6](https://github.com/revanced/revanced-cli/commit/4a23cb69bc385158d47b6ea8d3da54b0566a242c))
|
||||||
|
|
||||||
|
## [1.9.3](https://github.com/revanced/revanced-cli/compare/v1.9.2...v1.9.3) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* use absolute file path for key store ([d335846](https://github.com/revanced/revanced-cli/commit/d335846202b991e130882e9ce0ab268deb2e27ab))
|
||||||
|
|
||||||
|
## [1.9.2](https://github.com/revanced/revanced-cli/compare/v1.9.1...v1.9.2) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* update patcher version ([0df936e](https://github.com/revanced/revanced-cli/commit/0df936e99b01358a88a628af63eebb5ac92cae76))
|
||||||
|
|
||||||
|
## [1.9.1](https://github.com/revanced/revanced-cli/compare/v1.9.0...v1.9.1) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add back in: option to specify keystore file path ([c94471f](https://github.com/revanced/revanced-cli/commit/c94471f4643e44b2b472ff0d826db0d2743bdc86))
|
||||||
|
* remove logger from Signer.kt ([51e091c](https://github.com/revanced/revanced-cli/commit/51e091ce4021418508044029aa5af6aa7d5162a3))
|
||||||
|
|
||||||
|
|
||||||
|
### Reverts
|
||||||
|
|
||||||
|
* "feat: use of `java.util.logging.Logger`" ([2c8a106](https://github.com/revanced/revanced-cli/commit/2c8a10615192635202ddc137fc02f175c5914d8f))
|
||||||
|
|
||||||
|
# [1.9.0](https://github.com/revanced/revanced-cli/compare/v1.8.0...v1.9.0) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* migrate logger to `slf4j` ([6c4c192](https://github.com/revanced/revanced-cli/commit/6c4c1924ee9ae75af3449749a6a82b7ae5572129))
|
||||||
|
|
||||||
|
# [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)
|
## [1.7.1](https://github.com/revanced/revanced-cli/compare/v1.7.0...v1.7.1) (2022-06-22)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ dependencies {
|
|||||||
implementation(kotlin("stdlib"))
|
implementation(kotlin("stdlib"))
|
||||||
implementation(kotlin("reflect"))
|
implementation(kotlin("reflect"))
|
||||||
|
|
||||||
implementation("app.revanced:revanced-patcher:1.5.0")
|
implementation("app.revanced:revanced-patcher:1.7.2")
|
||||||
implementation("info.picocli:picocli:4.6.3")
|
implementation("info.picocli:picocli:4.6.3")
|
||||||
implementation("com.android.tools.build:apksig:7.2.1")
|
implementation("com.android.tools.build:apksig:7.2.1")
|
||||||
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
|
implementation("com.github.revanced:jadb:master-SNAPSHOT") // updated fork
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 1.7.1
|
version = 1.10.2
|
||||||
|
|||||||
@@ -1,20 +1,28 @@
|
|||||||
package app.revanced.cli.command
|
package app.revanced.cli.command
|
||||||
|
|
||||||
import app.revanced.cli.patcher.Patcher
|
import app.revanced.cli.patcher.Patcher
|
||||||
|
import app.revanced.cli.patcher.PatcherLogger
|
||||||
import app.revanced.cli.signing.Signing
|
import app.revanced.cli.signing.Signing
|
||||||
|
import app.revanced.cli.signing.SigningOptions
|
||||||
import app.revanced.patcher.PatcherOptions
|
import app.revanced.patcher.PatcherOptions
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
|
||||||
import app.revanced.patcher.extensions.PatchExtensions.description
|
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.patcher.util.patch.implementation.JarPatchBundle
|
||||||
import app.revanced.utils.adb.Adb
|
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
|
||||||
|
|
||||||
|
private class CLIVersionProvider : IVersionProvider {
|
||||||
|
override fun getVersion() = arrayOf(
|
||||||
|
MainCommand::class.java.`package`.implementationVersion ?: "unknown"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
name = "ReVanced-CLI",
|
name = "ReVanced-CLI",
|
||||||
version = ["1.0.0"],
|
mixinStandardHelpOptions = true,
|
||||||
mixinStandardHelpOptions = true
|
versionProvider = CLIVersionProvider::class
|
||||||
)
|
)
|
||||||
internal object MainCommand : Runnable {
|
internal object MainCommand : Runnable {
|
||||||
@ArgGroup(exclusive = false, multiplicity = "1")
|
@ArgGroup(exclusive = false, multiplicity = "1")
|
||||||
@@ -61,6 +69,9 @@ internal object MainCommand : Runnable {
|
|||||||
@Option(names = ["--cn"], description = ["Overwrite the default CN for the signed file"])
|
@Option(names = ["--cn"], description = ["Overwrite the default CN for the signed file"])
|
||||||
var cn = "ReVanced"
|
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"])
|
@Option(names = ["-p", "--password"], description = ["Overwrite the default password for the signed file"])
|
||||||
var password = "ReVanced"
|
var password = "ReVanced"
|
||||||
|
|
||||||
@@ -89,7 +100,10 @@ internal object MainCommand : Runnable {
|
|||||||
|
|
||||||
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,
|
||||||
|
logger = PatcherLogger
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -99,20 +113,22 @@ internal object MainCommand : Runnable {
|
|||||||
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) {
|
val patchedFile = if (args.mount) outputFile
|
||||||
File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
else File(args.cacheDirectory).resolve("${outputFile.nameWithoutExtension}_raw.apk")
|
||||||
} else outputFile
|
|
||||||
|
|
||||||
Patcher.start(patcher, patchedFile)
|
Patcher.start(patcher, patchedFile)
|
||||||
|
|
||||||
println("[aligning & signing]")
|
|
||||||
|
|
||||||
if (!args.mount) {
|
if (!args.mount) {
|
||||||
Signing.start(
|
Signing.start(
|
||||||
patchedFile,
|
patchedFile,
|
||||||
outputFile,
|
outputFile,
|
||||||
args.cn,
|
SigningOptions(
|
||||||
args.password,
|
args.cn,
|
||||||
|
args.password,
|
||||||
|
args.keystorePath ?: outputFile.absoluteFile.parentFile
|
||||||
|
.resolve("${outputFile.nameWithoutExtension}.keystore")
|
||||||
|
.name
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/main/kotlin/app/revanced/cli/patcher/PatcherLogger.kt
Normal file
23
src/main/kotlin/app/revanced/cli/patcher/PatcherLogger.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package app.revanced.cli.patcher
|
||||||
|
|
||||||
|
import app.revanced.patcher.PatchLogger
|
||||||
|
|
||||||
|
object PatcherLogger : PatchLogger {
|
||||||
|
private const val prefix = "[patcher]"
|
||||||
|
|
||||||
|
override fun error(msg: String) {
|
||||||
|
println("error: $prefix: $msg")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun info(msg: String) {
|
||||||
|
println("info: $prefix: $msg")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun trace(msg: String) {
|
||||||
|
println("trace: $prefix: $msg")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun warn(msg: String) {
|
||||||
|
println("warn: $prefix: $msg")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,20 +6,21 @@ 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, cn: String, password: String) {
|
fun start(inputFile: File, outputFile: File, signingOptions: SigningOptions) {
|
||||||
val cacheDirectory = File(args.pArgs!!.cacheDirectory)
|
val cacheDirectory = File(args.pArgs!!.cacheDirectory)
|
||||||
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")
|
||||||
|
|
||||||
// align the inputFile and write to alignedOutput
|
// align the inputFile and write to alignedOutput
|
||||||
|
println("[aligning]")
|
||||||
ZipAligner.align(inputFile, alignedOutput)
|
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
|
||||||
val keyStore = Signer(cn, password).signApk(alignedOutput, signedOutput)
|
println("[signing]")
|
||||||
|
Signer(signingOptions).signApk(alignedOutput, signedOutput)
|
||||||
|
|
||||||
// afterwards copy over the file and the keystore to the output
|
// afterwards copy over the file to the output
|
||||||
signedOutput.copyTo(outputFile, true)
|
signedOutput.copyTo(outputFile, true)
|
||||||
keyStore.copyTo(outputFile.resolveSibling(keyStore.name), true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package app.revanced.cli.signing
|
||||||
|
|
||||||
|
data class SigningOptions(
|
||||||
|
val cn: String,
|
||||||
|
val password: String,
|
||||||
|
val keyStoreFilePath: String
|
||||||
|
)
|
||||||
@@ -66,5 +66,7 @@ fun Patcher.applyPatchesVerbose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun Patcher.mergeFiles() {
|
fun Patcher.mergeFiles() {
|
||||||
this.addFiles(args.pArgs!!.mergeFiles)
|
this.addFiles(args.pArgs!!.mergeFiles) {
|
||||||
|
println("[merged] ${it.name}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package app.revanced.utils.signing
|
package app.revanced.utils.signing
|
||||||
|
|
||||||
|
import app.revanced.cli.signing.SigningOptions
|
||||||
import com.android.apksig.ApkSigner
|
import com.android.apksig.ApkSigner
|
||||||
import org.bouncycastle.asn1.x500.X500Name
|
import org.bouncycastle.asn1.x500.X500Name
|
||||||
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
|
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
|
||||||
@@ -17,9 +18,9 @@ import java.security.cert.X509Certificate
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
internal class Signer(
|
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) {
|
private fun newKeystore(out: File) {
|
||||||
val (publicKey, privateKey) = createKey()
|
val (publicKey, privateKey) = createKey()
|
||||||
val privateKS = KeyStore.getInstance("BKS", "BC")
|
val privateKS = KeyStore.getInstance("BKS", "BC")
|
||||||
@@ -34,7 +35,7 @@ internal class Signer(
|
|||||||
val pair = gen.generateKeyPair()
|
val pair = gen.generateKeyPair()
|
||||||
var serialNumber: BigInteger
|
var serialNumber: BigInteger
|
||||||
do serialNumber = BigInteger.valueOf(SecureRandom().nextLong()) while (serialNumber < BigInteger.ZERO)
|
do serialNumber = BigInteger.valueOf(SecureRandom().nextLong()) while (serialNumber < BigInteger.ZERO)
|
||||||
val x500Name = X500Name("CN=$cn")
|
val x500Name = X500Name("CN=${signingOptions.cn}")
|
||||||
val builder = X509v3CertificateBuilder(
|
val builder = X509v3CertificateBuilder(
|
||||||
x500Name,
|
x500Name,
|
||||||
serialNumber,
|
serialNumber,
|
||||||
@@ -48,30 +49,30 @@ internal class Signer(
|
|||||||
return JcaX509CertificateConverter().getCertificate(builder.build(signer)) to pair.private
|
return JcaX509CertificateConverter().getCertificate(builder.build(signer)) to pair.private
|
||||||
}
|
}
|
||||||
|
|
||||||
fun signApk(input: File, output: File): File {
|
fun signApk(input: File, output: File) {
|
||||||
Security.addProvider(BouncyCastleProvider())
|
Security.addProvider(BouncyCastleProvider())
|
||||||
|
|
||||||
// TODO: keystore should be saved securely
|
// TODO: keystore should be saved securely
|
||||||
val ks = File(input.parent, "${output.nameWithoutExtension}.keystore")
|
val ks = File(signingOptions.keyStoreFilePath)
|
||||||
if (!ks.exists()) newKeystore(ks)
|
if (!ks.exists()) newKeystore(ks) else {
|
||||||
|
println("[found] existing keystore: ${ks.nameWithoutExtension}")
|
||||||
|
}
|
||||||
|
|
||||||
val keyStore = KeyStore.getInstance("BKS", "BC")
|
val keyStore = KeyStore.getInstance("BKS", "BC")
|
||||||
FileInputStream(ks).use { fis -> keyStore.load(fis, null) }
|
FileInputStream(ks).use { fis -> keyStore.load(fis, null) }
|
||||||
val alias = keyStore.aliases().nextElement()
|
val alias = keyStore.aliases().nextElement()
|
||||||
|
|
||||||
val config = ApkSigner.SignerConfig.Builder(
|
val config = ApkSigner.SignerConfig.Builder(
|
||||||
cn,
|
signingOptions.cn,
|
||||||
keyStore.getKey(alias, passwordCharArray) as PrivateKey,
|
keyStore.getKey(alias, passwordCharArray) as PrivateKey,
|
||||||
listOf(keyStore.getCertificate(alias) as X509Certificate)
|
listOf(keyStore.getCertificate(alias) as X509Certificate)
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
val signer = ApkSigner.Builder(listOf(config))
|
val signer = ApkSigner.Builder(listOf(config))
|
||||||
signer.setCreatedBy(cn)
|
signer.setCreatedBy(signingOptions.cn)
|
||||||
signer.setInputApk(input)
|
signer.setInputApk(input)
|
||||||
signer.setOutputApk(output)
|
signer.setOutputApk(output)
|
||||||
|
|
||||||
signer.build().sign()
|
signer.build().sign()
|
||||||
|
|
||||||
return ks
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user