Mr_hEx icon

Find Entry Point Or Main Activity for APK file From AI

Mr_hEx | PRO | 09/23/23 11:30:15 AM UTC (Edited) | 0 ⭐ | 1069 👁️ | Never ⏰ | []
Python |

1.61 KB

|

None

|

0 👍

/

0 👎

from xml.dom import minidom
 
# Open and read the AndroidManifest.xml file
with open('AndroidManifest.xml', 'r') as file:
    xml_content = file.read()
 
# Parse the XML content to find the main activity
dom = minidom.parseString(xml_content)
application = dom.getElementsByTagName('application')[0]
 
# Initialize a variable to hold the name of the main activity
main_activity_name = None
 
# Iterate over all 'activity' elements in the 'application' element
for activity in application.getElementsByTagName('activity'):
    # Iterate over all 'intent-filter' elements in the 'activity' element
    for intent_filter in activity.getElementsByTagName('intent-filter'):
        # Check if the 'intent-filter' has an 'action' with name 'android.intent.action.MAIN'
        has_main_action = any(action.getAttribute('android:name') == 'android.intent.action.MAIN'
                              for action in intent_filter.getElementsByTagName('action'))
        # Check if the 'intent-filter' has a 'category' with name 'android.intent.category.LAUNCHER'
        has_launcher_category = any(category.getAttribute('android:name') == 'android.intent.category.LAUNCHER'
                                    for category in intent_filter.getElementsByTagName('category'))
        
        # If both conditions are met, this activity is the main activity
        if has_main_action and has_launcher_category:
            main_activity_name = activity.getAttribute('android:name')
            break
 
    if main_activity_name:
        break
 
# Print the name of the main activity
print(f"Main Activity: {main_activity_name}")
 

Comments