| import { readFileSync, existsSync } from "node:fs";
|
|
|
| |
| |
| |
| |
| |
|
|
| export function validateBinaryMagic(path) {
|
| if (!existsSync(path)) return null;
|
| let buf;
|
| try {
|
| buf = readFileSync(path, { encoding: null }).subarray(0, 16);
|
| } catch {
|
| return null;
|
| }
|
| if (buf.length < 4) return null;
|
|
|
|
|
| if (buf[0] === 0x7f && buf[1] === 0x45 && buf[2] === 0x4c && buf[3] === 0x46) return "elf";
|
|
|
|
|
| if (buf[0] === 0xfe && buf[1] === 0xed && buf[2] === 0xfa && buf[3] === 0xcf) return "macho";
|
| if (buf[0] === 0xfe && buf[1] === 0xed && buf[2] === 0xfa && buf[3] === 0xce) return "macho";
|
|
|
|
|
| if (buf[0] === 0xcf && buf[1] === 0xfa && buf[2] === 0xed && buf[3] === 0xfe) return "macho-le";
|
| if (buf[0] === 0xce && buf[1] === 0xfa && buf[2] === 0xed && buf[3] === 0xfe) return "macho-le";
|
|
|
|
|
| if (buf[0] === 0xca && buf[1] === 0xfe && buf[2] === 0xba && buf[3] === 0xbe) return "macho-fat";
|
|
|
|
|
| if (buf[0] === 0x4d && buf[1] === 0x5a) return "pe";
|
|
|
| return null;
|
| }
|
|
|
| |
| |
| |
|
|
| export function platformBinaryLabel() {
|
| if (process.platform === "win32") return "pe";
|
| if (process.platform === "darwin") return "macho";
|
| return "elf";
|
| }
|
|
|