1#[cfg(target_os = "windows")]
2mod hwid {
3 use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};
4
5 pub fn get_hwid() -> std::io::Result<String> {
6 let key = RegKey::predef(HKEY_LOCAL_MACHINE)
7 .open_subkey("SOFTWARE\\Microsoft\\Cryptography")?;
8
9 key.get_value::<String, _>("MachineGuid")
10 }
11}
12
13#[cfg(target_os = "linux")]
14mod hwid {
15 pub fn get_hwid() -> std::io::Result<String> {
16 Ok(std::fs::read_to_string("/etc/machine-id")?.trim_end_matches("\n").to_string())
17 }
18}
19
20#[cfg(not(any(target_os = "windows", target_os = "linux")))]
21pub fn get_hwid() -> std::io::Result<String> {
22 Err(std::io::Error::new(
23 std::io::ErrorKind::Other,
24 "get_hwid is only supported on Windows",
25 ))
26}
27
28pub fn get_hwid() -> std::io::Result<String> {
41 hwid::get_hwid()
42}