Advertisement
Mr_hEx

Find Entry Point Or Main Activity for APK file From AI

Sep 23rd, 2023 (edited)
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. from xml.dom import minidom
  2.  
  3. # Open and read the AndroidManifest.xml file
  4. with open('AndroidManifest.xml', 'r') as file:
  5.     xml_content = file.read()
  6.  
  7. # Parse the XML content to find the main activity
  8. dom = minidom.parseString(xml_content)
  9. application = dom.getElementsByTagName('application')[0]
  10.  
  11. # Initialize a variable to hold the name of the main activity
  12. main_activity_name = None
  13.  
  14. # Iterate over all 'activity' elements in the 'application' element
  15. for activity in application.getElementsByTagName('activity'):
  16.     # Iterate over all 'intent-filter' elements in the 'activity' element
  17.     for intent_filter in activity.getElementsByTagName('intent-filter'):
  18.         # Check if the 'intent-filter' has an 'action' with name 'android.intent.action.MAIN'
  19.         has_main_action = any(action.getAttribute('android:name') == 'android.intent.action.MAIN'
  20.                               for action in intent_filter.getElementsByTagName('action'))
  21.         # Check if the 'intent-filter' has a 'category' with name 'android.intent.category.LAUNCHER'
  22.         has_launcher_category = any(category.getAttribute('android:name') == 'android.intent.category.LAUNCHER'
  23.                                     for category in intent_filter.getElementsByTagName('category'))
  24.        
  25.         # If both conditions are met, this activity is the main activity
  26.         if has_main_action and has_launcher_category:
  27.             main_activity_name = activity.getAttribute('android:name')
  28.             break
  29.  
  30.     if main_activity_name:
  31.         break
  32.  
  33. # Print the name of the main activity
  34. print(f"Main Activity: {main_activity_name}")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement