Created
July 19, 2022 04:42
-
-
Save pwnwriter/8e7c414a079a6e1d19dda8623baecac3 to your computer and use it in GitHub Desktop.
script to automate wireless debugginggg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Enable wireless debugging and connect using adb. | |
command -v adb su >/dev/null || exit 1 | |
# Variables | |
_SUDO="su -c" | |
_ADB="adb" | |
# Functions | |
adb_wifi_enabled () { $_SUDO "settings put global adb_wifi_enabled $1" ;} | |
get_latest_port () { $_SUDO logcat -d --format=raw | grep 'adb wifi started on port' | tail -n 1 | cut -d' ' -f6 ; } | |
# Restart adb_wifi and get the port from logcat | |
OLD_ADB_PORT="$(get_latest_port)" | |
adb_wifi_enabled 0 ; adb_wifi_enabled 1 | |
i=0 ; while true ; do | |
ADB_PORT="$(get_latest_port)" | |
[[ "${ADB_PORT}" != "${OLD_ADB_PORT}" ]] && [[ "${#ADB_PORT}" > 0 ]] && break | |
((i++)) | |
[[ $i == 10 ]] && exit 1 | |
sleep 2 | |
done | |
# Connect to adb | |
ADB_IP="127.0.0.1:${ADB_PORT}" | |
$_ADB connect "$ADB_IP" &>/dev/null% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment