mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
* refactor(errors): require a reason for every analysis cancellation Add cancelledBy, the one constructor for AnalysisCancelledError. Its reason argument is required: an aborted signal, an earlier cancellation, a reason carried from an inner failure, or an OwnerCancellation when REA closed the work's owner itself. Closed adb, apktool, firmware, sqlite, gdb, web-bundle analyzer and binary-session record owners now report OwnerCancellation.ownerClosed instead of an absent reason. Firmware's predecessor wait returns its cancellation as a Result, removing an unreachable reason-less fallback. An architecture guard rejects new direct constructions, with a counted per-file baseline that can only shrink. * refactor(errors): share one aborted-signal predicate with cancelledBy * refactor(process): return a departing caller's reason from a shared startup wait * refactor(browser): build browser cancellations with a required reason Migrate every AnalysisCancelledError construction under src/browser, src/javascript, src/electron, src/inspector and src/captures to cancelledBy and lower the guard baseline from 671 to 572. Service-worker setup aborts with OwnerCancellation.ownerClosed on close. * refactor(providers): build decompiler-provider cancellations with a required reason (#10587) Migrate every AnalysisCancelledError construction under src/ghidra, src/ida, src/cutter, src/jeb and src/kuna to cancelledBy and lower the guard baseline from 671 to 572. Closed Kuna target commands report OwnerCancellation.ownerClosed instead of an absent reason, and Kuna and JEB close abort their lifetimes with that typed reason. * fix(errors): read the reason of any signal-shaped cancellation source * test(ci): cover the counted-baseline comparison behind the architecture guard * refactor(electron): drop an unused error import from the fuse failure mapper
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
import type { AsarHeaderAdmission } from "../config/asarHeaderAdmission.js";
|
|
import type {
|
|
ElectronPageInspection,
|
|
InspectElectronPageInput,
|
|
} from "../domain/javascript/electronObservation.js";
|
|
import type { CdpConnection } from "./CdpConnection.js";
|
|
import { CdpCaptureCompleteness } from "./CdpCaptureCompleteness.js";
|
|
import type { CdpEndpointTarget } from "./CdpEndpoint.js";
|
|
import { optionalCdpCommand } from "./CdpOptionalCommand.js";
|
|
import { authorizedElectronFile } from "./ElectronFileScope.js";
|
|
import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
|
import { cancelledBy } from "../domain/analysisErrorCore.js";
|
|
import {
|
|
parseCdpWorkerTarget,
|
|
workerTargetOwnership,
|
|
} from "./CdpWorkerTarget.js";
|
|
|
|
/** Inventory local worker targets without attaching to them. */
|
|
export const captureElectronWorkers = async (input: {
|
|
readonly connection: CdpConnection;
|
|
readonly signal?: AbortSignal;
|
|
readonly target: CdpEndpointTarget;
|
|
readonly request: InspectElectronPageInput;
|
|
readonly frameIds: ReadonlySet<string>;
|
|
readonly completeness: CdpCaptureCompleteness;
|
|
readonly limitations: string[];
|
|
readonly asarHeaderAdmission: AsarHeaderAdmission;
|
|
}): Promise<ElectronPageInspection["workers"]> => {
|
|
const result = await optionalCdpCommand(
|
|
{
|
|
connection: input.connection,
|
|
sessionId: undefined,
|
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
},
|
|
"Target.getTargets",
|
|
{},
|
|
input.limitations,
|
|
);
|
|
if (!result.ok) {
|
|
// A malformed target list is unreadable, not empty.
|
|
if (result.error._tag === "CdpMalformedReply")
|
|
input.completeness.exclude("workers", "invalid_protocol_value", null);
|
|
else input.completeness.unavailable("workers");
|
|
return [];
|
|
}
|
|
const workers: ElectronPageInspection["workers"] = [];
|
|
const { targetInfos } = result.value;
|
|
for (const entry of targetInfos) {
|
|
throwIfElectronWorkerCaptureCancelled(input.signal);
|
|
const parsed = parseCdpWorkerTarget(entry);
|
|
if (!parsed.ok) {
|
|
input.completeness.exclude("workers", "invalid_protocol_value");
|
|
continue;
|
|
}
|
|
const target = parsed.value;
|
|
if (target.kind === "non_worker") continue;
|
|
const ownership = workerTargetOwnership(
|
|
target,
|
|
input.target.id,
|
|
input.frameIds,
|
|
);
|
|
if (ownership !== "selected") {
|
|
input.completeness.exclude(
|
|
"workers",
|
|
ownership === "unknown" ? "unattributed_target" : "out_of_target_scope",
|
|
);
|
|
continue;
|
|
}
|
|
const path = await authorizedElectronFile(
|
|
target.url,
|
|
input.signal,
|
|
"inspect_electron_page",
|
|
input.asarHeaderAdmission,
|
|
);
|
|
if (path === undefined) {
|
|
input.completeness.exclude("workers", "out_of_target_scope");
|
|
continue;
|
|
}
|
|
workers.push({
|
|
target_id: target.targetId,
|
|
type: target.type,
|
|
file_path: path,
|
|
attached: target.attached,
|
|
opener_target_id: target.openerTargetId,
|
|
parent_frame_id: target.parentFrameId,
|
|
});
|
|
}
|
|
return workers.sort((left, right) =>
|
|
compareUnicodeCodePoints(left.target_id, right.target_id),
|
|
);
|
|
};
|
|
|
|
const throwIfElectronWorkerCaptureCancelled = (signal?: AbortSignal): void => {
|
|
if (signal?.aborted === true)
|
|
throw cancelledBy("inspect_electron_page", signal);
|
|
};
|