Skip to content

Instantly share code, notes, and snippets.

@JuniorJPDJ

JuniorJPDJ/wifi.sh

Last active Apr 10, 2020
Embed
What would you like to do?
Nexmon firmware replacing on-demand
#!/system/bin/sh
# place me in this folder:
export HOME="/sdcard/wifi"
# place patched firmware with this name
patched_path="$HOME/bcmdhd_sta.bin.patched"
backup_path="$HOME/bcmdhd_sta.bin.backup"
fw_path="/system/etc/wifi/bcmdhd_sta.bin"
[[ "$UID" -eq 0 ]] || {
echo "This script must be run as root"
exit 1
}
cd
wifi=$(settings get global wifi_on)
if [ $wifi -eq 1 ]; then
svc wifi disable
echo "Android WiFi turned off"
fi
mount -o rw,remount /system
cp "$fw_path" "$backup_path"
cp "$patched_path" "$fw_path"
chmod 644 "$fw_path"
mount -o ro,remount /system
echo "Firmware patch loaded"
ip link set wlan0 down
ip link set wlan0 up
echo "WiFi interface set to UP state"
nexutil -d
nexutil -m2
echo "Monitor mode enabled"
echo "Entering interactive shell"
export LD_PRELOAD="/data/local/tmp/libfakeioctl.so"
export HISTFILE="$HOME/.bash_history"
export USER="$(id -un)"
export HOSTNAME="$(getprop ro.cm.device)"
export PS1='\[\033[01;31m\]root\[\033[00m\]@\[\033[01;32m\]${HOSTNAME:=$(hostname)}\[\033[01;34m\] \[\033[01;37m\]\w \[\033[00m\]\$ '
export PATH="$PATH:/data/local/wifi-toolkit/"
export TERM=xterm
export TMPDIR="/data/local/tmp"
bash --norc -O checkwinsize -O histappend -i
unset HISTFILE
unset LD_PRELOAD
echo "Restoring firmware backup"
mount -o rw,remount /system
cp "$backup_path" "$fw_path"
chmod 644 "$fw_path"
mount -o ro,remount /system
rm "$backup_path"
echo "Setting WiFi interface to DOWN state"
ip link set wlan0 down
if [ $wifi -eq 1 ]; then
echo "Turning Android WiFi on"
svc wifi enable
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment