1. 程式人生 > >python獲取安卓包名與activity方法

python獲取安卓包名與activity方法

添加 name open pytho activit main 獲取 activity exist

代碼如下:

def adbcmdapk(filepath):
    if not os.path.exists(filepath):
        return 0
    getPackageActivity = ‘aapt d badging %s |findstr "package launchable-activity"‘ % (filepath)
    result = os.popen(getPackageActivity).readlines()
    packageandpackage = {}
    package = ""
    activity = ""
    for i in range(len(result)):
        if "package" in result[i]:
            nameNumber = result[i].find("e=‘")
            versionCodeNumber = result[i].find("‘ v")
            package = result[i][nameNumber + 3:versionCodeNumber]
        if "launchable-activity" in result[i]:
            nameNumber = result[i].find("e=‘")
            versionCodeNumber = result[i].find("‘  l")
            activity = result[i][nameNumber + 3:versionCodeNumber]
        # 添加到字典中
        packageandpackage[package] = activity
    return packageandpackage

測試類


if __name__ == ‘__main__‘:
    pa = "E:\\toontest3.8.1.apk"
    print(adbcmdapk(pa))

結果:

{‘com.systoon.toon‘: ‘com.systoon.toon.user.login.view.WelcomeActivity‘}

python獲取安卓包名與activity方法