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'}
class ApkInfo():
def __init__(self, apkPath):
self.apkPath = apkPath
def getApkBaseInfo(self):
p = subprocess.Popen("aapt dump badging %s" % self.apkPath, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
match = re.compile("package: name='(\S+)' versionCode='(\d+)' versionName='(\S+)'").match(output.decode())
if not match:
raise Exception("can't get packageinfo")
packagename = match.group(1)
versionCode = match.group(2)
versionName = match.group(3)
print('packagename:' + packagename)
print('versionCode:' + versionCode)
print('versionName:' + versionName)
return packagename, versionName, versionCode
if name == 'main':
ApkInfo(r"E:\toontest3.8.1.apk").getApkBaseInfo()
packagename:com.systoon.toon
versionCode:1803060450
versionName:3.8.1
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。