Skip to content

Alignment issues in patched APK #88

@kitadai31

Description

@kitadai31

I would like to report three alignment issues.

1. resources.arsc should be uncompressed and aligned across all Android versions

Currently, resources.arsc is saved uncompressed only on Android 11+.

// Align resources.arsc due to targeting API 30 for silent install
if (Build.VERSION.SDK_INT >= 30) {
container.log("Extracting resources.arsc to be aligned later")
resourcesArscBytes = ZipReader(apk)
.use { it.openEntry("resources.arsc")?.read() }
?: throw IllegalArgumentException("APK is missing resources.arsc")
}

However, this should be applied to all versions.
Android 11 now enforces resources.arsc to be stored uncompressed, but the uncompressed arsc had been recommended from earlier versions.
Reference: https://stackoverflow.com/questions/23260194/why-dont-compress-resources-arsc-in-apk-files

I suggest modifying this part of the PatchIconsStep to save the arsc here uncompressed and aligned.
Because this is a only part which writes resources.arsc.

container.log("Writing resources unaligned compressed")
it.deleteEntry("resources.arsc")
// This doesn't need to be aligned and uncompressed here, since that is done during AlignmentStep
it.writeEntry("resources.arsc", arsc.toByteArray())

- it.writeEntry("resources.arsc", arsc.toByteArray())
+ zip.writeEntry("resources.arsc", arsc.toByteArray(), ZipCompression.NONE, 4)

I confirmed this is fine by building aliucord manager myself.

2. Custom app icon is not uncompressed and aligned

This is a png resource, so it must be stored uncompressed aligned

it.writeEntry("res/ic_foreground_replacement.png", options.iconReplacement.imageBytes)

3. dex aligning part is not efficient

This is not an important issue, but currently, the Manager stores the dex once as unaligned in ReorganizeDexStep, then deletes all the dex and writes it again in the AlignmentStep, this time aligned.
I think this is not efficient and you can write all dex uncompressed and aligned at ReorganizeDexStep.

The zip.deleteEntry() and zip.deleteEntries() functions are slow and these take up most of the time in AlignmentStep.
Reducing the number of the use of deleteEntry can potentially improve speed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions