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
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.
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 theentriesStart
at5140
(0x1414
), but our actual value is5136
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
KNOWN_CONFIG_BYTES
. That matches the size variable of theResConfig
which is still 52.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 between2.0.0
and2.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.
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.
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/
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