Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
refactor: Move alignment code to ZipFile
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 20, 2023
1 parent a022feb commit ac5742d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions revanced-lib/api/revanced-lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ public final class app/revanced/lib/signing/SigningOptions {
public fun toString ()Ljava/lang/String;
}

public final class app/revanced/lib/zip/ZipAligner {
public static final field INSTANCE Lapp/revanced/lib/zip/ZipAligner;
public final fun getApkZipEntryAlignment ()Lkotlin/jvm/functions/Function1;
}

public final class app/revanced/lib/zip/ZipFile : java/io/Closeable {
public static final field ApkZipFile Lapp/revanced/lib/zip/ZipFile$ApkZipFile;
public fun <init> (Ljava/io/File;)V
public final fun addEntryCompressData (Lapp/revanced/lib/zip/structures/ZipEntry;[B)V
public fun close ()V
public final fun copyEntriesFromFileAligned (Lapp/revanced/lib/zip/ZipFile;Lkotlin/jvm/functions/Function1;)V
}

public final class app/revanced/lib/zip/ZipFile$ApkZipFile {
public final fun getApkZipEntryAlignment ()Lkotlin/jvm/functions/Function1;
}

public final class app/revanced/lib/zip/structures/ZipEntry {
public static final field Companion Lapp/revanced/lib/zip/structures/ZipEntry$Companion;
public fun <init> (Ljava/lang/String;)V
Expand Down
5 changes: 2 additions & 3 deletions revanced-lib/src/main/kotlin/app/revanced/lib/ApkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.revanced.lib

import app.revanced.lib.signing.ApkSigner
import app.revanced.lib.signing.SigningOptions
import app.revanced.lib.zip.ZipAligner
import app.revanced.lib.zip.ZipFile
import app.revanced.lib.zip.structures.ZipEntry
import app.revanced.patcher.PatcherResult
Expand Down Expand Up @@ -35,15 +34,15 @@ object ApkUtils {

patchedEntriesSource.resourceFile?.let {
file.copyEntriesFromFileAligned(
ZipFile(it), ZipAligner.apkZipEntryAlignment
ZipFile(it), ZipFile.apkZipEntryAlignment
)
}

// TODO: Do not compress result.doNotCompress

// TODO: Fix copying resources that are not needed anymore.
file.copyEntriesFromFileAligned(
ZipFile(apkFile), ZipAligner.apkZipEntryAlignment
ZipFile(apkFile), ZipFile.apkZipEntryAlignment
)
}
}
Expand Down
14 changes: 0 additions & 14 deletions revanced-lib/src/main/kotlin/app/revanced/lib/zip/ZipAligner.kt

This file was deleted.

11 changes: 11 additions & 0 deletions revanced-lib/src/main/kotlin/app/revanced/lib/zip/ZipFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,15 @@ class ZipFile(file: File) : Closeable {
if (centralDirectoryNeedsRewrite) writeCD()
filePointer.close()
}

companion object ApkZipFile {
private const val DEFAULT_ALIGNMENT = 4
private const val LIBRARY_ALIGNMENT = 4096

val apkZipEntryAlignment = { entry: ZipEntry ->
if (entry.compression.toUInt() != 0u) null
else if (entry.fileName.endsWith(".so")) LIBRARY_ALIGNMENT
else DEFAULT_ALIGNMENT
}
}
}

0 comments on commit ac5742d

Please sign in to comment.