feat: add simplified windows x86 support

This commit is contained in:
yankun
2026-06-27 18:33:59 +08:00
parent 7de0777748
commit 67c995db83
12 changed files with 400 additions and 84 deletions
+57 -1
View File
@@ -4,6 +4,8 @@ const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const { execSync } = require('child_process');
const os = require('os');
const { getPersistentFile } = require('./platform-paths');
/**
* 生成硬件唯一指纹作为 box_id。
@@ -19,7 +21,59 @@ const { execSync } = require('child_process');
* 有线 MAC 适用于嵌入式设备(网卡焊在主板,由固件烧录,不会更换)。
*/
const PERSIST_FILE = '/etc/clawd/.box_id';
const PERSIST_FILE = getPersistentFile('.box_id');
function readCommand(cmd, opts = {}) {
try {
return execSync(cmd, {
timeout: opts.timeout || 5000,
encoding: 'utf8',
windowsHide: true,
stdio: ['ignore', 'pipe', 'ignore'],
}).trim();
} catch (_) {
return null;
}
}
function getWindowsMachineGuid() {
const out = readCommand('reg query "HKLM\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid');
const m = out && out.match(/MachineGuid\s+REG_SZ\s+([^\r\n]+)/i);
return m ? m[1].trim().toLowerCase() : null;
}
function getWindowsBiosUuid() {
const ps = 'powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "(Get-CimInstance Win32_ComputerSystemProduct).UUID"';
const uuid = readCommand(ps);
if (!uuid) return null;
const clean = uuid.trim().toLowerCase();
if (clean === '00000000-0000-0000-0000-000000000000') return null;
if (clean === 'ffffffff-ffff-ffff-ffff-ffffffffffff') return null;
return clean.replace(/-/g, '');
}
function getWindowsMac() {
const ifaces = os.networkInterfaces();
const macs = [];
for (const addrs of Object.values(ifaces)) {
for (const addr of addrs || []) {
const mac = String(addr.mac || '').replace(/:/g, '').toLowerCase();
if (mac && mac.length === 12 && mac !== '000000000000') macs.push(mac);
}
}
return macs.sort()[0] || null;
}
function getWindowsBoxId() {
const machineGuid = getWindowsMachineGuid();
const biosUuid = getWindowsBiosUuid();
const mac = getWindowsMac();
if (machineGuid || biosUuid || mac) {
const raw = [machineGuid || '', biosUuid || '', mac || ''].join(':');
return crypto.createHash('sha256').update(raw).digest('hex').slice(0, 32);
}
return getPersistentUUID();
}
// ── 1. /etc/machine-id ───────────────────────────────────────────────────────
function getMachineId() {
@@ -119,6 +173,8 @@ function getPersistentUUID() {
// ── 主函数 ────────────────────────────────────────────────────────────────────
function getBoxId() {
if (process.platform === 'win32') return getWindowsBoxId();
const machineId = getMachineId();
const cpuSerial = getCpuSerial();
const ethMac = getEthMac();