"use strict";
exports.id = "node_modules_telerik_machine-id_index_mjs";
exports.ids = ["node_modules_telerik_machine-id_index_mjs"];
exports.modules = {

/***/ "../node_modules/@telerik/machine-id/index.mjs":
/*!*****************************************************!*\
  !*** ../node_modules/@telerik/machine-id/index.mjs ***!
  \*****************************************************/
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */   loadMachineId: () => (/* binding */ loadMachineId)
/* harmony export */ });
/* harmony import */ var child_process__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! child_process */ "child_process");
/* harmony import */ var readline__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! readline */ "readline");
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! crypto */ "crypto");
/* harmony import */ var util__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! util */ "util");
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! fs */ "fs");






const exec = util__WEBPACK_IMPORTED_MODULE_3__.promisify(child_process__WEBPACK_IMPORTED_MODULE_0__.exec);
const readFile = fs__WEBPACK_IMPORTED_MODULE_4__.promises.readFile;

async function loadMachineIdWindows() {

    async function runInPowershell(command) {
        let output = "";

        const child = (0,child_process__WEBPACK_IMPORTED_MODULE_0__.spawn)("powershell.exe", ["-nologo"]);
        child.stdin.write(command + "\n");
        child.stdin.end();

        const shellInterface = readline__WEBPACK_IMPORTED_MODULE_1__.createInterface(child.stdout);

        for await(const line of shellInterface) {
            // if (!line) continue;
            if (line.startsWith("PS ")) continue;

            output = output == "" ? line : (output + "\n" + line);
        }

        const wmiObjects = output.trim().split("\n\n").map(a => {
            const wmiPropertyLines = a.split("\n");

            const properties = {
                fingerprint: ""
            };

            for (const line of wmiPropertyLines) {
                const separatorIndex = line.indexOf(" : ");
                if (separatorIndex == -1) continue;

                const value = line.length < separatorIndex + 3 ? "" : line.substring(separatorIndex + 3);

                if (value) {
                    properties.fingerprint += value + ";";
                    properties[line.substring(0, separatorIndex).trim()] = value;
                }
            }

            return properties;
        });

        return wmiObjects;
    }

    const bios = await runInPowershell("Get-WmiObject Win32_BIOS | Format-List -Property Manufacturer, SerialNumber, Name");
    const hdds = await runInPowershell("Get-WmiObject Win32_DiskDrive | Format-List -Property SerialNumber, Model, InterfaceType");
    const processors = await runInPowershell("Get-WmiObject Win32_Processor | Format-List -Property UniqueId, ProcessorId, Name, Manufacturer");

    // console.log("=== bios: ===\n" + JSON.stringify(bios, null, "  "));
    // console.log("=== hdds: ===\n" + JSON.stringify(hdds, null, "  "));
    // console.log("=== processors: ===\n" + JSON.stringify(processors, null, "  "));

    let machineFingerprint = [
        ...bios,
        // TRICKY: Filter USB hard disks, although my personal HDD is detected as SCSI when connected over USB.
        ...hdds.filter(f => f.InterfaceType != "USB"),
        ...processors
    ].map(m => m.fingerprint).join("");

    var shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha1');
    shasum.update(machineFingerprint);
    const machineId = shasum.digest("base64");

    return {
        fingerprint: machineFingerprint,
        id: machineId,
        algorithm: "SHA1"
    };
}

async function loadMachineIdDarwin() {

    const platfromResult = (await exec("ioreg -rd1 -w0 -c IOPlatformExpertDevice"))?.stdout?.toString();
    const { platformUUID } = platfromResult.match(/"IOPlatformUUID"\s=\s"(?<platformUUID>[0-9A-F\-]*)"/).groups;
    const { platformSN } = platfromResult.match(/"IOPlatformSerialNumber"\s=\s"(?<platformSN>[^"]*)"/).groups;
    
    const modelResult = (await exec("sysctl hw.model machdep.cpu.brand_string"))?.stdout?.toString();
    const { hardwareModel } = modelResult.match(/^hw.model:\s(?<hardwareModel>.*)$/m).groups;
    const { cpuBrand } = modelResult.match(/^machdep.cpu.brand_string:\s(?<cpuBrand>.*)$/m).groups;

    // Disk drives...
    let hdds = "";

    const ahciDDriveResult = (await exec("ioreg -rd1 -w0 -c AppleAHCIDiskDriver"))?.stdout?.toString();
    for (const ahciDevice of propertyGroups(ahciDDriveResult)) {
        try {
            const ahciName = ahciDevice.match(/^\s*"(Model|Model Name|Model Number)"\s*=\s*"(?<ahciName>[^"]*)"\s*$/m).groups.ahciName.trim();
            const ahciSN = ahciDevice.match(/^\s*"Serial Number"\s*=\s*"(?<ahciSN>[^"]*)"\s*$/m).groups.ahciSN.trim();
            hdds += `\nDisk Drive, AppleAHCIDiskDriver: ${ahciName} (${ahciSN})`;
        } catch {
        }
    }

    const ans2ControlerResult = (await exec("ioreg -rd1 -w0 -c AppleANS2Controller")).stdout?.toString();
    for (const ans2Controller of propertyGroups(ans2ControlerResult)) {
        try {
            const ans2Name = ans2Controller.match(/^\s*"(Model|Model Name|Model Number)"\s*=\s*"(?<ans2Name>[^"]*)"\s*$/m).groups.ans2Name.trim();
            const ans2SN = ans2Controller.match(/^\s*"Serial Number"\s*=\s*"(?<ans2SN>[^"]*)"\s*$/m).groups.ans2SN.trim();
            hdds += `\nDisk Drive, AppleANS2Controller: ${ans2Name} (${ans2SN})`;
        } catch {
        }
    }

    const machineFingerprint =
        `Platform UUID: ${platformUUID}\n` +
        `Platform S/N: ${platformSN}\n` + 
        `Hardware model: ${hardwareModel}\n` + 
        `CPU brand: ${cpuBrand}` + hdds;
    
    var shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha256');
    shasum.update(machineFingerprint);
    const machineId = shasum.digest("base64");

    return {
        fingerprint: machineFingerprint,
        id: machineId,
        algorithm: "SHA256"
    };
    
    /**
     * Each HDD is returned in a JSON-like structure:
     * ```
     * {
     *   "prop1" = "value1"
     *   "prop2" = "value2"
     * }
     * ```
     * This method is used to split the result into chunks of HDDs
     */
    function propertyGroups(str) {
        const groups = [];

        const startRegex = /(?<=\n[\t ]*){/g;
        const endRegex = /\n[\t ]*}/g;
    
        let start = 0;
        let end = 0;
        do {
            startRegex.lastIndex = start;
            start = startRegex.exec(ahciDDriveResult)?.index;
            if (start == undefined) break;
            endRegex.lastIndex = start;
            if (endRegex.exec(ahciDDriveResult)?.index == undefined) break;
            end = endRegex.lastIndex;
            console.log(`Found range: ${start} - ${end}`);
            groups.push(str.substring(start, end));
            start = end;
        } while(true);

        return groups;
    }
}

async function loadMachineIdLinux() {
    let linuxMachineId = "";

    try {
        linuxMachineId = (await readFile("/etc/machine-id"))?.toString()?.trim() || "";
    } catch {
    }

    try {
        linuxMachineId = linuxMachineId || (await readFile("/var/lib/dbus/machine-id"))?.toString()?.trim() || "";
    } catch {
    }

    let cpuModel = undefined;
    let cpuMHz = undefined;

    try {
        const cpuInfo = (await readFile("/proc/cpuinfo")).toString();

        try {
            for(const match of cpuInfo.matchAll(/^\s*model name\s*:\s*(?<cpuModel>.*)$/gm)) {
                cpuModel = match?.groups?.cpuModel;
            }
        } catch {}

        try {
            for (const match of cpuInfo.matchAll(/^\s*cpu MHz\s*:\s*(?<cpuMHz>.*)$/gm)) {
                cpuMHz = match?.groups?.cpuMHz;
            }
        } catch {}
    } catch {
    }

    let biosVendor = "";
    try {
        biosVendor = (await readFile("/sys/devices/virtual/dmi/id/bios_vendor"))?.toString()?.trim() || "";
    } catch {}

    let boardVendor = "";
    try {
        boardVendor = (await readFile("/sys/devices/virtual/dmi/id/board_vendor"))?.toString()?.trim() || "";
    } catch {}
    
    let chassisVendor = "";
    try {
        chassisVendor = (await readFile("/sys/devices/virtual/dmi/id/chassis_vendor"))?.toString()?.trim() || "";
    } catch {}

    const machineFingerprint = `Machine Id: ${linuxMachineId}\nCPU Model: ${cpuModel}\nCPU MHz: ${cpuMHz}\nBIOS Vendor: ${biosVendor}\nBoard Vendor: ${boardVendor}\nChassis Vendor: ${chassisVendor}`;

    var shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha256');
    shasum.update(machineFingerprint);
    const machineId = shasum.digest("base64");

    return {
        fingerprint: machineFingerprint,
        id: machineId,
        algorithm: "SHA256"
    };
}

async function loadMachineIdPerPlatform() {
    try {
        switch (process.platform) {
            case "win32": return await loadMachineIdWindows();
            case "darwin": return await loadMachineIdDarwin();
            case "linux": return await loadMachineIdLinux();
            default: throw new Error(`Platform ${process.platform} not supported.`);
        } 
    } catch(error) {
        if (error instanceof Error) {
            return { id: "ZGVmYXVsdF9pZA==", fingerprint: "", algorithm: "SHA1", error };
        } else {
            return { id: "ZGVmYXVsdF9pZA==", fingerprint: "", algorithm: "SHA1" };
        }
    }
}

let machineIdCache = undefined;

function loadMachineId() {
    return machineIdCache || (machineIdCache = loadMachineIdPerPlatform());
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (loadMachineId); 


/***/ })

};
;
//# sourceMappingURL=node_modules_telerik_machine-id_index_mjs.index.js.map