Skip to content

Commit

Permalink
fix: Do not sign if mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 19, 2023
1 parent 1319ab7 commit 578e16b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,17 @@ internal object PatchCommand : Runnable {

// region Save

ApkUtils.alignAndSign(
apk,
val aligned = resourceCachePath.resolve(apk.name)
ApkUtils.align(apk, aligned, patcherResult)
if (!mount) ApkUtils.sign(
aligned,
outputFilePath,
SigningOptions(
commonName,
password,
keystoreFilePath ?: outputFilePath.parentFile
keystoreFilePath ?: outputFilePath.absoluteFile.parentFile
.resolve("${outputFilePath.nameWithoutExtension}.keystore"),
),
patcherResult
)
)

// endregion
Expand Down
3 changes: 2 additions & 1 deletion revanced-lib/api/revanced-lib.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
public final class app/revanced/lib/ApkUtils {
public static final field INSTANCE Lapp/revanced/lib/ApkUtils;
public final fun alignAndSign (Ljava/io/File;Ljava/io/File;Lapp/revanced/lib/signing/SigningOptions;Lapp/revanced/patcher/PatcherResult;)V
public final fun align (Ljava/io/File;Ljava/io/File;Lapp/revanced/patcher/PatcherResult;)V
public final fun sign (Ljava/io/File;Ljava/io/File;Lapp/revanced/lib/signing/SigningOptions;)V
}

public final class app/revanced/lib/Options {
Expand Down
25 changes: 3 additions & 22 deletions revanced-lib/src/main/kotlin/app/revanced/lib/ApkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,18 @@ import app.revanced.patcher.PatcherResult
import java.io.File
import java.util.logging.Logger

@Suppress("MemberVisibilityCanBePrivate", "unused")
object ApkUtils {
private val logger = Logger.getLogger(ApkUtils::class.java.name)

/**
* Aligns and signs the apk at [apkFile] and writes it to [outputFile].
*
* @param apkFile The apk to align and sign.
* @param outputFile The apk to write the aligned and signed apk to.
* @param signingOptions The options to use for signing.
* @param patchedEntriesSource The result of the patcher to add the patched dex files and resources.
*/
fun alignAndSign(
apkFile: File,
outputFile: File,
signingOptions: SigningOptions,
patchedEntriesSource: PatcherResult
) {
if (outputFile.exists()) outputFile.delete()

align(apkFile, outputFile, patchedEntriesSource)
sign(outputFile, outputFile, signingOptions)
}

/**
* Creates a new apk from [apkFile] and [patchedEntriesSource] and writes it to [outputFile].
*
* @param apkFile The apk to copy entries from.
* @param outputFile The apk to write the new entries to.
* @param patchedEntriesSource The result of the patcher to add the patched dex files and resources.
*/
private fun align(apkFile: File, outputFile: File, patchedEntriesSource: PatcherResult) {
fun align(apkFile: File, outputFile: File, patchedEntriesSource: PatcherResult) {
logger.info("Aligning ${apkFile.name}")

ZipFile(outputFile).use { file ->
Expand Down Expand Up @@ -72,7 +53,7 @@ object ApkUtils {
* @param output The apk to write the signed apk to.
* @param signingOptions The options to use for signing.
*/
private fun sign(
fun sign(
apk: File,
output: File,
signingOptions: SigningOptions,
Expand Down

0 comments on commit 578e16b

Please sign in to comment.