2025-03-23 23:22:22 +02:00
|
|
|
const child_process = require("child_process");
|
2025-04-28 21:23:42 +03:00
|
|
|
const { default: e } = require("express");
|
2025-04-27 23:47:51 +03:00
|
|
|
const fs = require("fs");
|
2025-04-28 20:51:44 +03:00
|
|
|
const path = require("path");
|
2025-03-23 23:22:22 +02:00
|
|
|
|
2025-04-28 20:51:44 +03:00
|
|
|
module.exports = function (sourcePath) {
|
2025-03-24 17:00:37 +02:00
|
|
|
const { WINDOWS_SIGN_EXECUTABLE } = process.env;
|
|
|
|
if (!WINDOWS_SIGN_EXECUTABLE) {
|
|
|
|
console.warn("[Sign] Skip signing due to missing environment variable.");
|
|
|
|
return;
|
2025-04-28 21:23:42 +03:00
|
|
|
}
|
2025-04-28 20:38:22 +03:00
|
|
|
|
2025-04-28 21:23:42 +03:00
|
|
|
const buffer = fs.readFileSync(sourcePath);
|
|
|
|
console.log("Platform: ", process.platform);
|
|
|
|
console.log("CPU archi:", process.arch);
|
|
|
|
console.log("DLL archi: ", getDllArchitectureFromBuffer(buffer));
|
2025-04-27 23:47:51 +03:00
|
|
|
|
2025-04-28 20:09:27 +03:00
|
|
|
try {
|
2025-04-28 21:23:42 +03:00
|
|
|
const command = `${WINDOWS_SIGN_EXECUTABLE} --executable "${sourcePath}"`;
|
|
|
|
console.log(`[Sign] ${command}`);
|
|
|
|
|
2025-04-28 20:09:27 +03:00
|
|
|
child_process.execSync(command);
|
|
|
|
} catch (e) {
|
2025-04-28 20:20:16 +03:00
|
|
|
console.error("[Sign] Got error while signing " + e.output.toString("utf-8"));
|
2025-04-28 20:51:44 +03:00
|
|
|
process.exit(2);
|
2025-04-28 20:09:27 +03:00
|
|
|
}
|
2025-04-28 21:23:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getDllArchitectureFromBuffer(buffer) {
|
|
|
|
// Check for MZ header
|
|
|
|
if (buffer[0] !== 0x4D || buffer[1] !== 0x5A) {
|
|
|
|
return 'Not a PE file (missing MZ header)';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Offset to PE header
|
|
|
|
const peHeaderOffset = buffer.readUInt32LE(0x3C);
|
|
|
|
|
|
|
|
// Confirm PE signature
|
|
|
|
const peSig = buffer.toString('utf8', peHeaderOffset, peHeaderOffset + 4);
|
|
|
|
if (peSig !== 'PE\u0000\u0000') {
|
|
|
|
return 'Invalid PE header';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Machine field is 2 bytes at PE header + 4
|
|
|
|
const machine = buffer.readUInt16LE(peHeaderOffset + 4);
|
|
|
|
|
|
|
|
const archMap = {
|
|
|
|
0x014c: 'x86 (32-bit)',
|
|
|
|
0x8664: 'x64 (64-bit)',
|
|
|
|
0x01c4: 'ARM (32-bit)',
|
|
|
|
0xaa64: 'ARM64',
|
|
|
|
};
|
|
|
|
|
|
|
|
return archMap[machine] || `Unknown (0x${machine.toString(16)})`;
|
|
|
|
}
|