Skip to content

Commit

Permalink
perf: --rip-lib and --unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
E85Addict committed Mar 10, 2024
1 parent 26e580b commit 54201c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ internal object PatchCommand : Runnable {

private var aaptBinaryPath: File? = null

@CommandLine.Option(
names = ["--unsigned"],
description = ["Disable signing of the final apk."],
)
private var unsigned: Boolean = false

@CommandLine.Option(
names = ["--rip-lib"],
description = ["Rip native libs from APK (x86_64 etc.)"],
)
private var ripLibs = arrayOf<String>()

@CommandLine.Option(
names = ["-p", "--purge"],
description = ["Purge the temporary resource cache directory after patching."],
Expand Down Expand Up @@ -318,9 +330,9 @@ internal object PatchCommand : Runnable {

apk.copyTo(outputFilePath, overwrite = true)

patcherResult.applyTo(outputFilePath)
patcherResult.applyTo(outputFilePath, ripLibs)

if (!mount) {
if (!mount && !unsigned) {
outputFilePath.sign(
ApkUtils.SigningOptions(
keystoreFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ object ApkUtils {
* 6. Realign the APK.
*
* @param apkFile The file to apply the patched files to.
* @param ripLibs The string of libraries to remove.
*/
fun PatcherResult.applyTo(apkFile: File) {
fun PatcherResult.applyTo(apkFile: File, ripLibs: Array<String> ) {
ZFile.openReadWrite(apkFile, zFileOptions).use { targetApkZFile ->
dexFiles.forEach { dexFile ->
targetApkZFile.add(dexFile.name, dexFile.stream)
Expand Down Expand Up @@ -88,6 +89,11 @@ object ApkUtils {

targetApkZFile.realign()

// Delete all the libraries from the --rip-lib command.
targetApkZFile.entries().filter { entry ->
ripLibs.any { entry.centralDirectoryHeader.name.startsWith("lib/$it") }
}.forEach(StoredEntry::delete)

logger.fine("Writing changes")
}
}
Expand Down

0 comments on commit 54201c6

Please sign in to comment.