"use strict";
exports.id = "vendors-node_modules_telerik_machine-id_index_mjs";
exports.ids = ["vendors-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 */   loadWorkstationId: () => (/* binding */ loadWorkstationId)
/* 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;

function wsGuidFromHash(workstationHash) {
    var guidBuffer = Buffer.alloc(16);
    for (var i = 0; i < 16; i++) {
        guidBuffer[i] = workstationHash[i] ^ workstationHash[i + 16];
    }

    function digits(from, to) {
        let str = "";
        for (let i = from; i <= to; i++) {
            str += guidBuffer[i].toString(16, 2).padStart(2, '0').toUpperCase();
        }
        return str;
    }

    var wsid = `WS:${digits(0, 3)}-${digits(4, 5)}-${digits(6, 7)}-${digits(8, 9)}-${digits(10, 15)}`;
    return wsid;
}

async function loadWorkstationIdWindows() {
    const ps =
    "$BIOS = @(Get-WmiObject Win32_BIOS | Select-Object -Property Manufacturer, SerialNumber, Name);" +
    "$Product = @(Get-WmiObject Win32_ComputerSystemProduct | Select-Object -Property UUID);" +
    "New-Object -TypeName PSObject -Property @{" +
    "    'BIOS' = $BIOS;" +
    "    'Product' = $Product;" +
    "} | ConvertTo-JSON";

    const child = (0,child_process__WEBPACK_IMPORTED_MODULE_0__.spawn)("powershell.exe", ["-nologo", "-Command", ps]);

    let output = "";
    const shellInterface = readline__WEBPACK_IMPORTED_MODULE_1__.createInterface(child.stdout);
    for await(const line of shellInterface) {
        output = output == "" ? line : (output + "\n" + line);
    }

    const hardware = JSON.parse(output);

    let workstationFingerprint = "Telerik Licensing\nWorkstation Id Fingerprint\n";
    function addValue(value) {
        if (value == null || value == "") return;
        workstationFingerprint += value + ";";
    }

    workstationFingerprint += "BIOS:\n";
    for(var bios of hardware.BIOS) {
        workstationFingerprint += "  - ";
        addValue(bios.Manufacturer);
        addValue(bios.SerialNumber);
        addValue(bios.Name);
        workstationFingerprint += "\n";
    }

    workstationFingerprint += "Product:\n";
    for(var prod of hardware.Product) {
        workstationFingerprint += "  - ";
        addValue(prod.UUID);
        workstationFingerprint += "\n";
    }

    const shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha256');
    shasum.update(workstationFingerprint);
    const workstationHash = shasum.digest();

    const wsid = wsGuidFromHash(workstationHash);

    return { fingerprint: workstationFingerprint, id: wsid };
}

async function loadMachineIdWindows() {

    const ps =
        "$BIOS = @(Get-WmiObject Win32_BIOS | Select-Object -Property Manufacturer, SerialNumber, Name);" +
        "$DiskDrive = @(Get-WmiObject Win32_DiskDrive | Select-Object -Property SerialNumber, Model, InterfaceType);" +
        "$Processor = @(Get-WmiObject Win32_Processor | Select-Object -Property UniqueId, ProcessorId, Name, Manufacturer);" +
        "New-Object -TypeName PSObject -Property @{" +
        "    'BIOS' = $BIOS;" +
        "    'DiskDrive' = $DiskDrive;" +
        "    'Processor' = $Processor" +
        "} | ConvertTo-JSON";

    const child = (0,child_process__WEBPACK_IMPORTED_MODULE_0__.spawn)("powershell.exe", ["-nologo", "-Command", ps]);

    var output = "";
    const shellInterface = readline__WEBPACK_IMPORTED_MODULE_1__.createInterface(child.stdout);
    for await(const line of shellInterface) {
        output = output == "" ? line : (output + "\n" + line);
    }

    var hardware = JSON.parse(output);
    
    var machineFingerprint = "";

    function addValue(value) {
        if (value == null || value == "") return;
        machineFingerprint += value + ";";
    }

    for(var bios of hardware.BIOS) {
        addValue(bios.Manufacturer);
        addValue(bios.SerialNumber);
        addValue(bios.Name);
    }

    for(var bios of hardware.DiskDrive) {
        addValue(bios.SerialNumber);
        addValue(bios.Model);
        addValue(bios.InterfaceType);
    }

    for(var bios of hardware.Processor) {
        addValue(bios.UniqueId);
        addValue(bios.ProcessorId);
        addValue(bios.Name);
        addValue(bios.Manufacturer);
    }

    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 loadWorkstationIdDarwin() {

    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"))?.stdout?.toString();
    const { hardwareModel } = modelResult.match(/^hw.model:\s(?<hardwareModel>.*)$/m).groups;

    const workstationFingerprint =
        `Telerik Licensing\n` +
        `Workstation Id Fingerprint\n` +
        `Platform UUID: ${platformUUID}\n` +
        `Platform S/N: ${platformSN}\n` + 
        `Hardware model: ${hardwareModel}\n`;
    
    var shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha256');
    shasum.update(workstationFingerprint);
    const workstationHash = shasum.digest();
    const wsid = wsGuidFromHash(workstationHash);

    return { fingerprint: workstationFingerprint, id: wsid };
}

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 loadWorkstationIdLinux() {
    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 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 workstationFingerprint =
        `Telerik Licensing\n` +
        `Workstation Id Fingerprint\n` +
        `Machine Id: ${linuxMachineId}\n` +
        `BIOS Vendor: ${biosVendor}\n` +
        `Board Vendor: ${boardVendor}\n` +
        `Chassis Vendor: ${chassisVendor}\n`;

    var shasum = crypto__WEBPACK_IMPORTED_MODULE_2__.createHash('sha256');
    shasum.update(workstationFingerprint);
    const workstationHash = shasum.digest();

    const wsid = wsGuidFromHash(workstationHash);

    return { fingerprint: workstationFingerprint, id: wsid };
}

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" };
        }
    }
}

async function loadWorkstationIdPerPlatform() {
    try {
        switch (process.platform) {
            case "win32": return await loadWorkstationIdWindows();
            case "darwin": return await loadWorkstationIdDarwin();
            case "linux": return await loadWorkstationIdLinux();
            default: throw new Error(`Platform ${process.platform} not supported.`);
        } 
    } catch(error) {
        console.log(error);
        return { fingerprint: "<error>", id: "WS:00000000-0000-0000-0000-000000000000" }
    }
}

let machineIdCache = undefined;
function loadMachineId() {
    return machineIdCache || (machineIdCache = loadMachineIdPerPlatform());
};

let workstationIdCache = undefined;
function loadWorkstationId() {
    return workstationIdCache || (workstationIdCache = loadWorkstationIdPerPlatform());
}

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (loadMachineId);


/***/ })

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