Files
reverse-engineering-anything/scripts/verify-windows-native-artifact.mjs
608378c311 fix(windows): reject native addons with unusable delay-import tables (#15216)
* fix: deepen verified coverage for PR #14258

* fix(windows): recognize GNU delay-import terminator placement

* fix(windows): validate complete delay-import address tables

* fix(windows): validate delay-load descriptor targets

* fix(windows): validate delay-import function names

* fix(windows): bound delay imports to the dedicated IAT section

* test(windows): cover delay-import verifier refusals

* test(windows): cover nonzero delay-import padding

* fix(windows): require readable delay-import descriptors

* test(windows): accept read-only delay import names

* fix(windows): validate initial delay loader state

---------

Co-authored-by: ShuaixinHuang <ShuaixinHuang@users.noreply.github.com>
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
2026-11-30 19:18:16 +08:00

46 lines
1.4 KiB
JavaScript

#!/usr/bin/env node
import { access, readFile } from "node:fs/promises";
const root = new URL("../", import.meta.url);
const source = new URL("src/domain/windowsNativeArtifact.ts", root);
let sourceExists = true;
try {
await access(source);
} catch (cause) {
if (cause?.code !== "ENOENT") throw cause;
sourceExists = false;
}
const owner = sourceExists
? await (
await import("./lib/verifier-source-loader.mjs")
).importVerifierSource(source.href, import.meta.url)
: await import(new URL("dist/domain/windowsNativeArtifact.js", root).href);
const {
WINDOWS_NATIVE_ARTIFACT,
parseWindowsNativeManifest,
validateWindowsNativeArtifact,
validateWindowsNativeDelayImports,
} = owner;
const packageJson = JSON.parse(
await readFile(new URL("package.json", root), "utf8"),
);
const parsed = parseWindowsNativeManifest(
JSON.parse(
await readFile(new URL("native/windows/build/manifest.json", root), "utf8"),
),
packageJson.version,
);
if (!parsed.ok) throw parsed.error;
const manifest = parsed.value;
const bytes = await readFile(
new URL(`native/windows/build/${WINDOWS_NATIVE_ARTIFACT.artifact}`, root),
);
const valid = validateWindowsNativeArtifact(manifest, bytes);
if (!valid.ok) throw valid.error;
const delayImports = validateWindowsNativeDelayImports(bytes);
if (!delayImports.ok) throw delayImports.error;
process.stdout.write(
`${JSON.stringify({ ok: true, ...manifest, artifactBytes: bytes.length })}\n`,
);