Skip to content

Instantly share code, notes, and snippets.

@pastewka
Last active September 20, 2021 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pastewka/12681a63688e83a7942510482aba6e7f to your computer and use it in GitHub Desktop.
Save pastewka/12681a63688e83a7942510482aba6e7f to your computer and use it in GitHub Desktop.
Automatically import bluetooth keys from Windows to Linux
#! /bin/bash
WINDOWS_ROOT=$1
cd $WINDOWS_ROOT/Windows/System32/config
# Get MAC address of Bluetooth module
for mac in /var/lib/bluetooth/??:??:??:??:??:??; do
btmacwin=$(basename ${mac} | sed 's/://g' | awk '{print tolower($0)}')
btdir=${mac}
done
# Get MAC addresses of registered Bluetooth devices
for device in ${btdir}/??:??:??:??:??:??; do
devicewin=$(basename ${device} | sed 's/://g' | awk '{print tolower($0)}')
chntpw -e SYSTEM <<EOF | grep ':00000' > keywin.tmp
cd ControlSet001\\Services\\BTHPORT\\Parameters\\Keys\\${btmacwin}
hex ${devicewin}
q
EOF
keywin=$(cat keywin.tmp)
key=$(echo ${keywin:8:47} | sed 's/ //g')
if [[ -n "$key" ]]; then
echo $key
cat $device/info | sed -E "s/Key=[A-Z0-9]+$/Key=${key}/" > $device/new_info
mv $device/new_info $device/info
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment