Print the OEM Windows product key from firmware (#7480)
* Print the OEM Windows product key from firmware Machines that shipped with Windows keep the OEM key in the ACPI MSDM table. `omarchy windows license key` reads it with strings, then cat. * Rename the firmware key command to omarchy-windows-key
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# omarchy:summary=Print the OEM Windows product key stored in firmware
|
||||||
|
# omarchy:requires-sudo=true
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
MSDM=${OMARCHY_MSDM_PATH:-/sys/firmware/acpi/tables/MSDM}
|
||||||
|
|
||||||
|
if [[ ! -e $MSDM ]]; then
|
||||||
|
echo "No Windows license key found in firmware." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read_msdm() {
|
||||||
|
if [[ -r $MSDM ]]; then
|
||||||
|
"$@" "$MSDM"
|
||||||
|
else
|
||||||
|
sudo "$@" "$MSDM"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
extract_key() {
|
||||||
|
grep -aoEm1 '[A-Z0-9]{5}(-[A-Z0-9]{5}){4}'
|
||||||
|
}
|
||||||
|
|
||||||
|
key=""
|
||||||
|
if omarchy-cmd-present strings; then
|
||||||
|
key=$(read_msdm strings | extract_key) || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $key ]]; then
|
||||||
|
key=$(read_msdm cat | extract_key) || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z $key ]]; then
|
||||||
|
echo "Firmware license table found, but no Windows product key could be extracted." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s\n' "$key"
|
||||||
@@ -36,6 +36,8 @@ There's no GPU passthrough with this setup, so it's not suitable for gaming or v
|
|||||||
|
|
||||||
The version installed is Windows 11 Pro, unactivated. You'll need your own license key to use the gated features.
|
The version installed is Windows 11 Pro, unactivated. You'll need your own license key to use the gated features.
|
||||||
|
|
||||||
|
If this computer shipped with Windows, the OEM key is still in firmware even after installing Omarchy. Print it with `omarchy windows key`. That key is bound to this machine — it will activate Windows reinstalled on this hardware, but it usually will not activate the VM.
|
||||||
|
|
||||||
You can change the resource allocation later by editing `~/.config/windows/docker-compose.yml`, which is also where you'd mount a USB device. See all the options on [the Dockur Windows project](https://github.com/dockur/windows).
|
You can change the resource allocation later by editing `~/.config/windows/docker-compose.yml`, which is also where you'd mount a USB device. See all the options on [the Dockur Windows project](https://github.com/dockur/windows).
|
||||||
|
|
||||||
To get rid of the whole thing, use _Remove > Windows_ from the Omarchy menu. That deletes the VM's disk and all its data, so make sure anything you care about is out of `~/Windows` first.
|
To get rid of the whole thing, use _Remove > Windows_ from the Omarchy menu. That deletes the VM's disk and all its data, so make sure anything you care about is out of `~/Windows` first.
|
||||||
|
|||||||
Executable
+65
@@ -0,0 +1,65 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||||
|
|
||||||
|
command="$ROOT/bin/omarchy-windows-key"
|
||||||
|
tmp=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
|
||||||
|
rg -q '/sys/firmware/acpi/tables/MSDM' "$command" ||
|
||||||
|
fail "windows key helper reads the ACPI MSDM table"
|
||||||
|
pass "windows key helper reads the ACPI MSDM table"
|
||||||
|
|
||||||
|
rg -q 'read_msdm strings' "$command" ||
|
||||||
|
fail "windows key helper tries strings first"
|
||||||
|
pass "windows key helper tries strings first"
|
||||||
|
|
||||||
|
rg -q 'read_msdm cat' "$command" ||
|
||||||
|
fail "windows key helper falls back to cat"
|
||||||
|
pass "windows key helper falls back to cat"
|
||||||
|
|
||||||
|
write_msdm() {
|
||||||
|
local path=$1
|
||||||
|
local payload=$2
|
||||||
|
|
||||||
|
python3 -c 'import pathlib, sys
|
||||||
|
pathlib.Path(sys.argv[1]).write_bytes(b"MSDM" + b"\x00" * 52 + sys.argv[2].encode())
|
||||||
|
' "$path" "$payload"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_helper() {
|
||||||
|
OMARCHY_MSDM_PATH=$1 PATH="$ROOT/bin:$PATH" "$command"
|
||||||
|
}
|
||||||
|
|
||||||
|
key="XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
|
||||||
|
write_msdm "$tmp/msdm" "$key"
|
||||||
|
output=$(run_helper "$tmp/msdm")
|
||||||
|
[[ $output == "$key" ]] || fail "windows key helper prints the firmware key" "actual: $output"
|
||||||
|
pass "windows key helper prints the firmware key"
|
||||||
|
|
||||||
|
mkdir -p "$tmp/bin"
|
||||||
|
cat >"$tmp/bin/strings" <<'EOF'
|
||||||
|
#!/bin/bash
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
chmod +x "$tmp/bin/strings"
|
||||||
|
output=$(PATH="$tmp/bin:$ROOT/bin:$PATH" OMARCHY_MSDM_PATH="$tmp/msdm" "$command")
|
||||||
|
[[ $output == "$key" ]] || fail "windows key helper falls back to cat when strings finds nothing" "actual: $output"
|
||||||
|
pass "windows key helper falls back to cat when strings finds nothing"
|
||||||
|
|
||||||
|
write_msdm "$tmp/empty" "no-product-key-here"
|
||||||
|
if OMARCHY_MSDM_PATH="$tmp/empty" PATH="$ROOT/bin:$PATH" "$command" >"$tmp/out" 2>"$tmp/err"; then
|
||||||
|
fail "windows key helper fails when the table has no key"
|
||||||
|
fi
|
||||||
|
[[ $(<"$tmp/err") == "Firmware license table found, but no Windows product key could be extracted." ]] ||
|
||||||
|
fail "windows key helper reports a missing key" "actual: $(<"$tmp/err")"
|
||||||
|
pass "windows key helper reports a missing key"
|
||||||
|
|
||||||
|
if OMARCHY_MSDM_PATH="$tmp/missing" PATH="$ROOT/bin:$PATH" "$command" >"$tmp/out" 2>"$tmp/err"; then
|
||||||
|
fail "windows key helper fails when firmware has no MSDM table"
|
||||||
|
fi
|
||||||
|
[[ $(<"$tmp/err") == "No Windows license key found in firmware." ]] ||
|
||||||
|
fail "windows key helper reports missing firmware table" "actual: $(<"$tmp/err")"
|
||||||
|
pass "windows key helper reports missing firmware table"
|
||||||
Reference in New Issue
Block a user