AndroidDeveloperLB / apk-parser

BSD 2-Clause "Simplified" License
26 stars 11 forks source link

Bug: Unable to fetch app-names (labels) of some apps properly #3

Open AndroidDeveloperLB opened 2 years ago

AndroidDeveloperLB commented 2 years ago

Running the sample, I've found this app that it failed to get its app-name (label) properly :

apk label is different for "com.google.android.networkstack.permissionconfig" on /system/priv-app/NetworkPermissionConfigGoogle/NetworkPermissionConfigGoogle.apk : correct one is: "com.android.server.NetworkPermissionConfig" vs found: "com.google.android.networkstack.permissionconfig"isSystemApp?true

This might be related:

https://github.com/hsiafan/apk-parser/issues/123 https://github.com/hsiafan/apk-parser/issues/99

Attached the problematic APK:

NetworkPermissionConfigGoogle.zip

EDIT: another case:

apk label is different for "com.google.android.gms" on /product/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk : correct one is: "Google Play services" vs found: "resourceId:0x7f1a0033"

It became quite large, so I had to split it. Rename "PrebuiltGmsCore.zip" to "PrebuiltGmsCore.zip.001" and "PrebuiltGmsCore2.zip" to "PrebuiltGmsCore.zip.002" , and "PrebuiltGmsCore3.zip" to "PrebuiltGmsCore.zip.003"

PrebuiltGmsCore.zip PrebuiltGmsCore2.zip PrebuiltGmsCore3.zip

AndroidDeveloperLB commented 2 years ago

Another example, originated from Vivo V23:

apk label is different for "com.mediatek.ims" on /system/priv-app/ImsService/ImsService.apk : correct one is: "com.mediatek.ims.ImsApp" vs found: "com.mediatek.ims" isSystemApp?true

ImsService.zip

AndroidDeveloperLB commented 2 years ago

Another example, from Samsung Galaxy A32:

apk label is different for "com.android.stk" on /system/app/Stk/Stk.apk : correct one is: "SIM Toolkit" vs found: "SIM toolkit" isSystemApp?true apk label is different for "com.android.stk2" on /system/app/Stk2/Stk2.apk : correct one is: "SIM Toolkit2" vs found: "SIM toolkit" isSystemApp?true apk label is different for "com.samsung.app.newtrim" on /system/app/VideoTrimmer/VideoTrimmer.apk : correct one is: "Video trimmer" vs found: "Video Trimmer" isSystemApp?true

APKs:

apks.zip

AndroidDeveloperLB commented 2 years ago

More examples, this time including apps that are not built-in:

apk label is different for "com.unicell.pangoandroid" on /data/app/~~1tUbh_pu1ADTMAVluBDmOg==/com.unicell.pangoandroid-uvBuwCw2W_yUsg5wwe9D1Q==/base.apk : correct one is: "Pango" vs found: "פנגו" isSystemApp?false apk label is different for "com.google.android.ext.shared" on /system/app/GoogleExtShared/GoogleExtShared.apk : correct one is: "Android Shared Library" vs found: "{7:65536}" isSystemApp?true apk label is different for "android.autoinstalls.config.google.nexus" on /product/app/PlayAutoInstallConfig/PlayAutoInstallConfig.apk : correct one is: "Device configuration" vs found: "@string/app_name" isSystemApp?true apk label is different for "com.samsung.slsi.telephony.oemril" on /system_ext/priv-app/OemRilService/OemRilService.apk : correct one is: "com.samsung.slsi.telephony.oemril.OemRilApp" vs found: "com.samsung.slsi.telephony.oemril" isSystemApp?true

Attached for some:

labels.zip

msdhedhi commented 2 weeks ago

I ran into a related issue where the original apk-parser could no longer consume apk files from an A15 aosp build. I was able to fork/patch the library: https://github.com/msdhedhi/apk-parser/commit/6104ca509ab0177aed82852f13b447e6b7d961db

AndroidDeveloperLB commented 2 weeks ago

@msdhedhi Interesting. Very appreciate it that you've contacted me here and offer this. Have you tested the parsing of the apps I've mentioned? Also, how did you find about this solution? Where did you look at? And why not fork from my repository?

msdhedhi commented 2 weeks ago

I tried the apks in "labels.zip". The manifest for OemRilService.apk does not have a "android:label" attribute so the label is being returned as null. GoogleExtShared.apk reports the correct label "Android Services Library" PlayAutoInstallConfig.apk is returning the label as "@string/app_name" so that still needs to be looked at. To debug this issue, i looked at the struct ResTable_type in file https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-15.0.0_r5/libs/androidfw/include/androidfw/ResourceTypes.h The following checkin added support for new formats https://android.googlesource.com/platform/frameworks/base/+/a1f2bce0e56185d8a3ddbbb75cf9daacdcb5a3d2%5E%21/libs/androidfw/include/androidfw/ResourceTypes.h I did not fork from your repo since it has pulled in a bunch of androidx imports and kotlkin code and our solution currently requires it to be all java without any andoridx/kotlin libraries.

AndroidDeveloperLB commented 2 weeks ago

Those libraries are quite common on Android, and Kotlin is becoming more and more popular. Besides, creating a release version using Proguard, a lot would be removed anyway if not used. I also applied some fixes on the way. You use it outside of Android, perhaps?

I had created the sample to have some tests on the current device, too, to check for weird issues. Such a thing helps to find possible issues on the repository in parsing APKs, from actual scenarios. That's how I've found all these APK files.

Is it the only thing you've fixed?

AndroidDeveloperLB commented 3 days ago

@msdhedhi I tried to add your changes to mine (was hard but I think I got it). Still got 36 errors of label fetching. About "OemRilService.apk", Android OS says its label isn't empty but "com.samsung.slsi.telephony.oemril.OemRilApp".

About "GoogleExtShared.apk", seems it's not installed anymore on my device, but it's installed on Android emulator, and indeed it got "Android Shared Library" as label, so you made the detection better indeed.

About "PlayAutoInstallConfig.apk", sadly the app isn't installed anymore and I can't install it on my device, but I can on the emulator.

I wanted now to compare before&after , on my device and on emulator.

Device (Pixel 6, Android 15): label errors: 25 before, 36 after However, number of errors of not being able to parse APK files at all decreased in , from 94 to 17. image

Emulator (API 34 - Android 14): label errors: 2 before, 1 after.

image

So again an improvement in label detection. This time it failed to get the label of "com.google.android.ondevicepersonalization.services" (OnDevicePersonalizationGoogle.apk, attached here). Supposed to be "com.android.ondevicepersonalization.services.OnDevicePersonalizationApplication". Seems similar case of "OemRilService.apk". Perhaps the OS takes the path to the class that extends Application for some reason. I've noticed it when checking the manifest via online APK parsers:

http://www.javadecompilers.com/apk https://sisik.eu/apk-tool

OnDevicePersonalizationGoogle.zip

Please test on a real device against all APK files of the OS. This way you could find issues as I've found. Here's the APK of my sample, to test on all installed apps:

app-debug.zip

AndroidDeveloperLB commented 12 hours ago

@msdhedhi Here are many more APK files that got the app label wrong. Sometimes it's just by a single letter for some reason (upper-case vs lower-case) :

apks.zip

apks2.zip

apks3.zip

Another one is a bit big, so here is a link to it: https://www.apkmirror.com/apk/google-inc/pixel-camera-services/pixel-camera-services-2-0-654932140-02-release/