Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership. Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers. BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
95 lines
3.1 KiB
TypeScript
95 lines
3.1 KiB
TypeScript
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
|
|
import { dirname, join } from "node:path";
|
|
import { execFileOutput } from "../process/ExecFileOutput.js";
|
|
|
|
/** Launch coordinates obtained from Ghidra's own release configuration helper. */
|
|
export const ghidraJavaLaunch = async (options: {
|
|
readonly platform: NodeJS.Platform;
|
|
readonly analyzeHeadlessPath: string;
|
|
readonly javaHome: string;
|
|
readonly homeRoot: string;
|
|
readonly tempRoot: string;
|
|
readonly arguments: readonly string[];
|
|
readonly environment: NodeJS.ProcessEnv;
|
|
readonly signal?: AbortSignal;
|
|
}): Promise<{
|
|
readonly command: string;
|
|
readonly arguments: readonly string[];
|
|
readonly environment: NodeJS.ProcessEnv;
|
|
}> => {
|
|
const supportRoot = dirname(options.analyzeHeadlessPath);
|
|
const installRoot = dirname(supportRoot);
|
|
const command = join(options.javaHome, "bin", "java");
|
|
const isolatedProperties = [
|
|
`-Duser.home=${options.homeRoot}`,
|
|
`-Djava.io.tmpdir=${options.tempRoot}`,
|
|
];
|
|
const supportArguments = [
|
|
...isolatedProperties,
|
|
"-cp",
|
|
join(supportRoot, "LaunchSupport.jar"),
|
|
"LaunchSupport",
|
|
installRoot,
|
|
];
|
|
const environment = {
|
|
...snapshotEnvironment(options.environment, options.platform),
|
|
};
|
|
const configuredEnvironment = await execFileOutput(
|
|
command,
|
|
[...supportArguments, "-envvars"],
|
|
{
|
|
env: environment,
|
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
},
|
|
);
|
|
for (const line of configuredEnvironment.stdout.split(/\r?\n/u)) {
|
|
if (line === "") continue;
|
|
const separator = line.indexOf("=");
|
|
const sourceKey = line.slice(0, separator);
|
|
const key =
|
|
options.platform === "win32" ? sourceKey.toUpperCase() : sourceKey;
|
|
if (separator < 1 || !/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key))
|
|
throw new Error(
|
|
`Invalid Ghidra LaunchSupport environment entry: ${line}`,
|
|
);
|
|
if ((environment[key] ?? "") === "")
|
|
environment[key] = line.slice(separator + 1);
|
|
}
|
|
const configuredArguments = await execFileOutput(
|
|
command,
|
|
[...supportArguments, "-vmargs"],
|
|
{
|
|
env: environment,
|
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
},
|
|
);
|
|
const vmArguments = configuredArguments.stdout
|
|
.split(/\r?\n/u)
|
|
.filter((line) => line !== "");
|
|
if (
|
|
vmArguments.some(
|
|
(argument) => !argument.startsWith("-") || argument.includes("\0"),
|
|
)
|
|
)
|
|
throw new Error("Invalid Ghidra LaunchSupport JVM argument");
|
|
return {
|
|
command,
|
|
environment,
|
|
arguments: [
|
|
...vmArguments,
|
|
...(options.platform === "darwin" ? ["-Xdock:name=Ghidra-Headless"] : []),
|
|
`-Xmx${environment.GHIDRA_HEADLESS_MAXMEM || environment.GHIDRA_MAXMEM || "2G"}`,
|
|
"-XX:ParallelGCThreads=2",
|
|
"-XX:CICompilerCount=2",
|
|
"-Djava.awt.headless=true",
|
|
...isolatedProperties,
|
|
"-showversion",
|
|
"-cp",
|
|
join(installRoot, "Ghidra", "Framework", "Utility", "lib", "Utility.jar"),
|
|
"ghidra.Ghidra",
|
|
"ghidra.app.util.headless.AnalyzeHeadless",
|
|
...options.arguments,
|
|
],
|
|
};
|
|
};
|