Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HOumoumen opened this issue Jan 9, 2016 · 25 comments · Fixed by #1237
Closed
Labels
Milestone

Comments

@HOumoumen
Copy link

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
@iBotPeaches
Copy link
Owner

Looks like duplicate of #1121 , but I haven't got an APK for either.

@wanam
Copy link

wanam commented Jan 14, 2016

I'm getting the same issue on the new TW M builds with the latest apktool release and master branch:

I: Using Apktool 2.1.0-a64a03-SNAPSHOT on framework-res.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:544)
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:67)
at brut.androlib.ApkDecoder.setTargetSdkVersion(ApkDecoder.java:198)
at brut.androlib.ApkDecoder.decode(ApkDecoder.java:96)
at brut.apktool.Main.cmdDecode(Main.java:165)
at brut.apktool.Main.main(Main.java:81)
Caused by: java.io.IOException: Expected: 0x00000008, got: 0x00000000
at brut.util.ExtDataInput.skipCheckShort(ExtDataInput.java:56)
at brut.androlib.res.decoder.ARSCDecoder.readValue(ARSCDecoder.java:282)
at brut.androlib.res.decoder.ARSCDecoder.readEntry(ARSCDecoder.java:224)
at brut.androlib.res.decoder.ARSCDecoder.readTableType(ARSCDecoder.java:212)
at brut.androlib.res.decoder.ARSCDecoder.readTableTypeSpec(ARSCDecoder.java:154)
at brut.androlib.res.decoder.ARSCDecoder.readTablePackage(ARSCDecoder.java:116)
at brut.androlib.res.decoder.ARSCDecoder.readTableHeader(ARSCDecoder.java:78)
at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:47)
... 8 more

Apk: https://www.dropbox.com/s/i80xi2uyjlfttji/framework-res.apk?dl=0

@mythtrandyr
Copy link

@wanam
Use Apktool v2.0.0 for TW M framework-res & other file

@wanam
Copy link

wanam commented Jan 15, 2016

@mythtrandyr Nice catch, 2.0.0 is working fine.
@iBotPeaches Is this a regression?

@iBotPeaches
Copy link
Owner

Confirmed.

@iBotPeaches
Copy link
Owner

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.

@omervk
Copy link

omervk commented Feb 21, 2016

I have a similar issue. Would an additional APK sample help?

@ShinySide
Copy link

@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

@iBotPeaches
Copy link
Owner

This broke because of this commit - 6ee029d

If we revert this commit we break #924

On this bug.

76 bytes read (reverted) = good.
72 bytes read (not reverted) = bad

On #924
72 bytes read (not reverted) = good
68 bytes read (reverted) = bad

So patch or not something gets broken. I need to figure out why this is, but I now know the problem. Sorry for the delay.

@jerdog
Copy link

jerdog commented Apr 8, 2016

Any update on this @iBotPeaches ?

@iBotPeaches
Copy link
Owner

Unfortunately nothing easy. Like I had expected, simply reverting the commit that caused the problem this far down the commit line doesn't work. Trying to make this work with the current codebase I don't think is the best method of attack as tons of refactoring has occurred around it.

We just have big problem in which some APKs rely on reading the remaining bytes in a ResConfig while others rely on skipping the reading of these extra bytes. This is a combination of KNOWN_BYTESand this fix. I'm thinking of a command line parameter for advanced users that sets KNOWN_BYTES so if these edge cases present themselves they can be solved with some googling and a different parameter.

@iBotPeaches
Copy link
Owner

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 -

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 -

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.

@iBotPeaches
Copy link
Owner

➜  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
Copy link
Owner

➜  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.

@hoshsadiq
Copy link

hoshsadiq commented Dec 18, 2016

Sorry to be a pain and open an old bug report, I'm having the same issue with the Sony Select APK.

~/bin/apktool d ~/Downloads/apk/Sony\ Select_5.0.7.zip --output ~/Downloads/apk/SonySelect.out
I: Using Apktool 2.2.1 on Sony Select_5.0.7.zip
I: Decoding AndroidManifest.xml with only framework resources...
Exception in thread "main" brut.androlib.AndrolibException: Could not decode XML
	at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:147)
	at brut.androlib.res.decoder.XmlPullStreamDecoder.decodeManifest(XmlPullStreamDecoder.java:153)
	at brut.androlib.res.decoder.ResFileDecoder.decodeManifest(ResFileDecoder.java:140)
	at brut.androlib.res.AndrolibResources.decodeManifest(AndrolibResources.java:162)
	at brut.androlib.Androlib.decodeManifestFull(Androlib.java:117)
	at brut.androlib.ApkDecoder.decode(ApkDecoder.java:120)
	at brut.apktool.Main.cmdDecode(Main.java:166)
	at brut.apktool.Main.main(Main.java:81)
Caused by: java.io.IOException: Expected: 0x00080003, got: 0x6d783f3c
	at brut.util.ExtDataInput.skipCheckInt(ExtDataInput.java:48)
	at brut.androlib.res.decoder.AXmlResourceParser.doNext(AXmlResourceParser.java:843)
	at brut.androlib.res.decoder.AXmlResourceParser.next(AXmlResourceParser.java:100)
	at brut.androlib.res.decoder.AXmlResourceParser.nextToken(AXmlResourceParser.java:110)
	at org.xmlpull.v1.wrapper.classic.XmlPullParserDelegate.nextToken(XmlPullParserDelegate.java:105)
	at brut.androlib.res.decoder.XmlPullStreamDecoder.decode(XmlPullStreamDecoder.java:140)
	... 7 more

EDIT: scrap that, remove the --output option prevents this from happening

@iBotPeaches
Copy link
Owner

➜  Bug1131 apktool d Sony\ Select_5.0.7.apk 
I: Using Apktool 2.2.2-7c6c7a-SNAPSHOT on Sony Select_5.0.7.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/ibotpeaches/.local/share/apktool/framework/1.apk
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 apktool d Sony\ Select_5.0.7.apk --output foo
I: Using Apktool 2.2.2-7c6c7a-SNAPSHOT on Sony Select_5.0.7.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/ibotpeaches/.local/share/apktool/framework/1.apk
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 

Not sure @hoshsadiq , couldn't duplicate with --output or not.

@hoshsadiq
Copy link

Very odd hm. I'll try and replicate it again and tie down the causes if you'd like! Will report back. I think it may be because I was giving it a path as a value for --output where --output actually just requires a dir name (correct me if I'm wrong).

@GYDHA
Copy link

GYDHA commented Dec 14, 2017

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

@ouihamdaoui
Copy link

Log For : app.apk

Log Type : Recompiling

Log Recorded At : 12 2018-01- 2:02:12,15

Log Recorded By : Advanced ApkTool v4.2.0 By BDFreak


W: C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\AndroidManifest.xml:17: error: No resource identifier found for attribute 'roundIcon' in package 'android'
W:
Exception in thread "main" brut.androlib.AndrolibException: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\pc\AppData\Local\Temp\brut_util_Jar_5011332091424466575.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 26, --version-code, 10, --version-name, 10.0, -F, C:\Users\pc\AppData\Local\Temp\APKTOOL277819359608319825.tmp, -0, arsc, -0, arsc, -I, C:\Users\pc\Desktop\AdvancedApkTool\1-BDFreak\Frameworks\1.apk, -S, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\res, -M, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\AndroidManifest.xml]
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:478)
at brut.androlib.Androlib.buildResources(Androlib.java:412)
at brut.androlib.Androlib.build(Androlib.java:311)
at brut.androlib.Androlib.build(Androlib.java:264)
at brut.apktool.Main.cmdBuild(Main.java:227)
at brut.apktool.Main.main(Main.java:84)
Caused by: brut.androlib.AndrolibException: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\pc\AppData\Local\Temp\brut_util_Jar_5011332091424466575.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 26, --version-code, 10, --version-name, 10.0, -F, C:\Users\pc\AppData\Local\Temp\APKTOOL277819359608319825.tmp, -0, arsc, -0, arsc, -I, C:\Users\pc\Desktop\AdvancedApkTool\1-BDFreak\Frameworks\1.apk, -S, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\res, -M, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:439)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:464)
... 5 more
Caused by: brut.common.BrutException: could not exec (exit code = 1): [C:\Users\pc\AppData\Local\Temp\brut_util_Jar_5011332091424466575.tmp, p, --forced-package-id, 127, --min-sdk-version, 15, --target-sdk-version, 26, --version-code, 10, --version-name, 10.0, -F, C:\Users\pc\AppData\Local\Temp\APKTOOL277819359608319825.tmp, -0, arsc, -0, arsc, -I, C:\Users\pc\Desktop\AdvancedApkTool\1-BDFreak\Frameworks\1.apk, -S, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\res, -M, C:\Users\pc\Desktop\AdvancedApkTool\3-Out\app.apk\AndroidManifest.xml]
at brut.util.OS.exec(OS.java:95)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:433)
... 6 more


@terrynguyen255
Copy link

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/

@teplinsky-maxim
Copy link

Still not fixed in 2.7.1

@harsh-im
Copy link

harsh-im commented Nov 9, 2023

@iBotPeaches getting the following error in the version 2.9.0. is this issue related to it?

I: Using Apktool 2.9.0 on 125358564fdedf675613b99233c8e8d8214f6187f94c18a733d040b80d39ebfb.apk
I: Loading resource table...
Exception in thread "main" brut.androlib.exceptions.AndrolibException: Could not decode arsc file
	at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:49)
	at brut.androlib.res.data.ResTable.loadResPackagesFromApk(ResTable.java:182)
	at brut.androlib.res.data.ResTable.loadMainPkg(ResTable.java:134)
	at brut.androlib.res.ResourcesDecoder.decodeResources(ResourcesDecoder.java:147)
	at brut.androlib.ApkDecoder.decode(ApkDecoder.java:104)
	at brut.apktool.Main.cmdDecode(Main.java:217)
	at brut.apktool.Main.main(Main.java:92)
Caused by: java.util.zip.ZipException: ZipFile invalid LOC header (bad signature)
	at java.base/java.util.zip.ZipFile$ZipFileInputStream.initDataOffset(ZipFile.java:935)
	at java.base/java.util.zip.ZipFile$ZipFileInputStream.read(ZipFile.java:946)
	at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:291)
	at java.base/java.io.BufferedInputStream.implRead(BufferedInputStream.java:325)
	at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:312)
	at java.base/java.io.FilterInputStream.read(FilterInputStream.java:71)
	at org.apache.commons.io.input.ProxyInputStream.read(ProxyInputStream.java:165)
	at com.google.common.io.LittleEndianDataInputStream.readAndCheckByte(LittleEndianDataInputStream.java:232)
	at com.google.common.io.LittleEndianDataInputStream.readUnsignedShort(LittleEndianDataInputStream.java:101)
	at com.google.common.io.LittleEndianDataInputStream.readShort(LittleEndianDataInputStream.java:194)
	at brut.util.DataInputDelegate.readShort(DataInputDelegate.java:46)
	at brut.androlib.res.data.arsc.ARSCHeader.read(ARSCHeader.java:46)
	at brut.androlib.res.decoder.ARSCDecoder.nextChunk(ARSCDecoder.java:668)
	at brut.androlib.res.decoder.ARSCDecoder.readResourceTable(ARSCDecoder.java:72)
	at brut.androlib.res.decoder.ARSCDecoder.decode(ARSCDecoder.java:44)

APK file : https://www.dropbox.com/scl/fo/5wymbvrd8nnpz0jrl74yz/h?rlkey=wzz6puinj0bwfukduuuktbcao&dl=0

@iBotPeaches
Copy link
Owner

@harsh-im - It is not. You have an archive (zip) that is being rejected by the increasing validation that the Zip Class offers in Java. Now AOSP/Android might accept it, but stricter Java validation may not.

What you are encountering is basically this ticket - #2553, but there is no good workaround at the moment as only option is to build a Zip class that doesn't invoke all the same criteria during parsing.

@harsh-im
Copy link

harsh-im commented Nov 9, 2023

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?

@iBotPeaches
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.