mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-20 15:26:13 +08:00
Added PowerShell fallback for WSL
If WSLENV is not set (which, for my clean installation of Win10 with Debian, it was not), PATH is not populated with Windows' entries and is missing PowerShell executable, causing the COM port listing to fail. This commit adds a fallback with the default path if not found in PATH, and also replaces the wmic.exe check (which is no longer used) with a PSH check.
This commit is contained in:
parent
8a0bbe21d4
commit
5d7cdcf1d9
21
pm3
21
pm3
|
@ -156,7 +156,7 @@ function get_pm3_list_WSL {
|
|||
# Need to look for this first, the call to Win32_serialport "crashes" then native bt serial port. Don't ask why.
|
||||
#BT direct SERIAL PORTS (COM)
|
||||
if $FINDBTRFCOMM; then
|
||||
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | sed -nr 's#.*\bCOM([0-9]+)\b.*#/dev/ttyS\1#p'); do
|
||||
for DEV in $($PSHEXE -command "Get-CimInstance -ClassName Win32_PnPEntity | Where-Object Caption -like 'Standard Serial over Bluetooth link (COM*' | Select Name" 2> /dev/null | sed -nr 's#.*\bCOM([0-9]+)\b.*#/dev/ttyS\1#p'); do
|
||||
# ttyS counterpart takes some more time to appear
|
||||
if [ -e "$DEV" ]; then
|
||||
PM3LIST+=("$DEV")
|
||||
|
@ -173,7 +173,7 @@ function get_pm3_list_WSL {
|
|||
fi
|
||||
|
||||
# Normal SERIAL PORTS (COM)
|
||||
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
|
||||
for DEV in $($PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_9AC4&PID_4B8F*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
|
||||
# ttyS counterpart takes some more time to appear
|
||||
if [ -e "$DEV" ]; then
|
||||
PM3LIST+=("$DEV")
|
||||
|
@ -189,7 +189,7 @@ function get_pm3_list_WSL {
|
|||
|
||||
#white BT dongle SERIAL PORTS (COM)
|
||||
if $FINDBTDONGLE; then
|
||||
for DEV in $(powershell.exe -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
|
||||
for DEV in $($PSHEXE -command "Get-CimInstance -ClassName Win32_serialport | Where-Object PNPDeviceID -like '*VID_10C4&PID_EA60*' | Select DeviceID" 2>/dev/null | sed -nr 's#^COM([0-9]+)\b#/dev/ttyS\1#p'); do
|
||||
# ttyS counterpart takes some more time to appear
|
||||
if [ -e "$DEV" ]; then
|
||||
PM3LIST+=("$DEV")
|
||||
|
@ -389,11 +389,20 @@ fi
|
|||
HOSTOS=$(uname | awk '{print toupper($0)}')
|
||||
if [ "$HOSTOS" = "LINUX" ]; then
|
||||
if uname -a|grep -q Microsoft; then
|
||||
# Test presence of wmic
|
||||
if ! wmic.exe computersystem get name >/dev/null 2>&1; then
|
||||
echo >&2 "[!!] Cannot run wmic.exe, are you sure your WSL is authorized to run Windows processes? (cf WSL interop flag)"
|
||||
# First try finding it using the PATH environment variable
|
||||
PSHEXE=$(which powershell.exe 2>/dev/null)
|
||||
|
||||
# If it fails (such as if WSLENV is not set), try using the default installation path
|
||||
if [ -z "$PSHEXE" ]; then
|
||||
PSHEXE=/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
|
||||
fi
|
||||
|
||||
# Finally test if PowerShell is working
|
||||
if ! "$PSHEXE" exit >/dev/null 2>&1; then
|
||||
echo >&2 "[!!] Cannot run powershell.exe, are you sure your WSL is authorized to run Windows processes? (cf WSL interop flag)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GETPM3LIST=get_pm3_list_WSL
|
||||
else
|
||||
GETPM3LIST=get_pm3_list_Linux
|
||||
|
|
Loading…
Reference in a new issue