Files
rea/src/ghidra/GhidraDiagnostics.ts
T
morluto 1f5be750bc fix(ghidra): harden location resolution and provider lifecycle
Preserve boundary diagnostics, resolve procedure names before bare hex addresses, and launch the inspected JVM directly on macOS for verifiable startup cancellation. Keep private socket paths within host limits and retain ownership when cleanup is incomplete.

Exercise the fixes through real CLI/MCP Ghidra workflows and provider-boundary integration tests, replacing redundant unit coverage.
2026-10-09 02:38:07 +08:00

83 lines
2.8 KiB
TypeScript

import type { JsonValue } from "../domain/jsonValue.js";
import type { ProviderProcessSnapshot } from "../process/ProviderProcess.js";
import type { GhidraLaunch } from "./GhidraLauncher.js";
import type { GhidraTransportKind } from "./GhidraTransport.js";
/** Inputs needed to project bounded diagnostics for one Ghidra runtime. */
export interface GhidraDiagnosticsOptions {
readonly targetPath: string;
readonly targetSha256: string;
readonly targetAdmission?: JsonValue;
readonly transport: GhidraTransportKind;
readonly providerVersion: string;
readonly profileDigest: string;
readonly runId?: string;
readonly runtimeRoot?: string;
readonly socketRoot?: string;
readonly endpointPath?: string;
readonly launch?: GhidraLaunch;
readonly snapshot?: ProviderProcessSnapshot;
readonly token?: string;
readonly previous: Readonly<Record<string, JsonValue>>;
}
/** Preserve actionable runtime coordinates after cleanup and redact bearer data. */
export const createGhidraDiagnostics = (
options: GhidraDiagnosticsOptions,
): Readonly<Record<string, JsonValue>> => {
if (
options.runtimeRoot === undefined &&
options.launch === undefined &&
Object.keys(options.previous).length > 0
)
return options.previous;
const redacted = (value: string): string =>
options.token === undefined
? value
: value.replaceAll(options.token, "[REDACTED]");
return {
target_path: options.targetPath,
target_sha256: options.targetSha256,
...(options.targetAdmission === undefined
? {}
: { target_admission: options.targetAdmission }),
transport: options.transport,
provider_version: options.providerVersion,
profile_digest: options.profileDigest,
...(options.runId === undefined ? {} : { run_id: options.runId }),
...(options.runtimeRoot === undefined
? {}
: { runtime_root: options.runtimeRoot }),
...(options.socketRoot === undefined
? {}
: { socket_root: options.socketRoot }),
...(options.endpointPath === undefined
? {}
: { endpoint_path: options.endpointPath }),
...(options.launch === undefined
? {}
: {
project_root: options.launch.projectRoot,
ghidra_log_path: options.launch.ghidraLogPath,
script_log_path: options.launch.scriptLogPath,
process_id: options.launch.process.pid ?? null,
}),
...(options.snapshot === undefined
? {}
: {
exit_code: options.snapshot.exitCode ?? null,
exit_signal: options.snapshot.signal ?? null,
stdout: boundedStream(options.snapshot.stdout, redacted),
stderr: boundedStream(options.snapshot.stderr, redacted),
}),
};
};
const boundedStream = (
stream: ProviderProcessSnapshot["stdout"],
redact: (value: string) => string,
): JsonValue => ({
text: redact(stream.text),
bytes: stream.bytes,
});