Move each error family out of domain/errors.ts into its own module (base, core, provider selection/adapter, browser observation, artifact, evidence, unknown registry, hopper, configuration) and relocate AnalysisErrorProjection to analysisErrorProjection. Migrate all 162 importers to the owning modules and delete errors.ts. No re-export shims; behavior is unchanged.
61 lines
2.4 KiB
TypeScript
61 lines
2.4 KiB
TypeScript
import type {
|
|
AnalysisProfileResolution,
|
|
ProviderIdentity,
|
|
} from "../application/AnalysisProvider.js";
|
|
import { createAnalysisProfile } from "../domain/analysisProfile.js";
|
|
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
|
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { err, ok, type Result } from "../domain/result.js";
|
|
import type { GhidraInstallationInspection } from "./GhidraInstallation.js";
|
|
|
|
/** Resolve version-bound, deterministic semantics before Ghidra imports a target. */
|
|
export const resolveGhidraAnalysisProfile = (
|
|
target: BinaryTarget,
|
|
identity: ProviderIdentity,
|
|
installation: GhidraInstallationInspection,
|
|
signal?: AbortSignal,
|
|
): Promise<Result<AnalysisProfileResolution, AnalysisError>> => {
|
|
if (signal?.aborted === true)
|
|
return Promise.resolve(err(new AnalysisCancelledError("open_binary")));
|
|
if (target.kind !== "executable")
|
|
return Promise.resolve(ok({ profile: null, compatibility: {} }));
|
|
if (installation.status === "unavailable")
|
|
return Promise.resolve(
|
|
err(new ProviderAdapterError(identity.id, "resolve_analysis_profile")),
|
|
);
|
|
const provider = { ...identity, version: installation.providerVersion };
|
|
const dosMz = target.format === "dos-mz";
|
|
return Promise.resolve(
|
|
ok({
|
|
profile: createAnalysisProfile(provider, {
|
|
target_kind: target.kind,
|
|
target_format: target.format,
|
|
architecture: target.architecture ?? null,
|
|
available_architectures: [
|
|
...(target.availableArchitectures ?? []),
|
|
].sort(),
|
|
import_mode: "ephemeral-read-only",
|
|
function_body_evidence: "complete-inclusive-ranges-v1",
|
|
jump_table_evidence: "typed-case-default-blocks-v1",
|
|
decompiler_jump_loads: true,
|
|
loader: dosMz ? "MzLoader" : "auto-from-header",
|
|
language_id: dosMz ? "x86:LE:16:Real Mode" : "auto-from-header",
|
|
compiler_spec_id: dosMz ? "default" : "auto-default",
|
|
...(dosMz
|
|
? {
|
|
load_segment: "0x1000",
|
|
address_coordinates: "linear-byte-offset",
|
|
}
|
|
: {}),
|
|
analyzer_preset: "ghidra-default",
|
|
}),
|
|
compatibility: {
|
|
languageId: dosMz ? "x86:LE:16:Real Mode" : "auto",
|
|
compilerSpecId: dosMz ? "default" : "auto",
|
|
},
|
|
}),
|
|
);
|
|
};
|