NetEaseGame / ATX

Smart phone automation tool. Support iOS, Android, WebApp and game.
Apache License 2.0
1.58k stars 422 forks source link

移除atx-androguard依赖 #121

Closed codeskyblue closed 7 years ago

codeskyblue commented 7 years ago

Usage of axmlparserpy

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