mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-11-10 17:49:32 +08:00
125 lines
3.5 KiB
Bash
Executable file
125 lines
3.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
PM3PATH=$(dirname "$0")
|
|
# try pm3 dirs in current repo workdir
|
|
if [ -d "$PM3PATH/client/" ]; then
|
|
CLIENT="$PM3PATH/client/proxmark3"
|
|
FULLIMAGE="$PM3PATH/armsrc/obj/fullimage.elf"
|
|
BOOTIMAGE="$PM3PATH/bootrom/obj/bootrom.elf"
|
|
# try install dir
|
|
elif [ -x "$PM3PATH/proxmark3" ]; then
|
|
CLIENT="$PM3PATH/proxmark3"
|
|
FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf"
|
|
BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf"
|
|
else
|
|
# hope it's installed somehow, still not sure where fw images are...
|
|
CLIENT="proxmark3"
|
|
FULLIMAGE="$PM3PATH/../share/proxmark3/firmware/fullimage.elf"
|
|
BOOTIMAGE="$PM3PATH/../share/proxmark3/firmware/bootrom.elf"
|
|
fi
|
|
|
|
function wait4proxmark_Linux {
|
|
echo >&2 "[=] Waiting for Proxmark3 to appear..."
|
|
while true; do
|
|
PM3=$(find /dev/pm3-* /dev/ttyACM* 2>/dev/null | head -1)
|
|
if [[ $PM3 != "" ]]; then
|
|
break
|
|
fi
|
|
sleep .1
|
|
done
|
|
echo "$PM3"
|
|
}
|
|
|
|
function wait4proxmark_macOS {
|
|
echo >&2 "[=] Waiting for Proxmark3 to appear..."
|
|
while true; do
|
|
PM3=$(find /dev/pm3-* /dev/tty.usbmodem* 2>/dev/null | head -1)
|
|
if [[ $PM3 != "" ]]; then
|
|
break
|
|
fi
|
|
sleep .1
|
|
done
|
|
echo "$PM3"
|
|
}
|
|
|
|
function wait4proxmark_Windows {
|
|
echo >&2 "[=] Waiting for Proxmark3 to appear..."
|
|
while true; do
|
|
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
|
|
echo "$PM3"
|
|
}
|
|
|
|
function wait4proxmark_WSL {
|
|
echo >&2 "[=] Waiting for Proxmark3 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
|
|
if [ -e "$PM3" ] && [ ! -w "$PM3" ]; then
|
|
echo "[!!] We need to give current user read/write access to $PM3"
|
|
sudo chmod 666 "$PM3"
|
|
fi
|
|
echo "$PM3"
|
|
}
|
|
|
|
SCRIPT=$(basename -- "$0")
|
|
|
|
if [ "$SCRIPT" = "pm3" ]; then
|
|
CMD() { $CLIENT "$@"; }
|
|
elif [ "$SCRIPT" = "pm3-flash" ]; then
|
|
CMD() {
|
|
ARGS=("$1" "--flash")
|
|
shift;
|
|
while [ "$1" != "" ]; do
|
|
if [ "$1" == "-b" ]; then
|
|
ARGS+=("--unlock-bootloader")
|
|
else
|
|
ARGS+=("--image" "$1")
|
|
fi
|
|
shift;
|
|
done
|
|
$CLIENT ${ARGS[@]};
|
|
}
|
|
elif [ "$SCRIPT" = "pm3-flash-all" ]; then
|
|
CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE" "--image" "$FULLIMAGE"; }
|
|
elif [ "$SCRIPT" = "pm3-flash-fullimage" ]; then
|
|
CMD() { $CLIENT "$1" "--flash" "--image" "$FULLIMAGE"; }
|
|
elif [ "$SCRIPT" = "pm3-flash-bootrom" ]; then
|
|
CMD() { $CLIENT "$1" "--flash" "--unlock-bootloader" "--image" "$BOOTIMAGE"; }
|
|
else
|
|
echo "[!!] Script ran under unknown name, abort: $SCRIPT"
|
|
exit 1
|
|
fi
|
|
HOSTOS=$(uname | awk '{print toupper($0)}')
|
|
if [ "$HOSTOS" = "LINUX" ]; then
|
|
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
|
|
|
|
CMD "$PORT" "$@"
|
|
exit $?
|