feat(ghidra): add private headless provider session

This commit is contained in:
N0zoM1z0
2026-07-16 01:27:54 +09:00
committed by N0zoM1z0
parent ed17e76473
commit f0e625d7ee
234 changed files with 8968 additions and 513 deletions
+46
View File
@@ -0,0 +1,46 @@
import type { JsonValue } from "../domain/jsonValue.js";
import { err, type Result } from "../domain/result.js";
import type { PendingOperations } from "../process/PendingOperations.js";
import type { GhidraSessionError } from "./GhidraSessionError.js";
import { ghidraResponseResult, parseGhidraResponseLine } from "./protocol.js";
/** Dependencies for correlating validated bridge responses. */
export interface GhidraResponseRouterOptions {
readonly pending: PendingOperations<
number,
Result<JsonValue, GhidraSessionError>
>;
readonly nextId: () => number;
readonly remoteFailure: (message: string, cause: Error) => GhidraSessionError;
readonly protocolFailure: (message: string, cause?: Error) => void;
}
/** Routes validated response IDs without giving the wire protocol client state. */
export class GhidraResponseRouter {
readonly #options: GhidraResponseRouterOptions;
constructor(options: GhidraResponseRouterOptions) {
this.#options = options;
}
/** Parse and settle one complete response line. */
route(line: string): void {
const parsed = parseGhidraResponseLine(line);
if (!parsed.ok) {
this.#options.protocolFailure(parsed.error.message, parsed.error);
return;
}
if (!this.#options.pending.has(parsed.value.id)) {
if (parsed.value.id >= this.#options.nextId())
this.#options.protocolFailure("Ghidra returned an unknown response id");
return;
}
const result = ghidraResponseResult(parsed.value);
this.#options.pending.settle(
parsed.value.id,
result.ok
? result
: err(this.#options.remoteFailure(result.error.message, result.error)),
);
}
}