Files
reverse-engineering-anything/src/artifacts/ArtifactEmbeddedFormatProbes.ts
T
morluto cd1b35bcb9 refactor(process): compose supervision and provider-client cleanup failures through the shared owner (#10905)
* refactor(process): compose supervision and provider-client cleanup failures through the shared owner

* refactor(native): compose LLDB, native UI and signature cleanup failures through the shared owner (#10908)

* refactor(native): compose LLDB, native UI and signature cleanup failures through the shared owner

* refactor(server): compose close, reset and session-status cleanup failures through the shared owner (#10915)

* refactor(dotnet): compose managed snapshot cleanup failures through the shared owner (#10917)

* refactor(dotnet): compose managed snapshot cleanup failures through the shared owner

* refactor(flutter): compose build cleanup failures through the shared owner (#10918)

* refactor(flutter): compose build cleanup failures through the shared owner

* refactor(apple): compose asset catalog and keyed archive cleanup failures through the shared owner (#10919)

* refactor(ghidra): join session cleanup failures through the shared owner (#10920)

* refactor(ghidra): join session cleanup failures through the shared owner

* refactor(desktop): compose build-setup cleanup failures through the shared owner (#10921)

* refactor(desktop): compose build-setup cleanup failures through the shared owner

* refactor(cutter): compose bridge service cleanup failures through the shared owner (#10922)

* refactor(cutter): compose bridge service cleanup failures through the shared owner

* refactor(electron): compose fuse and file-scope cleanup failures through the shared owner (#10923)

* refactor(electron): compose fuse and file-scope cleanup failures through the shared owner

* refactor(browser): compose scenario, web-bundle and capture cleanup failures through the shared owner (#10924)

* refactor(application): compose uninstall, session retirement and decompile-all cleanup failures through the shared owner (#10933)

* refactor(application): compose uninstall, session retirement and decompile-all cleanup failures through the shared owner

* refactor(ghidra): compose Java probe, NativeAOT snapshot and provider-client cleanup failures through the shared owner (#10927)

* refactor(ghidra): compose Java probe, NativeAOT snapshot and provider-client cleanup failures through the shared owner

* refactor(hopper): compose provider close cleanup failures through the shared owner (#10928)

* refactor(hopper): compose provider close cleanup failures through the shared owner

* refactor(javascript): compose analysis worker runtime and inspection failures through the shared owner (#10929)

* refactor(javascript): compose analysis worker runtime and inspection failures through the shared owner

* refactor(kuna): compose project-cache and target-command cleanup failures through the shared owner (#10930)

* refactor(kuna): compose project-cache and target-command cleanup failures through the shared owner

* refactor(native): compose macOS provider, pwndbg and pwntools cleanup failures through the shared owner (#10931)

* refactor(native): compose macOS provider, pwndbg and pwntools cleanup failures through the shared owner

* refactor(wasm): compose WABT artifact cleanup failures through the shared owner (#10932)

* refactor(wasm): compose WABT artifact cleanup failures through the shared owner

* refactor(application): compose analysis-view cancellation and retained-content cleanup failures through the shared owner (#10941)

* refactor(application): compose analysis-view cancellation and retained-content cleanup failures through the shared owner

* refactor(kuna): compose span-close cancellation cleanup through the shared owner (#10942)

* refactor(decompile): bind the initialization failure with its cleanup through the shared owner (#10965)

* refactor(decompile): bind the initialization failure with its cleanup through the shared owner

* refactor(cli): bind environment serve listener and close failures through the shared owner (#10966)

* refactor(cli): bind environment serve listener and close failures through the shared owner

* refactor(kuna): bind project export and span-read failures with their cleanup through the shared owner (#10967)

* refactor(kuna): bind project export and span-read failures with their cleanup through the shared owner

* refactor(cutter): bind descriptor read failures with their cleanup through the shared owner (#10968)

* refactor(cutter): bind descriptor read failures with their cleanup through the shared owner

* refactor(ida): bind workspace file failures with their cleanup through the shared owner (#10969)

* refactor(ida): bind workspace file failures with their cleanup through the shared owner

* refactor(rizin): bind debug finalization failures with their cleanup through the shared owner (#10970)

* refactor(rizin): bind debug finalization failures with their cleanup through the shared owner

* refactor(application): compose close rejections with unknown completion through one owner (#10971)

* refactor(application): compose close rejections with unknown completion through one owner

* refactor(hopper): compose startup and launcher close rejections through the shared owner (#10972)

* refactor(hopper): compose startup and launcher close rejections through the shared owner

* refactor(desktop): compose task-file close rejections through the shared owner (#10973)

* fix(hopper): confirm reported close failures when a later close of the client succeeds

* fix(hopper): keep owned close failures reading their own owner on retry

HopperClient bound every failed close part to its client retry, so a launcher
aggregate that already follows its child failures stayed pending after the
launcher released them. AnalysisCleanupRelease.bindUnowned now owns the rule
that a retry claims only ownerless failures; BinarySession's local copy of it
is removed.

* fix(hopper): release each close part's earlier failures when that part succeeds

One shared retry release made the session part's earlier failures wait for
the launcher part too, so a later close whose session cleanup succeeded kept
reporting the session's released resources. HopperClient keeps one release per
part (session, launcher), and each part confirms its own failures when it
succeeds.
2026-11-16 05:54:45 +08:00

204 lines
6.7 KiB
TypeScript

import {
probeBunStandaloneGraph,
type BunStandaloneProbe,
} from "./bun/BunModuleGraphLayout.js";
import {
locateDenoStandalone,
type DenoStandaloneProbe,
} from "./deno/DenoStandaloneLocation.js";
import {
resolveArtifactReaderLimits,
type ArtifactReaderLimits,
} from "../domain/artifactReaderLimits.js";
import type {
StableRegularFileDescriptor,
RegularFileState,
} from "../filesystem/RegularFile.js";
import {
regularFileState,
sameRegularFileState,
} from "../filesystem/RegularFile.js";
import { findDotnetBundleHeader } from "./dotnet/DotnetBundle.js";
import { ArtifactReaderFailure, abortIfNeeded } from "../resources/index.js";
import { locateGodotPck, type GodotPckLocation } from "./GodotPckLocation.js";
import {
locateNodeSea,
type NodeSeaLocation,
} from "./nodeSea/NodeSeaLocation.js";
import {
observePyInstallerCookie,
type PyInstallerCookie,
type PyInstallerCookieObservation,
} from "./pyinstaller/CArchiveLayout.js";
/** Completed observations and explicit recognition limits; null alone is examined absence. */
export interface ArtifactEmbeddedFormatProbeFacts {
readonly sourceState: RegularFileState;
readonly readerLimits?: ArtifactReaderLimits;
readonly bunStandalone?: BunStandaloneProbe;
readonly denoStandalone?: DenoStandaloneProbe;
readonly godotPck?: GodotPckLocation | null;
readonly nodeSea?: NodeSeaLocation | null;
readonly nodeSeaRecognitionFailure?: ArtifactReaderFailure;
readonly dotnetBundleHeaderOffset?: number | null;
readonly pyInstaller?: PyInstallerCookieObservation;
}
/** Share format observations only across admissions of the same unchanged regular file. */
export class ArtifactEmbeddedFormatProbes {
#facts: ArtifactEmbeddedFormatProbeFacts;
constructor(
path: string,
private readonly source: StableRegularFileDescriptor,
private readonly signal?: AbortSignal,
previous?: ArtifactEmbeddedFormatProbeFacts,
private readonly limits: ArtifactReaderLimits = resolveArtifactReaderLimits(),
) {
abortIfNeeded(signal);
if (
previous !== undefined &&
!sameRegularFileState(previous.sourceState, source.initial)
)
throw new ArtifactReaderFailure(
"integrity",
`Root artifact changed before inventory: ${path}`,
{ integrityCheck: "container-identity" },
);
const reusable =
previous !== undefined &&
JSON.stringify(previous.readerLimits) === JSON.stringify(limits);
if (previous !== undefined && !reusable) {
const {
bunStandalone: _bun,
nodeSea: _sea,
nodeSeaRecognitionFailure: _seaLimit,
...facts
} = previous;
this.#facts = { ...facts, readerLimits: limits };
} else
this.#facts = previous ?? {
sourceState: regularFileState(source.initial),
readerLimits: limits,
};
}
async godotPck(prefix?: Uint8Array): Promise<GodotPckLocation | undefined> {
abortIfNeeded(this.signal);
if (this.#facts.godotPck !== undefined)
return this.#facts.godotPck ?? undefined;
const location = await locateGodotPck(
this.source.handle,
this.source.initial.size,
this.signal,
prefix,
);
this.#facts = { ...this.#facts, godotPck: location ?? null };
return location;
}
async nodeSea(): Promise<NodeSeaLocation | undefined> {
abortIfNeeded(this.signal);
if (this.#facts.nodeSea !== undefined)
return this.#facts.nodeSea ?? undefined;
if (this.#facts.nodeSeaRecognitionFailure !== undefined) return undefined;
try {
const location = await locateNodeSea(
this.source.handle,
this.source.initial.size,
this.signal,
this.limits.node_sea,
);
this.#facts = { ...this.#facts, nodeSea: location ?? null };
return location;
} catch (cause) {
if (
cause instanceof ArtifactReaderFailure &&
(cause.readerLimit?.parameter ===
"artifact_limits.node_sea.recognition_header_count" ||
cause.readerLimit?.parameter ===
"artifact_limits.node_sea.recognition_load_command_bytes")
) {
this.#facts = { ...this.#facts, nodeSeaRecognitionFailure: cause };
return undefined;
}
throw cause;
}
}
async pyInstaller(): Promise<PyInstallerCookie | undefined> {
abortIfNeeded(this.signal);
if (this.#facts.pyInstaller !== undefined)
return this.#facts.pyInstaller.state === "located"
? this.#facts.pyInstaller.cookie
: undefined;
const found = await observePyInstallerCookie(
this.source.handle,
this.source.initial.size,
this.signal,
);
abortIfNeeded(this.signal);
if (!found.ok)
throw new ArtifactReaderFailure(found.error.reason, found.error.message);
this.#facts = { ...this.#facts, pyInstaller: found.value };
return found.value.state === "located" ? found.value.cookie : undefined;
}
async dotnetBundle(): Promise<number | undefined> {
abortIfNeeded(this.signal);
if (this.#facts.dotnetBundleHeaderOffset !== undefined)
return this.#facts.dotnetBundleHeaderOffset ?? undefined;
// An apphost inside a recognized CArchive cannot claim its outer carrier.
const packaged = await this.pyInstaller();
const header = await findDotnetBundleHeader(
this.source.handle,
this.source.initial.size,
this.signal,
packaged?.archiveStart ?? this.source.initial.size,
);
abortIfNeeded(this.signal);
this.#facts = { ...this.#facts, dotnetBundleHeaderOffset: header ?? null };
return header;
}
async bunStandalone(): Promise<BunStandaloneProbe> {
abortIfNeeded(this.signal);
if (this.#facts.bunStandalone !== undefined)
return this.#facts.bunStandalone;
const observed = await probeBunStandaloneGraph(
this.source.handle,
this.source.initial.size,
this.signal,
this.limits.bun,
);
abortIfNeeded(this.signal);
this.#facts = { ...this.#facts, bunStandalone: observed };
return observed;
}
async denoStandalone(): Promise<DenoStandaloneProbe> {
abortIfNeeded(this.signal);
if (this.#facts.denoStandalone !== undefined)
return this.#facts.denoStandalone;
const packaged = await this.pyInstaller();
const observed = await locateDenoStandalone(
this.source.handle,
this.source.initial.size,
this.signal,
packaged === undefined
? undefined
: {
start: packaged.archiveStart,
end: packaged.archiveStart + packaged.packageLength,
},
);
abortIfNeeded(this.signal);
this.#facts = { ...this.#facts, denoStandalone: observed };
return observed;
}
completedFacts(): ArtifactEmbeddedFormatProbeFacts {
return this.#facts;
}
}