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

Commit

Permalink
feat: rip-lib and unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and Blawuken committed Dec 28, 2023
1 parent 2d48607 commit daece06
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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."],
)
private var ripLibs = arrayOf<String>()

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

val alignedFile =
resourceCachePath.resolve(apk.name).apply {
ApkUtils.copyAligned(apk, this, patcherResult)
ApkUtils.copyAligned(apk, this, patcherResult, ripLibs)
}

if (!mount) {
if (!mount && !unsigned) {
ApkUtils.sign(
alignedFile,
outputFilePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ object ApkUtils {
* @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.
* @param exclude An array of libraries to remove.
*/
fun copyAligned(
apkFile: File,
outputFile: File,
patchedEntriesSource: PatcherResult,
exclude: Array<String>
) {
logger.info("Aligning ${apkFile.name}")

Expand All @@ -49,8 +51,10 @@ object ApkUtils {
// TODO: Do not compress result.doNotCompress

// TODO: Fix copying resources that are not needed anymore.
val inputZipFile = ZipFile(apkFile)
inputZipFile.entries.removeIf { entry -> exclude.any { entry.fileName.startsWith("lib/$it") } }
file.copyEntriesFromFileAligned(
ZipFile(apkFile),
inputZipFile,
ZipFile.apkZipEntryAlignment,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import java.util.zip.CRC32
import java.util.zip.Deflater

class ZipFile(file: File) : Closeable {
private var entries: MutableList<ZipEntry> = mutableListOf()
var entries: MutableList<ZipEntry> = mutableListOf()

// Open file for writing if it doesn't exist (because the intention is to write) or is writable.
private val filePointer: RandomAccessFile =
Expand Down

0 comments on commit daece06

Please sign in to comment.