使用python编写脚本获取手机当前应用apk的信息
前提是已设置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")
相关推荐
yangChong 2020-08-03
zyygive 2020-07-29
yangChong 2020-07-29
绿豆饼 2020-07-28
adb shell cd system/app rm *.apk21. 获取管理员权限: adb root22. 启动Activity: adb shell am start -n 包名/包名+类名。
蓝天梦 2020-07-28
rookieding 2020-07-26
zyygive 2020-06-11
zyygive 2020-06-09
安辉 2020-05-27
KarlMarxs 2020-05-15
xilove0 2020-04-20
laijunfeng 2020-04-07
KarlMarxs 2020-02-23
Soinice 2020-02-18
zyygive 2020-02-17
ProgrammerFan00 2020-02-16
Ubuntu黑客 2020-02-14
89590098 2020-02-01