mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 14:31:22 +00:00
refactor(ghidra): classify Ghidra failures through the shared provider classifier
PSP extension inspection reports through classifyProviderFailure with a Ghidra dialect. The startup deadline decides at abort time whether the shared startup owner closed it, so Ghidra and Hopper no longer compare the abort reason with the owner's sentinel, and Ghidra's startup no longer compares a producer cancellation's reason with the deadline's. Three helpers that only construct one error kind now name that kind instead of AnalysisError.
This commit is contained in:
1 parent
bf0d85c1da
commit
d9db9bf187
9 files changed
+96
-70
No files matched your search
@@ -41,10 +41,6 @@
|
||||
"src/frida/FridaInstrumentationManager.ts": 1,
|
||||
"src/ghidra/GhidraClient.ts": 1,
|
||||
"src/ghidra/GhidraFileArtifacts.ts": 1,
|
||||
"src/ghidra/GhidraJavaProbe.ts": 1,
|
||||
"src/ghidra/GhidraLoadImageAttest.ts": 1,
|
||||
"src/ghidra/GhidraNativeAotSnapshotOwner.ts": 1,
|
||||
"src/ghidra/GhidraPspExtension.ts": 1,
|
||||
"src/go/GoBinaryProvider.ts": 1,
|
||||
"src/hopper/HopperFileOffset.ts": 1,
|
||||
"src/il2cpp/Il2cppMetadataProvider.ts": 1,
|
||||
|
||||
@@ -34,10 +34,7 @@ import {
|
||||
Utf8NdjsonDecodingError,
|
||||
} from "../process/Utf8NdjsonLineBuffer.js";
|
||||
import { ABORTED, waitForAbortable } from "../process/AbortablePromise.js";
|
||||
import {
|
||||
SharedStartupAttempt,
|
||||
STARTUP_OWNER_CLOSED,
|
||||
} from "../process/SharedStartupAttempt.js";
|
||||
import { SharedStartupAttempt } from "../process/SharedStartupAttempt.js";
|
||||
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
|
||||
import { ProviderStartupDeadline } from "../process/ProviderDeadline.js";
|
||||
import { ProviderRunLineage } from "../process/ProviderRunLineage.js";
|
||||
@@ -1550,17 +1547,13 @@ export class GhidraClient {
|
||||
cause?: unknown,
|
||||
cancellation?: { readonly reason: unknown },
|
||||
): GhidraSessionError {
|
||||
if (
|
||||
cancellation !== undefined &&
|
||||
!(
|
||||
deadline.signal.aborted &&
|
||||
cancellation.reason === deadline.signal.reason
|
||||
)
|
||||
)
|
||||
// A producer that cancelled while startup's deadline still ran reports
|
||||
// its own cancellation; once the deadline aborted, the deadline reports.
|
||||
if (cancellation !== undefined && !deadline.signal.aborted)
|
||||
return this.#failure("cancelled", "Ghidra startup was cancelled", cause, {
|
||||
cancellation,
|
||||
});
|
||||
if (deadline.signal.reason === STARTUP_OWNER_CLOSED)
|
||||
if (deadline.ownerClosed)
|
||||
return this.#failure(
|
||||
"process",
|
||||
"Ghidra session closed during startup",
|
||||
|
||||
@@ -336,7 +336,7 @@ const systemCode = (cause: unknown): string | undefined =>
|
||||
const probeFailureError = (
|
||||
failure: GhidraJavaProbeFailure,
|
||||
cause: unknown,
|
||||
): AnalysisError => {
|
||||
): ProviderAdapterError => {
|
||||
const { output, ...facts } = failure;
|
||||
return new ProviderAdapterError("ghidra", "ghidra:java", {
|
||||
cause,
|
||||
|
||||
@@ -67,7 +67,7 @@ const comparisonFailure = (
|
||||
input: NativeLoadImageAttestationInput,
|
||||
reason: string,
|
||||
cause?: unknown,
|
||||
): AnalysisError =>
|
||||
): ProviderAdapterError =>
|
||||
new ProviderAdapterError("ghidra", input.operation, {
|
||||
diagnostics: { reason },
|
||||
...(cause === undefined ? {} : { cause }),
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
AnalysisArtifactChangedError,
|
||||
type AnalysisCancelledError,
|
||||
cancelledBy,
|
||||
carriedReason,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
@@ -358,7 +359,7 @@ export class GhidraNativeAotSnapshotOwner {
|
||||
reason: unknown,
|
||||
observations: JsonValue,
|
||||
partialObservation?: AnalysisPartialObservation,
|
||||
): AnalysisError {
|
||||
): AnalysisCancelledError {
|
||||
return cancelledBy(operation, carriedReason(reason), {
|
||||
diagnostics: { measured_observation: observations },
|
||||
partialObservation,
|
||||
|
||||
@@ -4,12 +4,12 @@ import { lstat, opendir, realpath } from "node:fs/promises";
|
||||
import { isAbsolute, join } from "node:path";
|
||||
import { z } from "zod";
|
||||
import { sameRegularFileState } from "../filesystem/RegularFile.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
cancelledBy,
|
||||
carriedReason,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import {
|
||||
classifyProviderFailure,
|
||||
type ProviderFailureDialect,
|
||||
} from "../providers/classifyProviderFailure.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type { GhidraInstallationInspection } from "./GhidraInstallation.js";
|
||||
import { parseGhidraJavaProperties } from "./GhidraJavaProperties.js";
|
||||
@@ -20,9 +20,7 @@ import { AnalysisCleanupLease } from "../artifacts/AnalysisCleanupLease.js";
|
||||
import { OwnedDirectoryHandle } from "../filesystem/OwnedDirectoryHandle.js";
|
||||
import {
|
||||
assertArtifactReadActive,
|
||||
artifactFileCancellationCause,
|
||||
artifactFilePrimaryFacts,
|
||||
bindArtifactFileCleanup,
|
||||
withArtifactRegularFile,
|
||||
} from "../artifacts/ArtifactFileOperation.js";
|
||||
|
||||
@@ -60,7 +58,7 @@ export const inspectGhidraPspExtension = async (
|
||||
fingerprint(root, ghidraVersion, resources, signal),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
throw ghidraPspInspectionError(cause);
|
||||
throw classifyProviderFailure(cause, GHIDRA_PSP_INSPECTION_DIALECT);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -227,46 +225,40 @@ export const resolveGhidraPspExtension = async (
|
||||
),
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
return err(ghidraPspInspectionError(cause));
|
||||
return err(classifyProviderFailure(cause, GHIDRA_PSP_INSPECTION_DIALECT));
|
||||
}
|
||||
};
|
||||
|
||||
/** Preserve the producer's primary failure and its live cleanup dependencies. */
|
||||
const ghidraPspInspectionError = (cause: unknown): AnalysisError => {
|
||||
if (cause instanceof AnalysisError) return cause;
|
||||
const cleanup =
|
||||
cause instanceof ArtifactReaderFailure ? cause.cleanup : undefined;
|
||||
const { cause: primary } = artifactFilePrimaryFacts(cause);
|
||||
const admission =
|
||||
primary instanceof GhidraAdmissionError ? primary : undefined;
|
||||
const identity =
|
||||
admission?.code ??
|
||||
(primary instanceof Error ? primary.message : String(primary));
|
||||
const reason = `PSP_EXTENSION_UNAVAILABLE: ${identity} Use a compatible caller-installed ghidra-allegrex under GHIDRA_INSTALL_DIR/Ghidra/Extensions; REA does not install it.`;
|
||||
const diagnostics =
|
||||
admission === undefined
|
||||
? undefined
|
||||
: { code: admission.code, ...admission.detail };
|
||||
const error =
|
||||
cause instanceof ArtifactReaderFailure && cause.reason === "cancelled"
|
||||
? cancelledBy(
|
||||
"resolve_analysis_profile",
|
||||
carriedReason(artifactFileCancellationCause(cause)),
|
||||
{ cleanup },
|
||||
)
|
||||
: new AnalysisCapabilityUnavailableError(
|
||||
"ghidra",
|
||||
"resolve_analysis_profile",
|
||||
reason,
|
||||
{
|
||||
cause,
|
||||
userMessage: reason,
|
||||
cleanup,
|
||||
...(diagnostics === undefined ? {} : { diagnostics }),
|
||||
},
|
||||
);
|
||||
bindArtifactFileCleanup(cause, error);
|
||||
return error;
|
||||
/**
|
||||
* How a failed extension inspection is reported. The shared classifier keeps
|
||||
* typed failures, a cancelled read and the read's live cleanup; anything else
|
||||
* means no compatible caller-installed extension was established.
|
||||
*/
|
||||
const GHIDRA_PSP_INSPECTION_DIALECT: ProviderFailureDialect = {
|
||||
providerId: "ghidra",
|
||||
operation: "resolve_analysis_profile",
|
||||
unclassified: (cause, details) => {
|
||||
const { cause: primary } = artifactFilePrimaryFacts(cause);
|
||||
const admission =
|
||||
primary instanceof GhidraAdmissionError ? primary : undefined;
|
||||
const identity =
|
||||
admission?.code ??
|
||||
(primary instanceof Error ? primary.message : String(primary));
|
||||
const reason = `PSP_EXTENSION_UNAVAILABLE: ${identity} Use a compatible caller-installed ghidra-allegrex under GHIDRA_INSTALL_DIR/Ghidra/Extensions; REA does not install it.`;
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
"ghidra",
|
||||
"resolve_analysis_profile",
|
||||
reason,
|
||||
{
|
||||
...details,
|
||||
cause,
|
||||
userMessage: reason,
|
||||
...(admission === undefined
|
||||
? {}
|
||||
: { diagnostics: { code: admission.code, ...admission.detail } }),
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
/** Close before descending, retaining the exact directory owner on uncertainty. */
|
||||
@@ -315,11 +307,12 @@ const readChildren = async (
|
||||
{ cause: signal.reason },
|
||||
)
|
||||
: attempt.cause;
|
||||
const error = ghidraPspInspectionError(
|
||||
const error = classifyProviderFailure(
|
||||
ArtifactReaderFailure.withCleanup(
|
||||
primary,
|
||||
ArtifactReaderFailure.cleanupObservation(attempt.cause, path),
|
||||
),
|
||||
GHIDRA_PSP_INSPECTION_DIALECT,
|
||||
);
|
||||
lease.bindCleanupError(error);
|
||||
throw error;
|
||||
|
||||
@@ -48,10 +48,7 @@ import {
|
||||
import { redactCapturedTransportCredential } from "../process/ProviderDiagnosticRedaction.js";
|
||||
import { ProviderRunLineage } from "../process/ProviderRunLineage.js";
|
||||
import { ABORTED, waitForAbortable } from "../process/AbortablePromise.js";
|
||||
import {
|
||||
SharedStartupAttempt,
|
||||
STARTUP_OWNER_CLOSED,
|
||||
} from "../process/SharedStartupAttempt.js";
|
||||
import { SharedStartupAttempt } from "../process/SharedStartupAttempt.js";
|
||||
import {
|
||||
type ProviderProcessDiagnostic,
|
||||
ProviderProcessSupervisor,
|
||||
@@ -975,7 +972,7 @@ export class HopperClient {
|
||||
async #startupInterruption(
|
||||
deadline: ProviderStartupDeadline,
|
||||
): Promise<HopperCancelledError | HopperTimeoutError | HopperProtocolError> {
|
||||
if (deadline.signal.reason === STARTUP_OWNER_CLOSED)
|
||||
if (deadline.ownerClosed)
|
||||
return new HopperProtocolError("Hopper session closed during startup");
|
||||
if (deadline.interruption === "cancelled")
|
||||
return hopperCancelledBySignal(deadline.signal);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
||||
import { ProviderStartupDeadline } from "./ProviderDeadline.js";
|
||||
import { STARTUP_OWNER_CLOSED } from "./SharedStartupAttempt.js";
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({
|
||||
@@ -323,3 +324,36 @@ it("finalizes an expired startup under its own budget and the caller's signal",
|
||||
deadline.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ reason: STARTUP_OWNER_CLOSED, ownerClosed: true },
|
||||
{ reason: new Error("caller stopped"), ownerClosed: false },
|
||||
])(
|
||||
"reports whether the startup owner closed: $ownerClosed",
|
||||
({ reason, ownerClosed }) => {
|
||||
const controller = new AbortController();
|
||||
const deadline = new ProviderStartupDeadline(1000, controller.signal);
|
||||
try {
|
||||
expect(deadline.ownerClosed).toBe(false);
|
||||
controller.abort(reason);
|
||||
expect(deadline.interruption).toBe("cancelled");
|
||||
expect(deadline.ownerClosed).toBe(ownerClosed);
|
||||
expect(deadline.signal.reason).toBe(reason);
|
||||
} finally {
|
||||
deadline.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("does not report an owner close after the budget elapsed", async () => {
|
||||
const controller = new AbortController();
|
||||
const deadline = new ProviderStartupDeadline(100, controller.signal);
|
||||
try {
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
controller.abort(STARTUP_OWNER_CLOSED);
|
||||
expect(deadline.interruption).toBe("timeout");
|
||||
expect(deadline.ownerClosed).toBe(false);
|
||||
} finally {
|
||||
deadline.dispose();
|
||||
}
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Deadline } from "../domain/deadline.js";
|
||||
import { STARTUP_OWNER_CLOSED } from "./SharedStartupAttempt.js";
|
||||
|
||||
/** Result of an abort-aware interval wait. */
|
||||
export type AbortableWaitResult = "elapsed" | "aborted";
|
||||
@@ -46,6 +47,7 @@ export class ProviderStartupDeadline {
|
||||
readonly #onExternalAbort: () => void;
|
||||
#timer: NodeJS.Timeout | undefined;
|
||||
#interruption: "cancelled" | "timeout" | undefined;
|
||||
#ownerClosed = false;
|
||||
|
||||
constructor(
|
||||
readonly timeoutMs: number,
|
||||
@@ -66,6 +68,8 @@ export class ProviderStartupDeadline {
|
||||
return;
|
||||
}
|
||||
this.#interruption = "cancelled";
|
||||
// The startup owner closing is not a caller's cancellation.
|
||||
this.#ownerClosed = signal?.reason === STARTUP_OWNER_CLOSED;
|
||||
this.#abort(signal?.reason);
|
||||
};
|
||||
if (signal?.aborted === true) {
|
||||
@@ -88,6 +92,14 @@ export class ProviderStartupDeadline {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when the cancellation came from the shared startup owner closing,
|
||||
* not from a caller. Decided when the caller's signal aborted.
|
||||
*/
|
||||
get ownerClosed(): boolean {
|
||||
return this.#ownerClosed;
|
||||
}
|
||||
|
||||
/** Milliseconds still available to the next startup phase. */
|
||||
remainingMs(): number {
|
||||
// Node timers can fire a fraction of a millisecond before the monotonic
|
||||
|
||||
Reference in new issue
Block a user