feat(process): record provider and verifier run lineage
This commit is contained in:
@@ -9,6 +9,7 @@ import { silentLogger, type Logger } from "../logger.js";
|
||||
import { PendingOperations } from "../process/PendingOperations.js";
|
||||
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
|
||||
import { ProviderStartupDeadline } from "../process/ProviderDeadline.js";
|
||||
import { ProviderRunLineage } from "../process/ProviderRunLineage.js";
|
||||
import {
|
||||
type ProviderProcessDiagnostic,
|
||||
type ProviderProcessSnapshot,
|
||||
@@ -84,6 +85,7 @@ export class GhidraClient {
|
||||
#snapshotPath: string | undefined;
|
||||
#token: string | undefined;
|
||||
#runId: string | undefined;
|
||||
readonly #lineage = new ProviderRunLineage();
|
||||
#nextId = 1;
|
||||
#closing = false;
|
||||
#processSnapshot: ProviderProcessSnapshot | undefined;
|
||||
@@ -217,6 +219,11 @@ export class GhidraClient {
|
||||
return structuredClone(this.#diagnostics());
|
||||
}
|
||||
|
||||
/** Latest token-verified launcher lineage for the active run. */
|
||||
runtimeLineage() {
|
||||
return this.#lineage.snapshot();
|
||||
}
|
||||
|
||||
async #start(signal: AbortSignal): Promise<GhidraStartResult> {
|
||||
if (signal.aborted)
|
||||
return err(this.#failure("cancelled", "Ghidra startup was cancelled"));
|
||||
@@ -274,7 +281,8 @@ export class GhidraClient {
|
||||
}
|
||||
if (deadline.signal.aborted) return this.#startupInterrupted(deadline);
|
||||
this.#token = randomBytes(32).toString("hex");
|
||||
this.#runId = randomUUID();
|
||||
this.#lineage.reset();
|
||||
this.#runId = this.#options.runId ?? randomUUID();
|
||||
const launched = await this.#options.launcher
|
||||
.launch(
|
||||
{
|
||||
@@ -312,7 +320,7 @@ export class GhidraClient {
|
||||
await this.#cleanup();
|
||||
return err(failure);
|
||||
}
|
||||
return completeGhidraStartupHandshake({
|
||||
const completed = await completeGhidraStartupHandshake({
|
||||
deadline,
|
||||
request: (method, params, requestOptions) =>
|
||||
this.#wire.request(method, params, requestOptions),
|
||||
@@ -321,6 +329,8 @@ export class GhidraClient {
|
||||
failure: this.#failure,
|
||||
startupTimeoutMs: this.#options.startupTimeoutMs,
|
||||
});
|
||||
if (completed.ok) await this.#lineage.observe(this.#launch);
|
||||
return completed;
|
||||
}
|
||||
|
||||
async #connect(
|
||||
@@ -497,6 +507,7 @@ export class GhidraClient {
|
||||
transport: this.#options.transport,
|
||||
providerVersion: this.#options.providerVersion,
|
||||
profileDigest: this.#options.profileDigest,
|
||||
...(this.#runId === undefined ? {} : { runId: this.#runId }),
|
||||
...(this.#runtimeRoot === undefined
|
||||
? {}
|
||||
: { runtimeRoot: this.#runtimeRoot.path }),
|
||||
|
||||
@@ -33,6 +33,7 @@ export type GhidraDiagnostic =
|
||||
/** Dependencies and exact profile commitment for one headless import. */
|
||||
export interface GhidraClientOptions {
|
||||
readonly launcher: GhidraLauncher;
|
||||
readonly runId?: string;
|
||||
readonly targetPath: string;
|
||||
readonly targetSha256: string;
|
||||
readonly transport?: GhidraTransportKind;
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface GhidraDiagnosticsOptions {
|
||||
readonly transport: GhidraTransportKind;
|
||||
readonly providerVersion: string;
|
||||
readonly profileDigest: string;
|
||||
readonly runId?: string;
|
||||
readonly runtimeRoot?: string;
|
||||
readonly launch?: GhidraLaunch;
|
||||
readonly snapshot?: ProviderProcessSnapshot;
|
||||
@@ -39,6 +40,7 @@ export const createGhidraDiagnostics = (
|
||||
transport: options.transport,
|
||||
provider_version: options.providerVersion,
|
||||
profile_digest: options.profileDigest,
|
||||
...(options.runId === undefined ? {} : { run_id: options.runId }),
|
||||
...(options.runtimeRoot === undefined
|
||||
? {}
|
||||
: {
|
||||
|
||||
@@ -157,9 +157,7 @@ export class GhidraHeadlessLauncher implements GhidraLauncher {
|
||||
}
|
||||
const spawned = started;
|
||||
return ok({
|
||||
process: spawned.process,
|
||||
ownsProcessLifetime: true,
|
||||
cleanup: () => cleanupStartedProcess(spawned, platform),
|
||||
...ownedGhidraProcess(spawned, platform),
|
||||
projectRoot: paths.projectRoot,
|
||||
ghidraLogPath: paths.ghidraLogPath,
|
||||
scriptLogPath: paths.scriptLogPath,
|
||||
@@ -176,6 +174,19 @@ export class GhidraHeadlessLauncher implements GhidraLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
const ownedGhidraProcess = (
|
||||
spawned: SpawnedOwnedProviderProcess,
|
||||
platform: NodeJS.Platform,
|
||||
): Pick<
|
||||
GhidraLaunch,
|
||||
"process" | "ownsProcessLifetime" | "ownership" | "cleanup"
|
||||
> => ({
|
||||
process: spawned.process,
|
||||
ownsProcessLifetime: true,
|
||||
ownership: spawned.ownership,
|
||||
cleanup: () => cleanupStartedProcess(spawned, platform),
|
||||
});
|
||||
|
||||
/** Exact executable and argv passed to shell-free process creation. */
|
||||
export interface GhidraHeadlessCommand {
|
||||
readonly command: string;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisClient,
|
||||
type AnalysisClientContext,
|
||||
type AnalysisOperation,
|
||||
type AnalysisProfileResolutionOptions,
|
||||
type AnalysisProviderCandidate,
|
||||
@@ -69,7 +70,8 @@ const SUPPORTED_FORMATS = new Set(["elf", "pe", "mach-o"]);
|
||||
/** Production seam for exercising provider projection without a real process. */
|
||||
export type GhidraProviderClientFactory = (
|
||||
options: GhidraClientOptions,
|
||||
) => Pick<GhidraClient, "start" | "callTool" | "close">;
|
||||
) => Pick<GhidraClient, "start" | "callTool" | "close"> &
|
||||
Partial<Pick<GhidraClient, "runtimeLineage">>;
|
||||
|
||||
/** Ghidra candidate backed by an isolated read-only headless import. */
|
||||
export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
@@ -172,6 +174,7 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
createClient(
|
||||
target: BinaryTarget,
|
||||
profile?: AnalysisProfileCommitment,
|
||||
context?: AnalysisClientContext,
|
||||
): AnalysisClient {
|
||||
const installation = this.#inspectInstallation();
|
||||
const prerequisites = ghidraClientPrerequisites(
|
||||
@@ -202,6 +205,7 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
: "unix-socket",
|
||||
providerVersion: prerequisites.value.providerVersion,
|
||||
profileDigest: committedProfile.digest,
|
||||
...(context === undefined ? {} : { runId: context.runId }),
|
||||
logger: this.logger.child({ layer: "ghidra-bridge" }),
|
||||
});
|
||||
return {
|
||||
@@ -254,6 +258,12 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
}),
|
||||
);
|
||||
},
|
||||
runtimeLineageSnapshots: () => {
|
||||
const observation = client.runtimeLineage?.() ?? null;
|
||||
return observation === null
|
||||
? []
|
||||
: [{ provider: committedProfile.provider, observation }];
|
||||
},
|
||||
close: () => client.close(),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user