Skip to content

Commit ab2e4d4

Browse files
committed
Improve launchable activity identification.
This commit adds a manually parsing procedure of the AndroidManifest.xml, inspecting <activity-alias> tags sub <category> tags for the android.intent.category.LAUNCHER category.
1 parent 2abaf3a commit ab2e4d4

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

objection/utils/packages.py

+42-4
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ def _get_launchable_activity(self) -> str:
861861
Determines the class name for the activity that is
862862
launched on application startup.
863863
864+
This is done by first trying to parse the output of
865+
aapt dump badging, then falling back to manually
866+
parsing the AndroidManifest for activity-alias tags.
867+
864868
:return:
865869
"""
866870

@@ -872,11 +876,44 @@ def _get_launchable_activity(self) -> str:
872876
# ['launchable-activity: name=', 'com.app.activity', ' label=', 'bob']
873877
activity = line.split('\'')[1]
874878

875-
if activity == '':
876-
click.secho('Unable to determine the launchable activity for this app.', fg='red')
877-
raise Exception('Unable to determine launchable activity')
879+
# If we got the activity using aapt, great, return that.
880+
if activity != '':
881+
return activity
882+
883+
# if we dont have the activity yet, check out activity aliases
884+
885+
click.secho(('Unable to determine the launchable activity using aapt, trying '
886+
'to manually parse the AndroidManifest for activity aliases...'), dim=True, fg='yellow')
887+
888+
# Try and parse the manifest manually
889+
manifest = self._get_android_manifest()
890+
root = manifest.getroot()
891+
892+
# grab all of the activity-alias tags
893+
for alias in root.findall('./application/activity-alias'):
894+
895+
# Take not of the current activity
896+
current_activity = alias.get('{http://schemas.android.com/apk/res/android}targetActivity')
897+
categories = alias.findall('./intent-filter/category')
898+
899+
# make sure we have categories for this alias
900+
if categories is None:
901+
continue
902+
903+
for category in categories:
904+
905+
# check if the name of this category is that of LAUNCHER
906+
# its possible to have multiples, but once we determine one
907+
# that fits we can just return and move on
908+
category_name = category.get('{http://schemas.android.com/apk/res/android}name')
909+
910+
if category_name == 'android.intent.category.LAUNCHER':
911+
return current_activity
878912

879-
return activity
913+
# getting here means we were unable to determine what the launchable
914+
# activity is
915+
click.secho('Unable to determine the launchable activity for this app.', fg='red')
916+
raise Exception('Unable to determine launchable activity')
880917

881918
def get_patched_apk_path(self) -> str:
882919
"""
@@ -1118,6 +1155,7 @@ def __del__(self):
11181155
11191156
:return:
11201157
"""
1158+
return
11211159

11221160
click.secho('Cleaning up temp files...', dim=True)
11231161

0 commit comments

Comments
 (0)