iBotPeaches / Apktool

A tool for reverse engineering Android apk files

Home Page:https://apktool.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Add all classes*.dex to doNotCompress

ProgerXP opened this issue · comments

Information

  1. Apktool Version (apktool -version) - 2.9.3, also tried on v2.9.2-27-5422bd70-SNAPSHOT
  2. Operating System (Mac, Linux, Windows) - Linux
  3. APK From? (Playstore, ROM, Other) - apktool.org
  4. Java Version (java --version) - 17.0.10

Problem

When a file contains multiple classes*.dex files, apktool only lists classes.dex in doNotCompress. I believe this is an error because 1) what's the reason for storing just one DEX but deflating others? 2) modern Android recommends to not compress DEX inside APK/JAR.

For example, this is the layout of an official framework.jar from Samsung (Android 14):

# unzip -lv framework.jar
...omitted for brevity...
 9945400  Stored  9945400   0% 2008-01-01 00:00 e8df447f  classes.dex
 9116160  Stored  9116160   0% 2008-01-01 00:00 029ddd68  classes2.dex
 9763660  Stored  9763660   0% 2008-01-01 00:00 43e389e2  classes3.dex
10065096  Stored 10065096   0% 2008-01-01 00:00 151a9bb9  classes4.dex
10739856  Stored 10739856   0% 2008-01-01 00:00 a932880d  classes5.dex
 1443936  Stored  1443936   0% 2008-01-01 00:00 6a7a19ee  classes6.dex

Contents of apktool.yml after doing apktool d framework.jar:

# ...
doNotCompress:
- classes.dex

If you then do apktool b and unzip -lv the rebuilt framework.jar:

10804636  Defl:N  4111202  62% 2024-04-23 12:00 aa7a970b  classes5.dex
 9241700  Defl:N  2971142  68% 2024-04-23 12:00 d059e262  classes2.dex
10112164  Defl:N  4115787  59% 2024-04-23 12:00 7c9343c3  classes4.dex
 1453960  Defl:N   472531  68% 2024-04-23 12:00 69a0a65b  classes6.dex
 9845760  Defl:N  3628758  63% 2024-04-23 12:00 721d7c44  classes3.dex
10003752  Stored 10003752   0% 2024-04-23 12:00 3d09642b  classes.dex

Note how classes.dex says Stored while others say Defl:N.

This can be worked around by manually adding classes2.dex, etc. to doNotCompress in apktool.yml. After doing so, all classes*.dex show up as Stored.

Some apps those dex files are deflated though - I've seen it happen with secondary loaders. Either way Apktool should properly read the compression of the file from the original to persist to the re-assembly.

That must not be working with your sample snippets above.

Confirmed as bug.

➜  3578 unzip -lv framework.jar.out/dist/framework.jar | grep 'classes'
 9241700  Stored  9241700   0% 2024-04-26 06:51 f1493867  classes2.dex
10003752  Stored 10003752   0% 2024-04-26 06:51 97fc3b6b  classes.dex
 9845760  Stored  9845760   0% 2024-04-26 06:51 6a119851  classes3.dex
10804636  Stored 10804636   0% 2024-04-26 06:51 ff59ddd0  classes5.dex
10112164  Stored 10112164   0% 2024-04-26 06:51 a039bda9  classes4.dex
 1453960  Stored  1453960   0% 2024-04-26 06:51 fbcada05  classes6.dex
➜  3578 

PR linked above will close this on merge.