如何在 python 中使用 adb 和子进程正确提取 apk

问题描述 投票:0回答:0

我正在尝试根据它落在选择菜单上的数字来获取 apk,但是当我使用 adb 和子进程在选择菜单上输入它的数字时,我似乎无法获得 apk 路径我打算使用 apktool 来反编译它完成后,这是我在选择菜单上输入数字时得到的结果。

/system/bin/sh: <stdin>[1]: 15: inaccessible or not found

我阅读了文档并在下面密切关注它这是我的代码我做错了什么? 我很想知道。

#  Create a select menu of all the available packages on the emulator and let the user choose one
output = subprocess.run(["adb", "-s", device_id, "shell", "pm", "list", "packages", "-3"], capture_output=True).stdout.decode("utf-8")
packages = output.strip().split("\n")
print("Available packages:")
for i, package in enumerate(packages):
    print(f"{i+1}: {package}")
package_index = int(input("Enter the number of the package to extract: ")) - 1
print(package_index)

# Print the path of the selected package and extract it to the local filesystem
package = packages[package_index]
print(package)
##print(packages)
package_name = package.split(":")[1]
print(package_name)
new_output = subprocess.run(["adb","-s", device_id, "shell", "pm grant", "path", package_name], capture_output=True).stdout.decode("utf-8")
package_path = new_output.strip().split(":")[1]
#print(output)
#print(package_path)

#print(f"Full path of {package_name}: {package_path}")
apk_type = input("Enter 1 to extract a single APK file, or 2 to extract a split APK: ")
if apk_type == "1":
    print("Hhhhh")
    #subprocess.run(["adb" ,"-s", device_id, "pull", package_path, f"{package_name}.apk"])
else:
    print("Working in progress......................................")
python android subprocess adb
© www.soinside.com 2019 - 2024. All rights reserved.