diff --git a/scripts/lib/ghidra-installation-inspection.d.mts b/scripts/lib/ghidra-installation-inspection.d.mts index 18e2c1bac2c..90a8dd3e6b2 100644 --- a/scripts/lib/ghidra-installation-inspection.d.mts +++ b/scripts/lib/ghidra-installation-inspection.d.mts @@ -1,4 +1,5 @@ import type { + AvailableGhidraInstallation, GhidraInstallationHost, GhidraInstallationInspection, GhidraInstallationOptions, @@ -9,3 +10,12 @@ export function inspectVerifierGhidraInstallation( options: Omit, host?: GhidraInstallationHost, ): Promise; + +export function inspectVerifierGhidraFromEnvironment( + environment: GhidraInstallationOptions["environment"], + installDir?: string, +): Promise; + +export function requireVerifierGhidraInstallation( + environment: GhidraInstallationOptions["environment"], +): Promise; diff --git a/scripts/lib/ghidra-installation-inspection.mjs b/scripts/lib/ghidra-installation-inspection.mjs index e8782298460..6ecd1fd3dee 100644 --- a/scripts/lib/ghidra-installation-inspection.mjs +++ b/scripts/lib/ghidra-installation-inspection.mjs @@ -7,3 +7,33 @@ export function inspectVerifierGhidraInstallation(options, host) { inspectGhidraInstallation({ ...options, resourceOwner }, host), ); } + +/** Inspect the verifier's selected installation with its optional Java home. */ +export function inspectVerifierGhidraFromEnvironment( + environment, + installDir = environment.GHIDRA_INSTALL_DIR, +) { + return inspectVerifierGhidraInstallation({ + environment, + installDir, + ...(environment.JAVA_HOME === undefined + ? {} + : { javaHome: environment.JAVA_HOME }), + }); +} + +/** Require a caller-selected, available installation before fixture setup. */ +export async function requireVerifierGhidraInstallation(environment) { + const installDir = environment.GHIDRA_INSTALL_DIR; + if (installDir === undefined) + throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); + const installation = await inspectVerifierGhidraFromEnvironment( + environment, + installDir, + ); + if (installation.status !== "available") + throw new Error( + `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, + ); + return installation; +} diff --git a/scripts/lib/real-ghidra-namespace-annotations.mjs b/scripts/lib/real-ghidra-namespace-annotations.mjs index 2e179719709..fed4b8148a6 100644 --- a/scripts/lib/real-ghidra-namespace-annotations.mjs +++ b/scripts/lib/real-ghidra-namespace-annotations.mjs @@ -7,7 +7,7 @@ import { tmpdir } from "node:os"; import { basename, dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { promisify } from "node:util"; -import { inspectVerifierGhidraInstallation } from "./ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./ghidra-installation-inspection.mjs"; /** Exercise qualified annotation names against real demangled C++ ABI symbols. */ export async function verifyGhidraNamespaceAnnotations({ @@ -476,11 +476,7 @@ async function verifyAddressNames(call, symbols, kind) { } async function requireNamespaceDemangler(env) { - const inspection = await inspectVerifierGhidraInstallation({ - environment: env, - installDir: env.GHIDRA_INSTALL_DIR, - ...(env.JAVA_HOME === undefined ? {} : { javaHome: env.JAVA_HOME }), - }); + const inspection = await inspectVerifierGhidraFromEnvironment(env); if ( inspection.status !== "available" || inspection.nativeDecompilerPath === null diff --git a/scripts/verify-ghidra-loader-relocation.mjs b/scripts/verify-ghidra-loader-relocation.mjs index 8d36edf1383..d44be35b245 100644 --- a/scripts/verify-ghidra-loader-relocation.mjs +++ b/scripts/verify-ghidra-loader-relocation.mjs @@ -13,7 +13,7 @@ import { spawnOwnedProviderProcess, } from "../dist/process/ProviderProcess.js"; import { cleanupOwnedProcessGroup } from "../dist/process/ProcessOwnership.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs"; import { VerifierFixture, @@ -65,13 +65,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined) "Set GHIDRA_INSTALL_DIR to a bring-your-own Ghidra installation.", ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); assert.ok( installation.analyzeHeadlessPath !== null && (installation.status === "available" || diff --git a/scripts/verify-real-ghidra-com.mjs b/scripts/verify-real-ghidra-com.mjs index a1261278e03..2e876534165 100644 --- a/scripts/verify-real-ghidra-com.mjs +++ b/scripts/verify-real-ghidra-com.mjs @@ -17,7 +17,7 @@ import { Ajv2020 } from "ajv/dist/2020.js"; import { parseEvidence } from "../dist/domain/evidence.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; import { nativeInstructionSchema } from "../dist/domain/native/nativeInstruction.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { buildDosComFixture, buildRejectedDosComFixture, @@ -50,13 +50,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined) throw new Error( "verify:ghidra:com prerequisite missing: GHIDRA_INSTALL_DIR (bring your own Ghidra).", ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); if (installation.status !== "available") throw new Error( `verify:ghidra:com prerequisite unavailable: ${JSON.stringify(installation)}`, diff --git a/scripts/verify-real-ghidra-cortex-m.mjs b/scripts/verify-real-ghidra-cortex-m.mjs index faebec3b144..ee3e04f94af 100644 --- a/scripts/verify-real-ghidra-cortex-m.mjs +++ b/scripts/verify-real-ghidra-cortex-m.mjs @@ -24,7 +24,7 @@ import { v8mBaselineFixture, v8mMsplimFixture, } from "../tests/conformance/ghidra/cortexM.fixture.mjs"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { llvmThumbMnemonics } from "./lib/llvm-thumb-oracle.mjs"; import { requireMcpLifecycleResult, @@ -53,13 +53,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined) throw new Error( "Set GHIDRA_INSTALL_DIR to a bring-your-own Ghidra installation.", ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); assert.equal(installation.status, "available", JSON.stringify(installation)); const run = createVerifierRun(); // Every LLVM and CLI command runs as an owned process tree with a deadline. diff --git a/scripts/verify-real-ghidra-dol.mjs b/scripts/verify-real-ghidra-dol.mjs index e15f0ae570f..f288396a507 100644 --- a/scripts/verify-real-ghidra-dol.mjs +++ b/scripts/verify-real-ghidra-dol.mjs @@ -15,7 +15,7 @@ import { } from "../dist/ghidra/GhidraLanguageCatalog.js"; import { parseEvidence } from "../dist/domain/evidence.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildGameCubeDolFixture } from "../tests/conformance/ghidra/dol-fixture.mjs"; import { GEKKO_LANGUAGE, @@ -48,19 +48,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "GameCube DOL verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); diff --git a/scripts/verify-real-ghidra-dos.mjs b/scripts/verify-real-ghidra-dos.mjs index f951276b349..f2b61e767f3 100644 --- a/scripts/verify-real-ghidra-dos.mjs +++ b/scripts/verify-real-ghidra-dos.mjs @@ -15,7 +15,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/client/stdio"; import { parseEvidence } from "../dist/domain/evidence.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; import { functionBodySchema } from "../dist/domain/native/functionBody.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { buildDosMzFixture } from "../tests/conformance/ghidra/dos-mz-fixture.mjs"; import { assertVerifierCleanupComplete, @@ -41,13 +41,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined) throw new Error( "verify:ghidra:dos prerequisite missing: GHIDRA_INSTALL_DIR (bring your own Ghidra).", ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); if (installation.status !== "available") throw new Error( `verify:ghidra:dos prerequisite unavailable: ${JSON.stringify(installation)}`, diff --git a/scripts/verify-real-ghidra-mips-relocatable.mjs b/scripts/verify-real-ghidra-mips-relocatable.mjs index 4881a403f25..dd7a40baca6 100755 --- a/scripts/verify-real-ghidra-mips-relocatable.mjs +++ b/scripts/verify-real-ghidra-mips-relocatable.mjs @@ -10,7 +10,7 @@ import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js"; import { parseEvidence } from "../dist/domain/evidence.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildMipsRelocatableFixture } from "../tests/conformance/ghidra/mips-fixture.mjs"; import { assertMipsRelocations, @@ -41,19 +41,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "MIPS verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); // Refuse a host without the fixture toolchain before allocating anything. diff --git a/scripts/verify-real-ghidra-mips.mjs b/scripts/verify-real-ghidra-mips.mjs index 06a47d7aeac..712736baf0b 100644 --- a/scripts/verify-real-ghidra-mips.mjs +++ b/scripts/verify-real-ghidra-mips.mjs @@ -29,7 +29,7 @@ import { import { parseEvidence } from "../dist/domain/evidence.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildMipsFixture } from "../tests/conformance/ghidra/mips-fixture.mjs"; import { buildPspFixture, @@ -70,19 +70,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "MIPS verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); // Refuse a host without the fixture toolchain before allocating anything. diff --git a/scripts/verify-real-ghidra-mips32-shared.mjs b/scripts/verify-real-ghidra-mips32-shared.mjs index c1727437d1b..e5ce235e86c 100755 --- a/scripts/verify-real-ghidra-mips32-shared.mjs +++ b/scripts/verify-real-ghidra-mips32-shared.mjs @@ -10,7 +10,7 @@ import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js"; import { parseEvidence } from "../dist/domain/evidence.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildMipsSharedFixture } from "../tests/conformance/ghidra/mips-fixture.mjs"; import { assertMipsSharedLoad, @@ -40,19 +40,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "MIPS verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); // Refuse a host without the fixture toolchain before allocating anything. The diff --git a/scripts/verify-real-ghidra-ppc.mjs b/scripts/verify-real-ghidra-ppc.mjs index dce640d898b..7f84184ed92 100644 --- a/scripts/verify-real-ghidra-ppc.mjs +++ b/scripts/verify-real-ghidra-ppc.mjs @@ -17,7 +17,7 @@ import { import { parseEvidence } from "../dist/domain/evidence.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildPowerPcFixture } from "../tests/conformance/ghidra/ppc-fixture.mjs"; import { requireMcpOperationResult } from "./lib/mcp-verifier-results.mjs"; import { @@ -41,19 +41,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "PowerPC verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); // Refuse a host without the fixture toolchain before allocating anything. diff --git a/scripts/verify-real-ghidra-ppc64.mjs b/scripts/verify-real-ghidra-ppc64.mjs index 9756b53b174..26c00c3a309 100644 --- a/scripts/verify-real-ghidra-ppc64.mjs +++ b/scripts/verify-real-ghidra-ppc64.mjs @@ -18,7 +18,7 @@ import { import { parseEvidence } from "../dist/domain/evidence.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { requireVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; import { buildPowerPc64Fixture } from "../tests/conformance/ghidra/ppc-fixture.mjs"; import { requireMcpOperationResult, @@ -44,19 +44,7 @@ if (!["linux", "darwin"].includes(process.platform)) throw new Error( "PPC64 verification requires a supported Linux/macOS Ghidra host", ); -if (process.env.GHIDRA_INSTALL_DIR === undefined) - throw new Error("Missing prerequisite: caller-supplied GHIDRA_INSTALL_DIR"); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); -if (installation.status !== "available") - throw new Error( - `Ghidra prerequisite unavailable: ${JSON.stringify(installation)}`, - ); +const installation = await requireVerifierGhidraInstallation(process.env); const entrypoint = fileURLToPath(new URL("./rea.mjs", import.meta.url)); const run = createVerifierRun(); // Refuse a host without the fixture toolchain before allocating anything. diff --git a/scripts/verify-real-ghidra-project-coverage.mjs b/scripts/verify-real-ghidra-project-coverage.mjs index 50bc7a88b6c..596f823402e 100644 --- a/scripts/verify-real-ghidra-project-coverage.mjs +++ b/scripts/verify-real-ghidra-project-coverage.mjs @@ -14,7 +14,7 @@ import { createVerifierRun, completeVerifierRun } from "./lib/verifier-run.mjs"; import { Client } from "@modelcontextprotocol/client"; import { createAnalysisProfile } from "../dist/domain/analysisProfile.js"; import { createEvidenceBundle } from "../dist/domain/evidenceBundle.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { withVerifierCleanup } from "./lib/verifier-cleanup.mjs"; import { VerifierFixture, @@ -36,13 +36,10 @@ export async function verifyProjectCoverage(run) { throw new Error( "Set GHIDRA_INSTALL_DIR to an absolute Ghidra installation path.", ); - const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, + const installation = await inspectVerifierGhidraFromEnvironment( + process.env, installDir, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), - }); + ); if (installation.status !== "available") throw new Error(`Ghidra is unavailable: ${JSON.stringify(installation)}`); if (process.platform === "win32") diff --git a/scripts/verify-real-ghidra-raw.mjs b/scripts/verify-real-ghidra-raw.mjs index fb246f06b62..05e78bf8b96 100644 --- a/scripts/verify-real-ghidra-raw.mjs +++ b/scripts/verify-real-ghidra-raw.mjs @@ -15,7 +15,7 @@ import { ProviderProcessSupervisor, spawnOwnedProviderProcess, } from "../dist/process/ProviderProcess.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { requireMcpLifecycleResult, requireMcpOutput, @@ -48,13 +48,7 @@ if (process.env.GHIDRA_INSTALL_DIR === undefined) throw new Error( "Set GHIDRA_INSTALL_DIR to a bring-your-own Ghidra installation.", ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); assert.equal(installation.status, "available", JSON.stringify(installation)); const run = createVerifierRun(); diff --git a/scripts/verify-real-ghidra-riscv.mjs b/scripts/verify-real-ghidra-riscv.mjs index 5307b7ecdca..465a4a3dfcb 100644 --- a/scripts/verify-real-ghidra-riscv.mjs +++ b/scripts/verify-real-ghidra-riscv.mjs @@ -14,7 +14,7 @@ import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js"; import { parseAnalysisSnapshot } from "../dist/domain/analysisSnapshot.js"; import { parseEvidence } from "../dist/domain/evidence.js"; import { functionDossierSchema } from "../dist/domain/native/functionDossier.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { SUPPORTED_GHIDRA_VERSION } from "../dist/ghidra/GhidraReleasePolicy.js"; import { buildRiscvFixture, @@ -59,13 +59,7 @@ for (const key of ["REA_GHIDRA_LANGUAGE_ID", "REA_GHIDRA_COMPILER_SPEC_ID"]) throw new Error( `Unset ${key}: this lane verifies provider-pinned selection.`, ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +const installation = await inspectVerifierGhidraFromEnvironment(process.env); assert.equal(installation.status, "available", JSON.stringify(installation)); assert.equal(installation.providerVersion, SUPPORTED_GHIDRA_VERSION); diff --git a/scripts/verify-real-ghidra-switch.mjs b/scripts/verify-real-ghidra-switch.mjs index 590e5bab68b..62235a4a8e5 100644 --- a/scripts/verify-real-ghidra-switch.mjs +++ b/scripts/verify-real-ghidra-switch.mjs @@ -99,19 +99,13 @@ try { let installation; try { if (!compilerOnly) { - const { inspectVerifierGhidraInstallation } = + const { inspectVerifierGhidraFromEnvironment } = await import("./lib/ghidra-installation-inspection.mjs"); assert.ok( process.env.GHIDRA_INSTALL_DIR, "Ghidra switch lane prerequisite missing: GHIDRA_INSTALL_DIR (bring your own)", ); - installation = await inspectVerifierGhidraInstallation({ - environment: process.env, - installDir: process.env.GHIDRA_INSTALL_DIR, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), - }); + installation = await inspectVerifierGhidraFromEnvironment(process.env); assert.equal( installation.status, "available", diff --git a/scripts/verify-real-ghidra-windows.mjs b/scripts/verify-real-ghidra-windows.mjs index 430c9fbed1e..9ed25d06091 100644 --- a/scripts/verify-real-ghidra-windows.mjs +++ b/scripts/verify-real-ghidra-windows.mjs @@ -19,7 +19,7 @@ import { parseGhidraInventoryInput, parseGhidraInventoryResult, } from "../dist/ghidra/GhidraInventoryValues.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { SUPPORTED_GHIDRA_VERSION } from "../dist/ghidra/GhidraReleasePolicy.js"; import { GhidraHeadlessLauncher } from "../dist/ghidra/GhidraLauncher.js"; import { GHIDRA_PROVIDER_IDENTITY } from "../dist/ghidra/GhidraProviderMetadata.js"; @@ -60,13 +60,10 @@ if (installDir === undefined || !isAbsolute(installDir)) throw new Error( `Set GHIDRA_INSTALL_DIR to the absolute root of Ghidra ${SUPPORTED_GHIDRA_VERSION}.`, ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, +const installation = await inspectVerifierGhidraFromEnvironment( + process.env, installDir, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +); if ( installation.status !== "available" || installation.analyzeHeadlessPath === null || diff --git a/scripts/verify-real-ghidra.mjs b/scripts/verify-real-ghidra.mjs index 86df721cd26..0520c03d815 100644 --- a/scripts/verify-real-ghidra.mjs +++ b/scripts/verify-real-ghidra.mjs @@ -9,7 +9,7 @@ import { fileURLToPath } from "node:url"; import { parseBinaryTarget } from "../dist/application/BinaryTargetResolver.js"; import { resolveGhidraAnalysisProfile } from "../dist/ghidra/GhidraAnalysisProfile.js"; import { GhidraClient } from "../dist/ghidra/GhidraClient.js"; -import { inspectVerifierGhidraInstallation } from "./lib/ghidra-installation-inspection.mjs"; +import { inspectVerifierGhidraFromEnvironment } from "./lib/ghidra-installation-inspection.mjs"; import { SUPPORTED_GHIDRA_VERSION } from "../dist/ghidra/GhidraReleasePolicy.js"; import { GhidraHeadlessLauncher } from "../dist/ghidra/GhidraLauncher.js"; import { GHIDRA_PROVIDER_IDENTITY } from "../dist/ghidra/GhidraProviderMetadata.js"; @@ -60,13 +60,10 @@ if (installDir === undefined || !isAbsolute(installDir)) throw new Error( `Set GHIDRA_INSTALL_DIR to the absolute root of an extracted Ghidra ${SUPPORTED_GHIDRA_VERSION} release.`, ); -const installation = await inspectVerifierGhidraInstallation({ - environment: process.env, +const installation = await inspectVerifierGhidraFromEnvironment( + process.env, installDir, - ...(process.env.JAVA_HOME === undefined - ? {} - : { javaHome: process.env.JAVA_HOME }), -}); +); if ( installation.status !== "available" || installation.analyzeHeadlessPath === null diff --git a/tests/boundary/process/verifierFileResources.test.ts b/tests/boundary/process/verifierFileResources.test.ts index 4ebaeb5e57d..55d06f0a0c9 100644 --- a/tests/boundary/process/verifierFileResources.test.ts +++ b/tests/boundary/process/verifierFileResources.test.ts @@ -181,6 +181,7 @@ it("Ghidra verifier probes await the shared owned inspection contract", async () ); const paths = [ ...names.map((name) => `scripts/${name}`), + "scripts/verify-ghidra-loader-relocation.mjs", "scripts/lib/real-ghidra-namespace-annotations.mjs", ]; const probes: string[] = []; @@ -200,6 +201,8 @@ it("Ghidra verifier probes await the shared owned inspection contract", async () [ "inspectGhidraInstallation", "inspectVerifierGhidraInstallation", + "inspectVerifierGhidraFromEnvironment", + "requireVerifierGhidraInstallation", ].includes(node.expression.text) ) { probes.push(path); @@ -208,7 +211,7 @@ it("Ghidra verifier probes await the shared owned inspection contract", async () path, reason: "installation result was not awaited", }); - if (node.expression.text !== "inspectVerifierGhidraInstallation") + if (node.expression.text === "inspectGhidraInstallation") violations.push({ path, reason: "inspection has no shared cleanup owner",