Apktool: Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file

Hamids-MBP:apk Hamid$ ./apktool d roqya.apk
I: Using Apktool 2.0.0 on roqya.apk
I: Loading resource table...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode arsc file
    at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:52)
    at brut.androlib.res.AndrolibResources.getResPackagesFromApk(AndrolibResources.java:538)
    at brut.androlib.res.AndrolibResources.loadMainPkg(AndrolibResources.java:63)
    at brut.androlib.res.AndrolibResources.getResTable(AndrolibResources.java:55)
    at brut.androlib.Androlib.getResTable(Androlib.java:64)
    at brut.androlib.ApkDecoder.setTargetSdkVersion(ApkDecoder.java:209)
    at brut.androlib.ApkDecoder.decode(ApkDecoder.java:92)
    at brut.apktool.Main.cmdDecode(Main.java:165)
    at brut.apktool.Main.main(Main.java:81)
Caused by: java.io.IOException: Expected: 0x00000008, got: 0x00000001
    at brut.util.ExtDataInput.skipCheckShort(ExtDataInput.java:56)
    at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:238)
    at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:201)
    at brut.androlib.res.decoder.ARSCDecoder.readConfig(ARSCDecoder.java:189)
    at brut.androlib.res.decoder.ARSCDecoder.readType(ARSCDecoder.java:157)
    at brut.androlib.res.decoder.ARSCDecoder.readPackage(ARSCDecoder.java:114)
    at brut.androlib.res.decoder.ARSCDecoder.readTable(ARSCDecoder.java:78)
    at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:47)
    ... 8 more

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 25 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Okay spent a good deal of time this weekend on this. While I don’t have a fix, I have good news. I’ve isolated the problem down to this struct - https://github.com/android/platform_frameworks_base/blob/master/include/androidfw/ResourceTypes.h#L897

Before that function runs we are position 20 (byte) of the reader, at the end of it. We are at 72. 72 - 20 = 52 bytes.

    private static final int KNOWN_CONFIG_BYTES = 52;

That is exactly whats expected, so the problem doesn’t make much sense. Before this function runs we have - https://github.com/iBotPeaches/Apktool/blob/6ee029dd30808a05f842c46672261a27dbb107da/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java#L171

Or entriesStart variable. This allows us to skip the entire block if needed since we know where the next “block” begins. For this instance we see the entriesStart at 5140 (0x1414), but our actual value is 5136 or (0x1410). As you can see, there is the 4 missing bytes.

The entire time I spent looking for the missing 4 bytes I failed. Skipping these bytes might prove to cause a problem, but we know the mistake happens at this struct - https://github.com/android/platform_frameworks_base/blob/master/include/androidfw/ResourceTypes.h#L897

You can compare that struct to our reading here - https://github.com/iBotPeaches/Apktool/blob/6ee029dd30808a05f842c46672261a27dbb107da/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ARSCDecoder.java#L266

After multiple multiple checks, there is no error there.

So the fix. Currently our DataInput has no counter. I need to add a decorator or wrap it in a counting stream so I can get current position. If after key points in apktool’s execution if the next position doesn’t match whats expected we either have a bug, problem or a place to simply skip bytes and hope for the best.

Couple notes

  1. No I can’t just raise KNOWN_CONFIG_BYTES. That matches the size variable of the ResConfig which is still 52.
  2. Yes the 52 is right. The read starts at position 20 and ends at 72. 72 - 20 = 52.
  3. Does the size (4 bytes) count towards that? As of now yes, but that would explain the missing 4 bytes. However simply skipping those 4 bytes break apks everywhere.

Yeah this is strange and regression. I thought the problem occurred during my massive changes in 2.0.3, but this is isolated to changes between 2.0.0 and 2.0.1. More importantly during the read of ConfigFlags.

Working on a fix.

Still not fixed in 2.7.1

I have a similar issue. After i deleted resources.arsc, it passed.

➜  G930F_Galaxy_S7 apktool if framework-res.apk -t 1131
I: Framework installed to: /home/ibotpeaches/apktool/framework/1-1131.apk
➜  G930F_Galaxy_S7 apktool if twframework-res.apk -t 1131
I: Framework installed to: /home/ibotpeaches/apktool/framework/2-1131.apk
➜  G930F_Galaxy_S7 apktool d SecContacts_M.apk -t 1131
I: Using Apktool 2.1.1-032a3e-SNAPSHOT on SecContacts_M.apk
I: Loading resource table...
I: Decoding Shared Library (touchwiz), pkgId: 2
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/ibotpeaches/apktool/framework/1-1131.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
➜  G930F_Galaxy_S7 apktool d SystemUI.apk -t 1131
I: Using Apktool 2.1.1-032a3e-SNAPSHOT on SystemUI.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/ibotpeaches/apktool/framework/1-1131.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
➜  G930F_Galaxy_S7 

The other application in this thread. Proving both work with this patch. I’ll clean it up and merge it in over the weekend / tonight.

Thank you for getting back to me quickly, @iBotPeaches. You mentioned that the error is caused by stricter validation in the Zip class in some newer Java versions. Based on the discussion in ticket #2553, can I resolve this issue by switching to a different Java version when using apktool?

Maybe?

The LTS versions were patched as well.

Since 2.5.1 has not released, I worked-around with this tutorial. Hope it helps someone. https://platinmods.com/threads/how-to-fix-apktool-decompile-error-using-mt-manager-app-arscdecoder-error.121708/

➜  Bug1131 apktool d framework-res.apk -f
I: Using Apktool 2.1.1-032a3e-SNAPSHOT on framework-res.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
➜  Bug1131 

Due to the complexity of this change. I’ll need to test this a lot more, but it is working for the test suite and the original apk here. So thats good news.

@iBotPeaches Having the same issue with the Galaxy S7. I can install and decompile frameworks and secsettings with 2.0.0, other apks get the same error as above. If I switch to 2.0.3 or build form source, after installing frameworks, I receive a non stop entire apk of the following error (SecContacts was used in screenshot. Terminal wouldnt let me copy)

screenshot- https://drive.google.com/file/d/0B3FpYTXXDE_ARTlVYWtsM2o2R3M/view?usp=sharing

apks- https://drive.google.com/file/d/0B3FpYTXXDE_AbjF0NEpqNEQ2a1E/view?usp=sharing