| 1 | # Validation test using top Play Store applications |
| 2 | |
| 3 | On 04/11/2023, a comprehensive dataset comprising 1809 applications, exceeding 53GB in total, was retrieved from all categories on the Play Store. The objective is to subject these applications to analysis using apkInspector in conjunction with [androguard](https://github.com/androguard/androguard) and [zipfile](https://docs.python.org/3/library/zipfile.html) for the purpose of validating the accuracy of apkInspector's results. |
| 4 | |
| 5 | The methodology involves a dual approach. Firstly, leveraging zipfile, we extracted the contents of each APK. Subsequently, apkInspector was employed for the same task. The ensuing directories from both methods were then compared to ensure the exact same output, thereby validating the consistency of results. |
| 6 | |
| 7 | Moving to the second phase, our focus shifts to extracting the AndroidManifest.xml files. This was performed separately using both androguard and apkInspector. The contents of these manifest files was then undergone a thorough comparison utilizing `xml.etree.ElementTree` to verify that they encompass identical elements, adding an additional layer of validation to the analysis process. |
| 8 | |
| 9 | The categories from which the applications were retrieved were the following: |
| 10 | ~~~~ |
| 11 | ANDROID_WEAR |
| 12 | WATCH_FACE |
| 13 | ART_AND_DESIGN |
| 14 | AUTO_AND_VEHICLES |
| 15 | BEAUTY |
| 16 | BOOKS_AND_REFERENCE |
| 17 | BUSINESS |
| 18 | COMICS |
| 19 | COMMUNICATION |
| 20 | DATING |
| 21 | EDUCATION |
| 22 | ENTERTAINMENT |
| 23 | EVENTS |
| 24 | FINANCE |
| 25 | FOOD_AND_DRINK |
| 26 | GAME |
| 27 | Google Cast, we retrieved 0 packages. |
| 28 | HEALTH_AND_FITNESS |
| 29 | HOUSE_AND_HOME |
| 30 | FAMILY |
| 31 | LIBRARIES_AND_DEMO |
| 32 | LIFESTYLE |
| 33 | MAPS_AND_NAVIGATION |
| 34 | MEDICAL |
| 35 | MUSIC_AND_AUDIO |
| 36 | NEWS_AND_MAGAZINES |
| 37 | PARENTING |
| 38 | PERSONALIZATION |
| 39 | PHOTOGRAPHY |
| 40 | PRODUCTIVITY |
| 41 | SHOPPING |
| 42 | SOCIAL |
| 43 | SPORTS |
| 44 | TOOLS |
| 45 | TRAVEL_AND_LOCAL |
| 46 | VIDEO_PLAYERS |
| 47 | WEATHER |
| 48 | ~~~~ |
| 49 | |
| 50 | ### The list of all the 1809 application is located [here](./packages_list.txt). |
| 51 | |
| 52 | |
| 53 | |
| 54 | ## Zip comparison |
| 55 | Utilizing [filecmp](https://docs.python.org/3/library/filecmp.html) and more specifically the [dircmp](https://docs.python.org/3/library/filecmp.html#filecmp.dircmp) class, we compare the two directories where on the first one we have extracted the apk using [zipfile](https://docs.python.org/3/library/zipfile.html) and on the second we used apkInspector. |
| 56 | ~~~~ |
| 57 | comparison = filecmp.dircmp(method1_directory, method2_directory) |
| 58 | ~~~~ |
| 59 | |
| 60 | ## AndroidManifest comparison |
| 61 | Using `xml.etree.ElementTree` we are parsing the resulting AndroidManifest.xml files from androguard and apkinspector and then compare the elements found in each case. The comparison includes checking every tag along with their attributes and any potential children. |
| 62 | The comparison method looks like the following: |
| 63 | ~~~~ |
| 64 | def compare_elements(elem1, elem2): |
| 65 | # Compare tags |
| 66 | if get_local_name(elem1.tag) != get_local_name(elem2.tag): |
| 67 | return False |
| 68 | |
| 69 | # Compare attributes |
| 70 | attrib_names1 = {k for k, v in elem1.attrib.items()} |
| 71 | attrib_names2 = {k for k, v in elem2.attrib.items()} |
| 72 | |
| 73 | # Compare sets of attribute names |
| 74 | if attrib_names1 != attrib_names2: |
| 75 | return False |
| 76 | |
| 77 | # Compare children |
| 78 | if len(elem1) != len(elem2): |
| 79 | return False |
| 80 | |
| 81 | for child1, child2 in zip(elem1, elem2): |
| 82 | if not compare_elements(child1, child2): |
| 83 | return False |
| 84 | |
| 85 | return True |
| 86 | ~~~~ |
| 87 | |
| 88 | |
| 89 | ## Results |
| 90 | |
| 91 | The results from the test can be seen below: |
| 92 | ~~~~ |
| 93 | Total Packages Tested: 1809 |
| 94 | Successful Unzipping: 1809 |
| 95 | Successful Manifest Comparison: 1806 |
| 96 | Packages with differences in the AndroidManifest: 3 |
| 97 | Packages where androguard failed to parse the AndroidManifest: 0 |
| 98 | Packages where apkInspector failed to parse the AndroidManifest: 0 |
| 99 | ~~~~ |
| 100 | |
| 101 | - The `Successful Unzipping` means that 100% of the applications were correctly unzipped. |
| 102 | - The `Successful Manifest Comparison` means that all applications except three, had the same AndroidManifest.xml file for both androguard and apkInspector. |
| 103 | - The `Packages with differences in the AndroidManifest` is for the applications that did not have a `Successful Manifest Comparison`. |
| 104 | - The `Packages where androguard failed to parse the AndroidManifest` and `Packages where apkInspector failed to parse the AndroidManifest` are for the applications that produced an AndroidManifest that for some reason did not have the correct XML format and parsing it using `xml.etree.ElementTree` failed. |
| 105 | |
| 106 | |
| 107 | The following three are the applications that were marked with a difference in the AndroidManifest: |
| 108 | - com.paypal.android.p2pmobile.apk |
| 109 | - by.iba.tapxphone.apk |
| 110 | - com.playstation.remoteplay.apk |
| 111 | |
| 112 | Their logs as to why they failed are similar and as an example one of them is shown: |
| 113 | ~~~~ |
| 114 | Current APK being processed: com.playstation.remoteplay.apk | 1295/1809 |
| 115 | manifest attribute names: {'UNKNOWN_SYSTEM_ATTRIBUTE_01010573', '{http://schemas.android.com/apk/res/android}versionCode', 'versionName', 'platformBuildVersionCode', 'package', 'platformBuildVersionName', 'UNKNOWN_SYSTEM_ATTRIBUTE_01010572'} |
| 116 | manifest attribute names: {'{http://schemas.android.com/apk/res/android}Unknown_Attribute_Name_6402', '{http://schemas.android.com/apk/res/android}Unknown_Attribute_Name_6414', '{http://schemas.android.com/apk/res/android}versionCode', 'platformBuildVersionCode', '{http://schemas.android.com/apk/res/android}Unknown_Attribute_Name_2691', 'package', 'platformBuildVersionName'} |
| 117 | com.playstation.remoteplay.apk: DIFFERENT |
| 118 | ~~~~ |
| 119 | Their difference comes from the fact that unknown system attributes were detected (the reason why this happens is irrelevant for the purpose of this comparison). Androguard, as can also he seen [here](https://github.com/androguard/androguard/blob/master/androguard/core/axml/__init__.py#L828), marks the unknown attributes with the string `android:UNKNOWN_SYSTEM_ATTRIBUTE_` followed by a hex value, while apkInspector marks it with the string `Unknown_Attribute_Name_` followed by a random four digit number. |
| 120 | |
| 121 | Therefore, we can safely assume that even for these three cases the actual manifest is the same for both tools. |
| 122 | |
| 123 | **The results of the test indicate that apkInspector can unzip an APK and decode the AndroidManifest.xml reliably and efficiently, comparable to other tools such as androguard.** |