【问题标题】:Using sendevent in python to usb connected phone slow due to su access由于 su 访问,在 python 中使用 sendevent 到 USB 连接的手机速度很慢
【发布时间】:2020-09-16 15:32:43
【问题描述】:

使用 python ppdb 自动点击。输入点击工作正常但速度很慢,所以我将我的设备(android 10,像素 2)植根以使用 sendevent /dev/input/event#。我使用 adb shell getevent 来监听触摸并找出我的设备的特定值(event2,以及用于点击、坐标输入、提升和发送它们的 0 0 0 的命令)

import utils as u, random, time, sys, os

driver= u.Driver(id)

sendCmd = "su +c sendevent /dev/input/event2 "
driver.device.shell(sendCmd + "3 57 374")
driver.device.shell(sendCmd + "3 54 970")
driver.device.shell(sendCmd + "3 53 900")
driver.device.shell(sendCmd + "0 0 0")
driver.device.shell(sendCmd + "3 57 -1")
driver.device.shell(sendCmd + "0 0 0")

它有效,但也相当慢。从我一直在阅读的内容来看,这可能是由于 su 每次都打开一个新的 shell 实例。我试图自己发送“su”,但它总是挂起。 (我已经尝试过 \n 和 ~ 作为线路关闭器)。 当我通过 cmd 手动发送代码时,“adb shell su”会挂起,但如果我键入 enter 并粘贴 sendevent 命令。我可以将点击发送到手机。另外,如果我在 cmd 中尝试“adb shell”,然后在下一行输入“su”,它会从 walleye:/$ 变为 walleye:/#,我也可以将 sendevents 粘贴在那里。 (如果我一次粘贴多个,这些点击会非常快)

我的下一个尝试是进入 ppadb 并查看套接字是如何处理的,但这有点超出我的想象。我玩了一下,但我无法通过单个“su”发送多个命令。我也尝试在 ppdb.devices 中使用 root 函数,但得到“RuntimeError: adbd cannot run as root in production builds”。

我看到的另一种可能性是重写 sendevent.c 文件,如这里的答案:Android sendevent is really slow - how to speed it up?

在这一点上,由于我不确定是什么导致 sendevent 变慢,所以我不确定如何进行。

编辑:我能够使用 MagiskHide Props Config 更改属性值 ro.adb.secure=0 、 ro.secure =0 和 ro.debuggable = 1。我仍然得到“adbd 无法在生产中以 root 身份运行构建”。 getprop ro.build.type 返回“用户”。

https://github.com/pcboy/adb-insecure-patcher 看起来很有希望,但我不确定如何使用它。

Edit2:在 adb-insecure-patcher 中打开 .sh,看起来它与我对 MagiskHide Props 所做的事情相同。目前正在研究如何重写 sendevent.c

【问题讨论】:

标签: python android shell adb su


【解决方案1】:

您无需执行任何操作。只需使用子流程:

import subprocess

#now you can send any adb command to device using:
subprocess.call("adb shell input tap 2300 1220", shell = True)
subprocess.call("adb shell input swipe 3847 1223 2341 1232", shell = True)
subprocess.call("adb shell monkey -p com.instagram.android -c android.intent.category.LAUNCHER 1",shell = True)

你明白了。 基本上以格式发送任何命令 subprocess.call("adb shell <your command here>", shell = True)

另外,我想子进程已经预先安装,但如果不是在你的命令行中输入pip install subprocess。你应该很高兴。

【讨论】:

    最近更新 更多