Apktool icon indicating copy to clipboard operation
Apktool copied to clipboard

[BUG]java.lang.ArrayIndexOutOfBoundsException when decompile apk

Open david8557 opened this issue 10 months ago • 8 comments
trafficstars

Information

  1. Apktool Version (apktool -version) - 2.11.0
  2. Operating System (Mac, Linux, Windows) - Windows
  3. APK From? (Playstore, ROM, Other) - Apkpure
  4. Java Version (java --version) - 22.0.1

Apktool version 2.10.0 has same issue, but version 2.9.3 works fine.

Stacktrace/Logcat

I: Using Apktool 2.11.0 on test.apk with 8 threads
I: Baksmaling classes.dex...
I: Baksmaling classes2.dex...
I: Copying raw assets/.wxxaawy.dex file...
I: Baksmaling classes3.dex...
I: Baksmaling classes4.dex...
I: Loading resource table...
I: Decoding file-resources...
I: Loading resource table from file: C:\Users\sss\AppData\Local\apktool\framework\1.apk
I: Decoding values */* XMLs...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: Index 10350680 out of bounds for length 129317
        at brut.androlib.BackgroundWorker.waitForFinish(SourceFile:0)
        at brut.androlib.ApkDecoder.decode(SourceFile:0)
        at brut.apktool.Main.main(SourceFile:0)
Caused by: java.util.concurrent.ExecutionException: java.lang.ArrayIndexOutOfBoundsException: Index 10350680 out of bounds for length 129317
        at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
        at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
        ... 3 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 10350680 out of bounds for length 129317
        at com.android.tools.smali.dexlib2.dexbacked.DexBuffer.readSmallUint(SourceFile)
        at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile.getMapItemForSection(SourceFile:0)
        at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile.<init>(SourceFile)
        at com.android.tools.smali.dexlib2.dexbacked.ZipDexContainer.getEntries(SourceFile:0)
        at com.android.tools.smali.dexlib2.dexbacked.ZipDexContainer.getDexEntryNames(SourceFile)
        at brut.androlib.ApkDecoder.decodeSourcesSmaliJob(SourceFile:0)
        at brut.androlib.ApkDecoder.lambda$decodeSourcesSmali$0(SourceFile)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1570)

An error has occured.

Steps to Reproduce

  1. apktool d test.apk -o test_decompile --only-main-classes

APK

APK link: https://pixeldrain.com/u/fhzaEige

david8557 avatar Jan 15 '25 02:01 david8557

This looks like an issue at smali - mind upstreaming this to them? https://github.com/google/smali

iBotPeaches avatar Jan 15 '25 02:01 iBotPeaches

This looks like an issue at smali - mind upstreaming this to them? https://github.com/google/smali

Ok let me try, which smali version is used in apktool 2.9.3?

david8557 avatar Jan 15 '25 03:01 david8557

Ok let me try, which smali version is used in apktool 2.9.3?

3.0.3

iBotPeaches avatar Jan 15 '25 03:01 iBotPeaches

Issue reported here https://github.com/google/smali/issues/88

david8557 avatar Jan 20 '25 02:01 david8557

I have a similar problem only it doesn't show up until I decompile, recompile, then try to decompile the recompiled apk a second time. (without any editing other than adding a few attributes). This is for the Google Pixel 6a SystemGoogle.apk.

./rebuild e:/3Custom14Pixelscript rebuild is loading.... Unpacking e:/3Custom14Pixelscript/SystemUIGoogle.apk... I: Using Apktool v2.11.0-3-4b2c9abe-SNAPSHOT on SystemUIGoogle.apk with 4 threads I: Baksmaling classes.dex... I: Loading resource table... I: Baksmaling classes2.dex... I: Decoding file-resources... I: Loading resource table from file: framework-3Custom14Pixelscript\1.apk I: Decoding values / XMLs... I: Decoding AndroidManifest.xml with resources... I: Regular manifest package... I: Copying original files... I: Copying lib... I: Copying unknown files... Rebuild only... Added 5 lines to SystemUIGoogle/res/values/attrs.xml Compiling first pass... I: Using Apktool v2.11.0-3-4b2c9abe-SNAPSHOT on SystemUIGoogle.apk with 4 threads I: Smaling smali folder into classes.dex... I: Smaling smali_classes2 folder into classes2.dex... I: Building resources with aapt2... I: Copying original files... I: Building apk file... I: Importing lib... I: Importing unknown files... I: Built apk into: SystemUIGoogle\dist\SystemUIGoogle.apk Decompiling first pass... I: Using Apktool v2.11.0-3-4b2c9abe-SNAPSHOT on SystemUIGoogle.apk with 4 threads I: Baksmaling classes.dex... I: Loading resource table... I: Baksmaling classes2.dex... I: Decoding file-resources... I: Loading resource table from file: framework-3Custom14Pixelscript\1.apk I: Decoding values / XMLs... I: Decoding AndroidManifest.xml with resources... I: Regular manifest package... Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.ExecutionException: com.android.tools.smali.dexli b2.util.DexUtil$InvalidFile: Unexpected container offset in header at brut.androlib.BackgroundWorker.waitForFinish(BackgroundWorker.java:41) at brut.androlib.ApkDecoder.decode(ApkDecoder.java:87) at brut.apktool.Main.cmdDecode(Main.java:244) at brut.apktool.Main.main(Main.java:105) Caused by: java.util.concurrent.ExecutionException: com.android.tools.smali.dexlib2.util.DexUtil$InvalidFile: Unexpected cont ainer offset in header at java.util.concurrent.FutureTask.report(Unknown Source) at java.util.concurrent.FutureTask.get(Unknown Source) at brut.androlib.BackgroundWorker.waitForFinish(BackgroundWorker.java:39) ... 3 more Caused by: com.android.tools.smali.dexlib2.util.DexUtil$InvalidFile: Unexpected container offset in header at com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile.(DexBackedDexFile.java:141) at com.android.tools.smali.dexlib2.dexbacked.ZipDexContainer.getEntries(ZipDexContainer.java:104) at com.android.tools.smali.dexlib2.dexbacked.ZipDexContainer.getDexEntryNames(ZipDexContainer.java:82) at brut.androlib.src.SmaliDecoder.decode(SmaliDecoder.java:74) at brut.androlib.ApkDecoder.decodeSourcesSmaliJob(ApkDecoder.java:193) at brut.androlib.ApkDecoder.lambda$decodeSourcesSmali$0(ApkDecoder.java:168) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Tulsadiver avatar Jan 22 '25 16:01 Tulsadiver

Issue reported here google/smali#88

@iBotPeaches Can you please check this? https://github.com/google/smali/issues/88#issuecomment-2636033513 It seem not the smali issue, because I have skipped this

I: Copying raw assets/.wxxaawy.dex file...

but it have error when

I: Regular manifest package...

david8557 avatar Feb 05 '25 08:02 david8557

Ok let me try, which smali version is used in apktool 2.9.3?

3.0.3

@iBotPeaches Please check this when you have some free time.

Issue reported here google/smali#88

@iBotPeaches Can you please check this? google/smali#88 (comment) It seem not the smali issue, because I have skipped this

I: Copying raw assets/.wxxaawy.dex file...

but it have error when

I: Regular manifest package...

david8557 avatar Feb 11 '25 01:02 david8557

@iBotPeaches This issue still isn't resolved in latest commit.

david8557 avatar May 24 '25 03:05 david8557

@iBotPeaches I think I found the real problem here. I'm not sure if we need to fix this in apktool or in smali. https://github.com/google/smali/issues/88#issuecomment-3172294211

david8557 avatar Aug 10 '25 01:08 david8557