refactor: Move alignment code to ZipFile

This commit is contained in:
oSumAtrIX
2023-09-20 04:48:02 +02:00
parent a022febd0c
commit ac5742dd6c
4 changed files with 18 additions and 22 deletions

View File

@@ -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
@@ -35,7 +34,7 @@ object ApkUtils {
patchedEntriesSource.resourceFile?.let {
file.copyEntriesFromFileAligned(
ZipFile(it), ZipAligner.apkZipEntryAlignment
ZipFile(it), ZipFile.apkZipEntryAlignment
)
}
@@ -43,7 +42,7 @@ object ApkUtils {
// TODO: Fix copying resources that are not needed anymore.
file.copyEntriesFromFileAligned(
ZipFile(apkFile), ZipAligner.apkZipEntryAlignment
ZipFile(apkFile), ZipFile.apkZipEntryAlignment
)
}
}

View File

@@ -1,14 +0,0 @@
package app.revanced.lib.zip
import app.revanced.lib.zip.structures.ZipEntry
object ZipAligner {
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
}
}

View File

@@ -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
}
}
}