使用python编写脚本获取手机当前应用apk的信息
作者:whsnow 时间:2022-08-01 22:54:15
前提是已设置ANDROID_HOME环境变量,使用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")
标签:python,应用信息
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
PHP引用的调用方法分析
2023-11-06 15:23:23
PyCharm如何设置Console控制台输出自动换行
2022-05-22 03:42:18
![](https://img.aspxhome.com/file/2023/0/78510_0s.png)
Python求正态分布曲线下面积实例
2021-01-28 18:20:07
![](https://img.aspxhome.com/file/2023/6/81496_0s.jpg)
Python内置方法实现字符串的秘钥加解密(推荐)
2023-10-22 23:45:35
![](https://img.aspxhome.com/file/2023/8/103318_0s.jpg)
python中的global关键字的使用方法
2023-07-15 13:26:50
BeautifulSoup中find和find_all的使用详解
2023-11-08 21:00:22
![](https://img.aspxhome.com/file/2023/4/93514_0s.png)
Python通用验证码识别OCR库之ddddocr验证码识别
2021-05-16 22:55:00
![](https://img.aspxhome.com/file/2023/4/126914_0s.jpg)
SQL根据时间范围条件查询数据
2009-01-18 13:32:00
Django连接MQTT的示例代码
2022-10-04 22:40:39
Python模块相关知识点小结
2022-04-12 06:58:23
![](https://img.aspxhome.com/file/2023/5/102905_0s.png)
pygame实现贪吃蛇小游戏
2023-04-18 19:09:07
![](https://img.aspxhome.com/file/2023/2/105722_0s.jpg)
Oracle如何直接运行OS命令(上)第1/2页
2010-07-30 12:54:00
Python常用的json标准库
2022-02-26 10:37:52
Python制作简易版小工具之计算天数的实现思路
2023-10-29 08:12:07
![](https://img.aspxhome.com/file/2023/4/91874_0s.png)
python淘宝抢购脚本程序实现
2023-08-02 11:29:52
![](https://img.aspxhome.com/file/2023/1/82951_0s.jpg)
解析:安装 MySQL时如何选择安装软件包
2008-12-31 17:15:00
Python Decorator的设计模式演绎过程解析
2021-10-13 14:29:37
python函数的重新定义及练习
2023-10-12 22:47:55
![](https://img.aspxhome.com/file/2023/8/63528_0s.png)
Python&Matlab实现伏羲八卦图的绘制
2023-02-01 02:42:39
![](https://img.aspxhome.com/file/2023/5/121635_0s.gif)
Pycharm连接远程服务器过程图解
2023-07-25 04:37:53
![](https://img.aspxhome.com/file/2023/1/88991_0s.png)