mirror of
https://github.com/ReVanced/revanced-library.git
synced 2026-01-18 00:43:56 +00:00
Compare commits
18 Commits
v2.1.0-dev
...
v2.2.2-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2959b610a | ||
|
|
2a30845f61 | ||
|
|
1b4d87e563 | ||
|
|
7f7dfdd5b5 | ||
|
|
56773fa3d3 | ||
|
|
249372c31f | ||
|
|
e7bed8565e | ||
|
|
4a24e2e92d | ||
|
|
fca8a3f4c0 | ||
|
|
f59ecbccd1 | ||
|
|
c92be32607 | ||
|
|
51109c4768 | ||
|
|
f2bd3f5eee | ||
|
|
cc5ee29d14 | ||
|
|
c4bad9a653 | ||
|
|
3f713cf76b | ||
|
|
dfe48a24bf | ||
|
|
132ad13670 |
2
.github/workflows/update_documentation.yml
vendored
2
.github/workflows/update_documentation.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
name: Dispatch event to documentation repository
|
name: Dispatch event to documentation repository
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main'
|
||||||
steps:
|
steps:
|
||||||
- uses: peter-evans/repository-dispatch@v2
|
- uses: peter-evans/repository-dispatch@v3
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.DOCUMENTATION_REPO_ACCESS_TOKEN }}
|
token: ${{ secrets.DOCUMENTATION_REPO_ACCESS_TOKEN }}
|
||||||
repository: revanced/revanced-documentation
|
repository: revanced/revanced-documentation
|
||||||
|
|||||||
59
CHANGELOG.md
59
CHANGELOG.md
@@ -1,3 +1,62 @@
|
|||||||
|
## [2.2.2-dev.1](https://github.com/ReVanced/revanced-library/compare/v2.2.1...v2.2.2-dev.1) (2024-03-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Support mounting even when Magisk is not installed ([2a30845](https://github.com/ReVanced/revanced-library/commit/2a30845f61d5f77ded7a72ee3d6ab55b4c512d52))
|
||||||
|
|
||||||
|
## [2.2.1](https://github.com/ReVanced/revanced-library/compare/v2.2.0...v2.2.1) (2024-03-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Do not specify a provider to automatically select an available one ([249372c](https://github.com/ReVanced/revanced-library/commit/249372c31f7e7975fc9eacb5361bd07dbc5dfb92))
|
||||||
|
|
||||||
|
## [2.2.1-dev.1](https://github.com/ReVanced/revanced-library/compare/v2.2.0...v2.2.1-dev.1) (2024-03-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Do not specify a provider to automatically select an available one ([249372c](https://github.com/ReVanced/revanced-library/commit/249372c31f7e7975fc9eacb5361bd07dbc5dfb92))
|
||||||
|
|
||||||
|
# [2.2.0](https://github.com/ReVanced/revanced-library/compare/v2.1.0...v2.2.0) (2024-03-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Make property private ([51109c4](https://github.com/ReVanced/revanced-library/commit/51109c476837828535dcd395a5222d2fcf7fc22c))
|
||||||
|
* Sign APKs using `apksig` ([f59ecbc](https://github.com/ReVanced/revanced-library/commit/f59ecbccd14a08d87d4f18c3c0cc47a884088b99))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Increase default expiration date of certificate ([f2bd3f5](https://github.com/ReVanced/revanced-library/commit/f2bd3f5eeee14ca32094be0d41c32b231a16bcc3))
|
||||||
|
|
||||||
|
# [2.2.0-dev.1](https://github.com/ReVanced/revanced-library/compare/v2.1.0...v2.2.0-dev.1) (2024-03-09)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Make property private ([51109c4](https://github.com/ReVanced/revanced-library/commit/51109c476837828535dcd395a5222d2fcf7fc22c))
|
||||||
|
* Sign APKs using `apksig` ([f59ecbc](https://github.com/ReVanced/revanced-library/commit/f59ecbccd14a08d87d4f18c3c0cc47a884088b99))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Increase default expiration date of certificate ([f2bd3f5](https://github.com/ReVanced/revanced-library/commit/f2bd3f5eeee14ca32094be0d41c32b231a16bcc3))
|
||||||
|
|
||||||
|
# [2.1.0](https://github.com/ReVanced/revanced-library/compare/v2.0.0...v2.1.0) (2024-03-04)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* Use `BKS` instead of default signing provider to fix backwards compatibility ([41805fc](https://github.com/ReVanced/revanced-library/commit/41805fcb0bdc778fe0870427a0a1caa6d4369cee))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Mention APK file name when logging aligning ([244ebc2](https://github.com/ReVanced/revanced-library/commit/244ebc21868c07d1852857f6858c1a53a5561155))
|
||||||
|
|
||||||
# [2.1.0-dev.2](https://github.com/ReVanced/revanced-library/compare/v2.1.0-dev.1...v2.1.0-dev.2) (2024-03-04)
|
# [2.1.0-dev.2](https://github.com/ReVanced/revanced-library/compare/v2.1.0-dev.1...v2.1.0-dev.2) (2024-03-04)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
public final class app/revanced/library/ApkSigner {
|
public final class app/revanced/library/ApkSigner {
|
||||||
public static final field INSTANCE Lapp/revanced/library/ApkSigner;
|
public static final field INSTANCE Lapp/revanced/library/ApkSigner;
|
||||||
public final fun newApkSigner (Lapp/revanced/library/ApkSigner$PrivateKeyCertificatePair;)Lapp/revanced/library/ApkSigner$Signer;
|
public final fun newApkSigner (Lapp/revanced/library/ApkSigner$PrivateKeyCertificatePair;)Lapp/revanced/library/ApkSigner$Signer;
|
||||||
|
public final fun newApkSigner (Ljava/lang/String;Lapp/revanced/library/ApkSigner$PrivateKeyCertificatePair;)Lapp/revanced/library/ApkSigner$Signer;
|
||||||
|
public final fun newApkSigner (Ljava/lang/String;Ljava/security/KeyStore;Ljava/lang/String;Ljava/lang/String;)Lapp/revanced/library/ApkSigner$Signer;
|
||||||
public final fun newApkSigner (Ljava/security/KeyStore;Ljava/lang/String;Ljava/lang/String;)Lapp/revanced/library/ApkSigner$Signer;
|
public final fun newApkSigner (Ljava/security/KeyStore;Ljava/lang/String;Ljava/lang/String;)Lapp/revanced/library/ApkSigner$Signer;
|
||||||
public final fun newKeyStore (Ljava/io/OutputStream;Ljava/lang/String;Ljava/util/Set;)V
|
public final fun newKeyStore (Ljava/io/OutputStream;Ljava/lang/String;Ljava/util/Set;)V
|
||||||
public final fun newKeyStore (Ljava/util/Set;)Ljava/security/KeyStore;
|
public final fun newKeyStore (Ljava/util/Set;)Ljava/security/KeyStore;
|
||||||
@@ -25,15 +27,16 @@ public final class app/revanced/library/ApkSigner$PrivateKeyCertificatePair {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class app/revanced/library/ApkSigner$Signer {
|
public final class app/revanced/library/ApkSigner$Signer {
|
||||||
public final fun getSigningExtension ()Lcom/android/tools/build/apkzlib/sign/SigningExtension;
|
|
||||||
public final fun signApk (Lcom/android/tools/build/apkzlib/zip/ZFile;)V
|
public final fun signApk (Lcom/android/tools/build/apkzlib/zip/ZFile;)V
|
||||||
public final fun signApk (Ljava/io/File;)V
|
public final fun signApk (Ljava/io/File;)V
|
||||||
|
public final fun signApk (Ljava/io/File;Ljava/io/File;)V
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class app/revanced/library/ApkUtils {
|
public final class app/revanced/library/ApkUtils {
|
||||||
public static final field INSTANCE Lapp/revanced/library/ApkUtils;
|
public static final field INSTANCE Lapp/revanced/library/ApkUtils;
|
||||||
public final fun applyTo (Lapp/revanced/patcher/PatcherResult;Ljava/io/File;)V
|
public final fun applyTo (Lapp/revanced/patcher/PatcherResult;Ljava/io/File;)V
|
||||||
public final fun sign (Ljava/io/File;Lapp/revanced/library/ApkUtils$SigningOptions;)V
|
public final fun sign (Ljava/io/File;Lapp/revanced/library/ApkUtils$SigningOptions;)V
|
||||||
|
public final fun sign (Ljava/io/File;Ljava/io/File;Lapp/revanced/library/ApkUtils$SigningOptions;)V
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class app/revanced/library/ApkUtils$SigningOptions {
|
public final class app/revanced/library/ApkUtils$SigningOptions {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.kotlin)
|
alias(libs.plugins.kotlin)
|
||||||
alias(libs.plugins.binary.compatibility.validator)
|
alias(libs.plugins.binary.compatibility.validator)
|
||||||
@@ -27,6 +29,7 @@ dependencies {
|
|||||||
implementation(libs.jadb) // Fork with Shell v2 support.
|
implementation(libs.jadb) // Fork with Shell v2 support.
|
||||||
implementation(libs.jackson.module.kotlin)
|
implementation(libs.jackson.module.kotlin)
|
||||||
implementation(libs.apkzlib)
|
implementation(libs.apkzlib)
|
||||||
|
implementation(libs.apksig)
|
||||||
implementation(libs.bcpkix.jdk15on)
|
implementation(libs.bcpkix.jdk15on)
|
||||||
implementation(libs.guava)
|
implementation(libs.guava)
|
||||||
|
|
||||||
@@ -43,10 +46,14 @@ tasks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin { jvmToolchain(11) }
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget.set(JvmTarget.JVM_11)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
withSourcesJar()
|
targetCompatibility = JavaVersion.VERSION_11
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
org.gradle.parallel = true
|
org.gradle.parallel = true
|
||||||
org.gradle.caching = true
|
org.gradle.caching = true
|
||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 2.1.0-dev.2
|
version = 2.2.2-dev.1
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ jadb = "1.2.1"
|
|||||||
kotlin = "1.9.22"
|
kotlin = "1.9.22"
|
||||||
revanced-patcher = "19.3.1"
|
revanced-patcher = "19.3.1"
|
||||||
binary-compatibility-validator = "0.14.0"
|
binary-compatibility-validator = "0.14.0"
|
||||||
apkzlib = "8.2.2"
|
apkzlib = "8.3.0"
|
||||||
bcpkix-jdk15on = "1.70"
|
bcpkix-jdk15on = "1.70"
|
||||||
guava = "33.0.0-jre"
|
guava = "33.0.0-jre"
|
||||||
|
apksig = "8.3.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" }
|
jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson-module-kotlin" }
|
||||||
@@ -17,6 +18,7 @@ revanced-patcher = { module = "app.revanced:revanced-patcher", version.ref = "re
|
|||||||
apkzlib = { module = "com.android.tools.build:apkzlib", version.ref = "apkzlib" }
|
apkzlib = { module = "com.android.tools.build:apkzlib", version.ref = "apkzlib" }
|
||||||
bcpkix-jdk15on = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bcpkix-jdk15on" }
|
bcpkix-jdk15on = { module = "org.bouncycastle:bcpkix-jdk15on", version.ref = "bcpkix-jdk15on" }
|
||||||
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
guava = { module = "com.google.guava:guava", version.ref = "guava" }
|
||||||
|
apksig = { module = "com.android.tools.build:apksig", version.ref = "apksig" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
|
binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binary-compatibility-validator" }
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package app.revanced.library
|
package app.revanced.library
|
||||||
|
|
||||||
|
import com.android.apksig.ApkSigner.SignerConfig
|
||||||
import com.android.tools.build.apkzlib.sign.SigningExtension
|
import com.android.tools.build.apkzlib.sign.SigningExtension
|
||||||
import com.android.tools.build.apkzlib.sign.SigningOptions
|
import com.android.tools.build.apkzlib.sign.SigningOptions
|
||||||
import com.android.tools.build.apkzlib.zip.ZFile
|
import com.android.tools.build.apkzlib.zip.ZFile
|
||||||
@@ -43,35 +44,28 @@ object ApkSigner {
|
|||||||
*/
|
*/
|
||||||
fun newPrivateKeyCertificatePair(
|
fun newPrivateKeyCertificatePair(
|
||||||
commonName: String = "ReVanced",
|
commonName: String = "ReVanced",
|
||||||
validUntil: Date = Date(System.currentTimeMillis() + 356.days.inWholeMilliseconds * 24),
|
validUntil: Date = Date(System.currentTimeMillis() + (365.days * 8).inWholeMilliseconds * 24),
|
||||||
): PrivateKeyCertificatePair {
|
): PrivateKeyCertificatePair {
|
||||||
logger.fine("Creating certificate for $commonName")
|
logger.fine("Creating certificate for $commonName")
|
||||||
|
|
||||||
// Generate a new key pair.
|
// Generate a new key pair.
|
||||||
val keyPair =
|
val keyPair = KeyPairGenerator.getInstance("RSA").apply {
|
||||||
KeyPairGenerator.getInstance("RSA").apply {
|
initialize(4096)
|
||||||
initialize(4096)
|
}.generateKeyPair()
|
||||||
}.generateKeyPair()
|
|
||||||
|
|
||||||
var serialNumber: BigInteger
|
val contentSigner = JcaContentSignerBuilder("SHA256withRSA").build(keyPair.private)
|
||||||
do serialNumber = BigInteger.valueOf(SecureRandom().nextLong())
|
|
||||||
while (serialNumber < BigInteger.ZERO)
|
|
||||||
|
|
||||||
val name = X500Name("CN=$commonName")
|
val name = X500Name("CN=$commonName")
|
||||||
|
val certificateHolder = X509v3CertificateBuilder(
|
||||||
// Create a new certificate.
|
name,
|
||||||
val certificate =
|
BigInteger.valueOf(SecureRandom().nextLong()),
|
||||||
JcaX509CertificateConverter().getCertificate(
|
Date(System.currentTimeMillis()),
|
||||||
X509v3CertificateBuilder(
|
validUntil,
|
||||||
name,
|
Locale.ENGLISH,
|
||||||
serialNumber,
|
name,
|
||||||
Date(System.currentTimeMillis()),
|
SubjectPublicKeyInfo.getInstance(keyPair.public.encoded),
|
||||||
validUntil,
|
).build(contentSigner)
|
||||||
Locale.ENGLISH,
|
val certificate = JcaX509CertificateConverter().getCertificate(certificateHolder)
|
||||||
name,
|
|
||||||
SubjectPublicKeyInfo.getInstance(keyPair.public.encoded),
|
|
||||||
).build(JcaContentSignerBuilder("SHA256withRSA").build(keyPair.private)),
|
|
||||||
)
|
|
||||||
|
|
||||||
return PrivateKeyCertificatePair(keyPair.private, certificate)
|
return PrivateKeyCertificatePair(keyPair.private, certificate)
|
||||||
}
|
}
|
||||||
@@ -189,6 +183,7 @@ object ApkSigner {
|
|||||||
/**
|
/**
|
||||||
* Create a new [Signer].
|
* Create a new [Signer].
|
||||||
*
|
*
|
||||||
|
* @param signer The name of the signer.
|
||||||
* @param privateKeyCertificatePair The private key and certificate pair to use for signing.
|
* @param privateKeyCertificatePair The private key and certificate pair to use for signing.
|
||||||
*
|
*
|
||||||
* @return The new [Signer].
|
* @return The new [Signer].
|
||||||
@@ -196,6 +191,38 @@ object ApkSigner {
|
|||||||
* @see PrivateKeyCertificatePair
|
* @see PrivateKeyCertificatePair
|
||||||
* @see Signer
|
* @see Signer
|
||||||
*/
|
*/
|
||||||
|
fun newApkSigner(
|
||||||
|
signer: String,
|
||||||
|
privateKeyCertificatePair: PrivateKeyCertificatePair,
|
||||||
|
) = Signer(
|
||||||
|
com.android.apksig.ApkSigner.Builder(
|
||||||
|
listOf(
|
||||||
|
SignerConfig.Builder(
|
||||||
|
signer,
|
||||||
|
privateKeyCertificatePair.privateKey,
|
||||||
|
listOf(privateKeyCertificatePair.certificate),
|
||||||
|
).build(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new [Signer].
|
||||||
|
*
|
||||||
|
* @param privateKeyCertificatePair The private key and certificate pair to use for signing.
|
||||||
|
*
|
||||||
|
* @return The new [Signer].
|
||||||
|
*
|
||||||
|
* @see PrivateKeyCertificatePair
|
||||||
|
* @see Signer
|
||||||
|
*/
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed in the future.",
|
||||||
|
ReplaceWith(
|
||||||
|
"newApkSigner(\"ReVanced\", privateKeyCertificatePair)",
|
||||||
|
),
|
||||||
|
)
|
||||||
fun newApkSigner(privateKeyCertificatePair: PrivateKeyCertificatePair) =
|
fun newApkSigner(privateKeyCertificatePair: PrivateKeyCertificatePair) =
|
||||||
Signer(
|
Signer(
|
||||||
SigningExtension(
|
SigningExtension(
|
||||||
@@ -212,6 +239,7 @@ object ApkSigner {
|
|||||||
/**
|
/**
|
||||||
* Create a new [Signer].
|
* Create a new [Signer].
|
||||||
*
|
*
|
||||||
|
* @param signer The name of the signer.
|
||||||
* @param keyStore The keystore to use for signing.
|
* @param keyStore The keystore to use for signing.
|
||||||
* @param keyStoreEntryAlias The alias of the key store entry to use for signing.
|
* @param keyStoreEntryAlias The alias of the key store entry to use for signing.
|
||||||
* @param keyStoreEntryPassword The password for recovering the signing key.
|
* @param keyStoreEntryPassword The password for recovering the signing key.
|
||||||
@@ -222,10 +250,36 @@ object ApkSigner {
|
|||||||
* @see Signer
|
* @see Signer
|
||||||
*/
|
*/
|
||||||
fun newApkSigner(
|
fun newApkSigner(
|
||||||
|
signer: String,
|
||||||
keyStore: KeyStore,
|
keyStore: KeyStore,
|
||||||
keyStoreEntryAlias: String,
|
keyStoreEntryAlias: String,
|
||||||
keyStoreEntryPassword: String,
|
keyStoreEntryPassword: String,
|
||||||
) = newApkSigner(readKeyCertificatePair(keyStore, keyStoreEntryAlias, keyStoreEntryPassword))
|
) = newApkSigner(signer, readKeyCertificatePair(keyStore, keyStoreEntryAlias, keyStoreEntryPassword))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new [Signer].
|
||||||
|
*
|
||||||
|
* @param keyStore The keystore to use for signing.
|
||||||
|
* @param keyStoreEntryAlias The alias of the key store entry to use for signing.
|
||||||
|
* @param keyStoreEntryPassword The password for recovering the signing key.
|
||||||
|
*
|
||||||
|
* @return The new [Signer].
|
||||||
|
*
|
||||||
|
* @see KeyStore
|
||||||
|
* @see Signer
|
||||||
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"This method will be removed in the future.",
|
||||||
|
ReplaceWith(
|
||||||
|
"newApkSigner(\"ReVanced\", readKeyCertificatePair(keyStore, keyStoreEntryAlias, keyStoreEntryPassword))",
|
||||||
|
"app.revanced.library.ApkSigner.newApkSigner",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
fun newApkSigner(
|
||||||
|
keyStore: KeyStore,
|
||||||
|
keyStoreEntryAlias: String,
|
||||||
|
keyStoreEntryPassword: String,
|
||||||
|
) = newApkSigner("ReVanced", readKeyCertificatePair(keyStore, keyStoreEntryAlias, keyStoreEntryPassword))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entry in a keystore.
|
* An entry in a keystore.
|
||||||
@@ -253,23 +307,48 @@ object ApkSigner {
|
|||||||
val certificate: X509Certificate,
|
val certificate: X509Certificate,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Signer internal constructor(val signingExtension: SigningExtension) {
|
class Signer {
|
||||||
|
private val signerBuilder: com.android.apksig.ApkSigner.Builder?
|
||||||
|
private val signingExtension: SigningExtension?
|
||||||
|
|
||||||
|
internal constructor(signerBuilder: com.android.apksig.ApkSigner.Builder) {
|
||||||
|
this.signerBuilder = signerBuilder
|
||||||
|
signingExtension = null
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("This constructor will be removed in the future.")
|
||||||
|
internal constructor(signingExtension: SigningExtension) {
|
||||||
|
signerBuilder = null
|
||||||
|
this.signingExtension = signingExtension
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign an APK file.
|
* Sign an APK file.
|
||||||
*
|
*
|
||||||
* @param apkFile The APK file to sign.
|
* @param apkFile The APK file to sign.
|
||||||
*/
|
*/
|
||||||
fun signApk(apkFile: File) = ZFile.openReadWrite(apkFile).use { signApk(it) }
|
@Deprecated("This method will be removed in the future.")
|
||||||
|
fun signApk(apkFile: File) = ZFile.openReadWrite(apkFile).use {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
signApk(it)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign an APK file.
|
* Sign an APK file.
|
||||||
*
|
*
|
||||||
* @param apkZFile The APK [ZFile] to sign.
|
* @param apkZFile The APK [ZFile] to sign.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("This method will be removed in the future.")
|
||||||
fun signApk(apkZFile: ZFile) {
|
fun signApk(apkZFile: ZFile) {
|
||||||
logger.info("Signing ${apkZFile.file.name}")
|
logger.info("Signing ${apkZFile.file.name}")
|
||||||
|
|
||||||
signingExtension.register(apkZFile)
|
signingExtension?.register(apkZFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun signApk(inputApkFile: File, outputApkFile: File) {
|
||||||
|
logger.info("Signing APK")
|
||||||
|
|
||||||
|
signerBuilder?.setInputApk(inputApkFile)?.setOutputApk(outputApkFile)?.build()?.sign()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ object ApkUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Aligning ${apkFile.name}")
|
logger.info("Aligning APK")
|
||||||
|
|
||||||
targetApkZFile.realign()
|
targetApkZFile.realign()
|
||||||
|
|
||||||
@@ -92,28 +92,38 @@ object ApkUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an existing or creates a new keystore.
|
||||||
|
*
|
||||||
|
* @param signingOptions The options to use for signing.
|
||||||
|
*/
|
||||||
|
private fun readOrNewKeyStore(signingOptions: SigningOptions) = if (signingOptions.keyStore.exists()) {
|
||||||
|
ApkSigner.readKeyStore(
|
||||||
|
signingOptions.keyStore.inputStream(),
|
||||||
|
signingOptions.keyStorePassword ?: "",
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val entry = ApkSigner.KeyStoreEntry(signingOptions.alias, signingOptions.password)
|
||||||
|
|
||||||
|
// Create a new keystore with a new keypair and saves it.
|
||||||
|
ApkSigner.newKeyStore(setOf(entry)).apply {
|
||||||
|
store(
|
||||||
|
signingOptions.keyStore.outputStream(),
|
||||||
|
signingOptions.keyStorePassword?.toCharArray(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs the apk file with the given options.
|
* Signs the apk file with the given options.
|
||||||
*
|
*
|
||||||
* @param signingOptions The options to use for signing.
|
* @param signingOptions The options to use for signing.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated("Use sign(File, File, SigningOptions) instead.")
|
||||||
fun File.sign(signingOptions: SigningOptions) {
|
fun File.sign(signingOptions: SigningOptions) {
|
||||||
// Get the keystore from the file or create a new one.
|
val keyStore = readOrNewKeyStore(signingOptions)
|
||||||
val keyStore =
|
|
||||||
if (signingOptions.keyStore.exists()) {
|
|
||||||
ApkSigner.readKeyStore(signingOptions.keyStore.inputStream(), signingOptions.keyStorePassword ?: "")
|
|
||||||
} else {
|
|
||||||
val entries = setOf(ApkSigner.KeyStoreEntry(signingOptions.alias, signingOptions.password))
|
|
||||||
|
|
||||||
// Create a new keystore with a new keypair and saves it.
|
|
||||||
ApkSigner.newKeyStore(entries).apply {
|
|
||||||
store(
|
|
||||||
signingOptions.keyStore.outputStream(),
|
|
||||||
signingOptions.keyStorePassword?.toCharArray(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
ApkSigner.newApkSigner(
|
ApkSigner.newApkSigner(
|
||||||
keyStore,
|
keyStore,
|
||||||
signingOptions.alias,
|
signingOptions.alias,
|
||||||
@@ -121,6 +131,24 @@ object ApkUtils {
|
|||||||
).signApk(this)
|
).signApk(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signs [inputApkFile] with the given options and saves the signed apk to [outputApkFile].
|
||||||
|
*
|
||||||
|
* @param inputApkFile The apk file to sign.
|
||||||
|
* @param outputApkFile The file to save the signed apk to.
|
||||||
|
* @param signingOptions The options to use for signing.
|
||||||
|
*/
|
||||||
|
fun sign(inputApkFile: File, outputApkFile: File, signingOptions: SigningOptions) {
|
||||||
|
val keyStore = readOrNewKeyStore(signingOptions)
|
||||||
|
|
||||||
|
ApkSigner.newApkSigner(
|
||||||
|
signingOptions.signer,
|
||||||
|
keyStore,
|
||||||
|
signingOptions.alias,
|
||||||
|
signingOptions.password,
|
||||||
|
).signApk(inputApkFile, outputApkFile)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options for signing an apk.
|
* Options for signing an apk.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,13 +29,17 @@ internal object Constants {
|
|||||||
internal val MOUNT_SCRIPT =
|
internal val MOUNT_SCRIPT =
|
||||||
"""
|
"""
|
||||||
#!/system/bin/sh
|
#!/system/bin/sh
|
||||||
MAGISKTMP="$( magisk --path )" || MAGISKTMP=/sbin
|
|
||||||
MIRROR="${'$'}MAGISKTMP/.magisk/mirror"
|
# Use Magisk mirror, if possible.
|
||||||
|
if command -v magisk &> /dev/null; then
|
||||||
|
MIRROR="${'$'}(magisk --path)/.magisk/mirror"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Wait for the system to boot.
|
||||||
until [ "$( getprop sys.boot_completed )" = 1 ]; do sleep 3; done
|
until [ "$( getprop sys.boot_completed )" = 1 ]; do sleep 3; done
|
||||||
until [ -d "/sdcard/Android" ]; do sleep 1; done
|
until [ -d "/sdcard/Android" ]; do sleep 1; done
|
||||||
|
|
||||||
# Unmount any existing mount as a safety measure
|
# Unmount any existing mount as a safety measure.
|
||||||
$UMOUNT
|
$UMOUNT
|
||||||
|
|
||||||
base_path="$PATCHED_APK_PATH"
|
base_path="$PATCHED_APK_PATH"
|
||||||
@@ -44,7 +48,7 @@ internal object Constants {
|
|||||||
chcon u:object_r:apk_data_file:s0 ${'$'}base_path
|
chcon u:object_r:apk_data_file:s0 ${'$'}base_path
|
||||||
mount -o bind ${'$'}MIRROR${'$'}base_path ${'$'}stock_path
|
mount -o bind ${'$'}MIRROR${'$'}base_path ${'$'}stock_path
|
||||||
|
|
||||||
# Kill the app to force it to restart the mounted APK in case it's already running
|
# Kill the app to force it to restart the mounted APK in case it's currently running.
|
||||||
$KILL
|
$KILL
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user