Last active
September 20, 2021 15:56
-
-
Save pastewka/12681a63688e83a7942510482aba6e7f to your computer and use it in GitHub Desktop.
Automatically import bluetooth keys from Windows to Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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