jaredrummler / APKParser

APK parser for Android
Other
637 stars 107 forks source link

Bug: unable to parse some split APK files #17

Open AndroidDeveloperLB opened 4 years ago

AndroidDeveloperLB commented 4 years ago

Example attached:

split_delight.zip

The crash exception:

    java.lang.Error: com.jaredrummler.apkparser.exception.ParserException: Unexpected chunk Type:203
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1173)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: com.jaredrummler.apkparser.exception.ParserException: Unexpected chunk Type:203
        at com.jaredrummler.apkparser.parser.ResourceTableParser.readChunkHeader(ResourceTableParser.java:204)
        at com.jaredrummler.apkparser.parser.ResourceTableParser.readPackage(ResourceTableParser.java:96)
        at com.jaredrummler.apkparser.parser.ResourceTableParser.parse(ResourceTableParser.java:67)
        at com.jaredrummler.apkparser.ApkParser.parseResourceTable(ApkParser.java:417)
        at com.jaredrummler.apkparser.ApkParser.transBinaryXml(ApkParser.java:269)
        at com.jaredrummler.apkparser.ApkParser.parseManifestXml(ApkParser.java:207)
        at com.jaredrummler.apkparser.ApkParser.getManifestXml(ApkParser.java:126)
        at com.android.apkinstalltest.MainActivity$onCreate$1.run(MainActivity.kt:33)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919) 

Looking at the manifest xml string that it tried to build, I can see that its result is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:dist="http://schemas.android.com/apk/distribution" android:versionCode="11002120" android:versionName="1.1 (6007940)" android:isFeatureSplit="true" android:compileSdkVersion="29" android:compileSdkVersionCodename="10" package="com.google.pixel.livewallpaper" platformBuildVersionCode="11002120" platformBuildVersionName="1.1 (6007940)" split="delight" split="delight">
    <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="28" />
    <dist:module dist:onDemand="true" dist:title="resourceId:0x7f0d006b">
        <dist:fusing dist:include="false" />
    </http://schemas.android.com/apk/distribution:module>
    <application android:hasCode="false">
        <meta-data android:name="com.android.vending.derived.apk.id" android:value="1" />
    </application>
</manifest>

But according to some online tools, it should have been:

<?xml version="1.0" encoding="utf-8"?>
<manifest android:versionCode="11002120" android:versionName="1.1 (6007940)" android:isFeatureSplit="true" android:compileSdkVersion="29" android:compileSdkVersionCodename="10" package="com.google.pixel.livewallpaper" platformBuildVersionCode="11002120" platformBuildVersionName="1.1 (6007940)" split="delight" split="delight"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:dist="http://schemas.android.com/apk/distribution">
    <dist:module dist:onDemand="true" dist:title="@2131558507">
        <dist:fusing dist:include="false" />
    </dist:module>
    <application android:hasCode="false">
        <meta-data android:name="com.android.vending.derived.apk.id" android:value="1" />
    </application>
</manifest>

Somehow it got </http://schemas.android.com/apk/distribution:module> instead of </dist:module> .

So this makes it a non valid XML content. Also I noticed other differences, such as "resourceId:0x7f0d006b"

AndroidDeveloperLB commented 4 years ago

Possible fix:

https://github.com/jaredrummler/APKParser/issues/18