Android Apk installation package export artifact exe gadget sharing, use the adb command to export the current foreground application with one click

Download address: https://github.com/miqt/PythonLearn/tree/master/apkdump/dist

Download and use, no need to configure any environment, I have compiled it into an exe executable file.

How to use the gadget to export apk from the mobile phone using the adb command:

  1. Open the target application on the mobile phone
  2. Double-click the exe file and wait for the export

Realize the source code:

import os
import re


def run_silently(cmd: str) -> str:
    """返回系统命令的执行结果"""
    with os.popen(cmd) as fp:
        bf = fp._stream.buffer.read()
    try:
        return bf.decode().strip()
    except UnicodeDecodeError:
        return bf.decode('gbk').strip()


print('APK DUMP TOOL START!')
print('https://github.com/miqt')

res = run_silently("adb shell dumpsys activity top")
# (ACTIVITY\s)(.*?)(/)(.*?)(\s.*?pid=)([0-9]+)
activitys = re.findall(r'(ACTIVITY\s)(.*?)(/)(.*?)(\s.*?pid=)([0-9]+)', res, 0)
print('---------------------CURRENT_TASK--------------------------')
for item in activitys:
    package = item[1]
    activity = item[3]
    pid = item[5]
    print(package, activity, pid)
print('-----------------------------------------------------------')
toppackage = activitys[activitys.count(activitys) - 1][1]
print('TOP TASK -->', toppackage)
res = run_silently("adb shell pm path " + toppackage)[8:]
print("PATH =", res)
print('-----------------------------------------------------------')
res = run_silently("adb pull " + res + " ./" + toppackage + ".apk")
print(res)
print('-----------------------------------------------------------')
print("DUMP SUCCESS")
os.system('pause')

Guess you like

Origin blog.csdn.net/qq_27512671/article/details/120068155