EZPPLauncher/electron/hwidUtil.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

const child_process = require("child_process");
const options = { encoding: "ascii", windowsHide: true, timeout: 200 };
const platforms = {
win32: [
"REG QUERY HKLM\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid",
/MachineGuid\s+REG_SZ\s+(.*?)\s/,
],
darwin: [
"ioreg -rd1 -c IOPlatformExpertDevice",
/"IOPlatformUUID" = "(.*?)"/,
],
linux: [
"cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || true",
/^([\da-f]+)/,
],
};
const crypto = require("crypto");
2024-07-21 12:58:59 +00:00
const defaultHWID = "recorderinthesandybridge";
/**
* Returns machine hardware id.
* Returns `undefined` if cannot determine.
2024-07-21 12:58:59 +00:00
* @return {Promise<string>}
*/
function getHwId() {
2024-07-21 12:58:59 +00:00
return new Promise((resolve) => {
2024-07-21 19:48:44 +00:00
try {
const getter = platforms[process.platform];
if (getter) {
const result = getter[1].exec(child_process.execSync(getter[0], options));
if (result) resolve(crypto.createHash("md5").update(result[1]).digest("hex"));
}
resolve(crypto.createHash("md5").update(defaultHWID).digest("hex"));
} catch {
resolve(crypto.createHash("md5").update(defaultHWID).digest("hex"));
2024-07-21 12:58:59 +00:00
}
})
}
exports.getHwId = getHwId;