使用python編寫腳本獲取手機當(dāng)前應(yīng)用apk的信息
更新時間:2014年07月21日 16:45:38 投稿:whsnow
使用aapt工具獲取apk的信息,保存至腳本所在目錄下的PackageInfo.txt文件中,需要的朋友可以參考下
前提是已設(shè)置ANDROID_HOME環(huán)境變量,使用aapt工具獲取apk的信息,保存至腳本所在目錄下的PackageInfo.txt文件中:
import os
import tempfile
import re
tempFile = tempfile.gettempdir()
def get_aapt():
if "ANDROID_HOME" in os.environ:
rootDir = os.path.join(os.environ["ANDROID_HOME"], "build-tools")
for path, subdir, files in os.walk(rootDir):
if "aapt.exe" in files:
return os.path.join(path, "aapt.exe")
else:
return "ANDROID_HOME not exist"
def get_current_package_name():
pattern = re.compile(r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+")
os.popen("adb wait-for-device")
out = os.popen("adb shell dumpsys input | findstr FocusedApplication").read()
package_name = pattern.findall(out)[0].split("/")[0]
return package_name
def get_match_apk(package_name):
list = []
for packages in os.popen("adb shell pm list packages -f " + package_name).readlines():
list.append(packages.split(":")[-1].split("=")[0])
apk_name = list[0].split("/")[-1]
os.popen("adb pull " + list[0] + " " + tempFile)
return tempFile + "\\" + apk_name
if __name__ == "__main__":
os.popen(get_aapt() + \
" dump badging " + \
get_match_apk(get_current_package_name()) + \
" > PackageInfo.txt")
os.popen("del " + tempFile + "\\*.apk")
相關(guān)文章
Python 實現(xiàn)數(shù)據(jù)結(jié)構(gòu)-堆棧和隊列的操作方法
隊、棧和鏈表一樣,在數(shù)據(jù)結(jié)構(gòu)中非?;A(chǔ)一種數(shù)據(jù)結(jié)構(gòu),同樣他們也有各種各樣、五花八門的變形和實現(xiàn)方式。這篇文章主要介紹了Python 實現(xiàn)數(shù)據(jù)結(jié)構(gòu)-堆棧和隊列的操作方法,需要的朋友可以參考下2019-07-07
python代碼實現(xiàn)TSNE降維數(shù)據(jù)可視化教程
今天小編就為大家分享一篇python代碼實現(xiàn)TSNE降維數(shù)據(jù)可視化教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02
Python re 模塊findall() 函數(shù)返回值展現(xiàn)方式解析
這篇文章主要介紹了Python re 模塊findall() 函數(shù)返回值展現(xiàn)方式解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-08-08
python3 QT5 端口轉(zhuǎn)發(fā)工具兩種場景分析
這篇文章主要介紹了python3 QT5 端口轉(zhuǎn)發(fā)工具,功能是打開本機端口,映射到指定IP的端口,接下來通過兩種場景給大家詳細介紹,感興趣的朋友一起看看吧2022-01-01

