proxmark3/proxmark3.sh

100 lines
2.6 KiB
Bash
Raw Normal View History

#!/bin/bash
FULLIMAGE="armsrc/obj/fullimage.elf"
BOOTIMAGE="bootrom/obj/bootrom.elf"
2019-07-15 00:20:41 +08:00
PM3PATH=$(dirname "$0")
cd "$PM3PATH" || exit 1
2018-08-17 00:31:12 +08:00
function wait4proxmark_Linux {
2019-03-09 18:10:22 +08:00
echo >&2 "Waiting for Proxmark to appear..."
2019-07-15 00:20:41 +08:00
while true; do
PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1)
if [[ $PM3 != "" ]]; then
break
fi
2019-03-09 18:10:22 +08:00
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
function wait4proxmark_macOS {
2019-03-09 18:10:22 +08:00
echo >&2 "Waiting for Proxmark to appear..."
while true; do
2019-07-15 00:20:41 +08:00
PM3=$(find /dev/pm3-* /dev/cu.usbmodem* 2>/dev/null | head -1)
2019-03-09 18:10:22 +08:00
if [[ $PM3 != "" ]]; then
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
function wait4proxmark_Windows {
echo >&2 "Waiting for Proxmark to appear..."
while true; do
2019-07-06 21:31:32 +08:00
device=$(wmic path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2')
if [[ $device != "" ]]; then
PM3=${device/ */}
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
echo "$PM3"
}
2019-07-13 06:06:19 +08:00
function wait4proxmark_WSL {
echo >&2 "Waiting for Proxmark to appear..."
while true; do
device=$(wmic.exe path Win32_SerialPort where "PNPDeviceID like '%VID_9AC4&PID_4B8F%'" get DeviceID,PNPDeviceID 2>/dev/null | awk 'NR==2')
if [[ $device != "" ]]; then
PM3=${device/ */}
PM3="/dev/ttyS${PM3#COM}"
break
fi
sleep .1
done
2019-07-15 00:20:41 +08:00
if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then
echo "We need to give current user read/write access to $PM3"
sudo chmod 666 "$PM3"
fi
2019-07-15 00:20:41 +08:00
echo "$PM3"
2019-07-13 06:06:19 +08:00
}
SCRIPT=$(basename -- "$0")
if [ "$SCRIPT" = "proxmark3.sh" ]; then
2019-07-15 00:20:41 +08:00
CMD() { client/proxmark3 "$@"; }
elif [ "$SCRIPT" = "flash-all.sh" ]; then
2019-07-15 00:20:41 +08:00
CMD() { client/flasher "$1" -b "$BOOTIMAGE" "$FULLIMAGE"; }
2019-07-15 04:13:40 +08:00
elif [ "$SCRIPT" = "flash-fullimage.sh" ]; then
2019-07-15 00:20:41 +08:00
CMD() { client/flasher "$1" "$FULLIMAGE"; }
elif [ "$SCRIPT" = "flash-bootrom.sh" ]; then
2019-07-15 00:20:41 +08:00
CMD() { client/flasher "$1" -b "$BOOTIMAGE"; }
else
echo "Script ran under unknown name, abort: $SCRIPT"
exit 1
fi
HOSTOS=$(uname | awk '{print toupper($0)}')
if [ "$HOSTOS" = "LINUX" ]; then
2019-07-13 06:06:19 +08:00
if uname -a|grep -q Microsoft; then
PORT=$(wait4proxmark_WSL)
else
PORT=$(wait4proxmark_Linux)
fi
elif [ "$HOSTOS" = "DARWIN" ]; then
PORT=$(wait4proxmark_macOS)
elif [[ "$HOSTOS" =~ MINGW(32|64)_NT* ]]; then
PORT=$(wait4proxmark_Windows)
else
echo "Host OS not recognized, abort: $HOSTOS"
exit 1
fi
if [ "$PORT" = "" ]; then
echo "No port, abort"
exit 1
fi
2019-07-15 00:20:41 +08:00
CMD "$PORT" "$@"
exit $?