2024-03-31
Android控制注意事项

长时间不开机的机器可能会发生时间错位问题 需要用adb进行时间校准

1
2
3
adb shell date "YYYY-MM-DD HH:MM:SS"
# sometimes you have to use '-s' flag

把所有闹钟都关闭 防止关了机又打开 或者在脚本操作控制的时候出问题


建议使用云手机平台(搜索:开源云手机),虚拟手机,方便进行环境打包和重新部署。

redroid supports adb connection, and is a docker image

redroid-doc and redroid tutorial

lamda is a multi-source (simulator and real device support) android controlling, network capturing and reverse engineering platform

lamda wiki


如果adb出现连接问题,可以重启adb服务

usb硬件出问题一般是因为供电不足,或者连接线接触不良。所以可以加强供电,以及更换更好的连接线。

1
2
3
adb kill-server
adb start-server

Read More

2023-12-01
Hide Magisk

You need to update to latest magisk by patching the unmodified kernel and install shizuku

enable whitelist mode

Read More

2022-10-15
Android Remote Control, App Automation

to change the resolution of android device run this command:

1
2
3
4
5
# <width>x<height>
adb shell wm size 3000x2000
# reset window size
adb shell wm size reset


launch scrcpy with HID simulation and screen off:

1
2
scrcpy -SK


run android in docker, run adb in docker

device discovery, termux daemon, remote unlock

unlock requires screenshot and input events.

https://technastic.com/unlock-android-phone-pin-pattern-adb/

click ok after input password:

https://stackoverflow.com/questions/29072501/how-to-unlock-android-phone-through-adb

scrcpy client

https://github.com/leng-yue/py-scrcpy-client

https://leng-yue.github.io/py-scrcpy-client/guide.html#bind-events

you want to use android emulator on macos m1?

https://github.com/google/android-emulator-m1-preview/releases/tag/0.3

check android screen lock/unlock state

https://android.stackexchange.com/questions/191086/adb-commands-to-get-screen-state-and-locked-state

Bonjour/Avahi/Zeroconf

logic: if the kill switch is off, when no physical input events happens, or not focused on scrcpy window with keyboard/mouse input events on pc for some time, allow to interact with the phone.

get physical events:

warning: this command could be offline for a short period of time after using the scrcpy. must automatically reconnect if the device is not offline.

1
2
adb -s 192.168.10.3:5555 shell getevent

to get focused window title:

hint: for headless ssh sessions, must set apropriate xorg environment variables, eg: env XAUTHORITY="/run/user/0/gdm/Xauthority" DISPLAY=:1 python3

general method:

1
2
3
import pywinctl
pywinctl.getActiveWindowTitle()

for linux:

1
2
watch -n 2 xdotool getactivewindow getwindowname

for macos: (allow permission first, deprecated since it will not get the window title instead of the program name)

https://alvinalexander.com/mac-os-x/applescript-unix-mac-osx-foreground-application-result/

(where is the window name?)

1
2
sleep 3 && osascript -e 'tell application "System Events"' -e 'set frontApp to name of first application process whose frontmost is true' -e 'end tell'

to get input events on macos:

download keylogger here:

https://hackernoon.com/writing-an-keylogger-for-macos-in-python-24adfa22722

https://github.com/beatsbears/pkl?ref=hackernoon.com

1
2
python pkl_nowriting.py

input events on linux:

1
2
xinput test-xi2 --root

Read More