import zipfile
from axmlparserpy.axmlprinter import AXMLPrinter
def get_package_name_activity(path):
file = zipfile.ZipFile(path, 'r')
manifest = file.read('AndroidManifest.xml')
file.close()
dom = parseString(AXMLPrinter(manifest).getBuff())
return get_package_name(dom), get_main_activity(dom)
class Manifest(object):
def __init__(self, dom):
self._dom = dom
@property
def package_name(self):
return dom.documentElement.getAttribute('package')
def get_package_name(dom):
"""
Returns:
package name
"""
return dom.documentElement.getAttribute('package')
def get_main_activity(dom):
"""
Returns:
the name of the main activity
"""
x = set()
y = set()
for item in dom.getElementsByTagName("activity"):
for sitem in item.getElementsByTagName("action"):
val = sitem.getAttribute("android:name")
if val == "android.intent.action.MAIN":
x.add(item.getAttribute("android:name"))
for sitem in item.getElementsByTagName("category"):
val = sitem.getAttribute("android:name")
if val == "android.intent.category.LAUNCHER":
y.add(item.getAttribute("android:name"))
z = x.intersection(y)
if len(z) > 0:
return z.pop()
return None
Usage of axmlparserpy