refactor(native): consolidate section and PE subject ownership

Specialize the buffer-backed directory driver for its actual ELF consumers and remove the unused PE branch. Share PE subject architecture interpretation at the existing machine owner, preserving unknowns for conflicting formats and unproven managed overrides.

Validation: runtime build and 108 focused service, native parser, GPU, and CLI/MCP tests passed using local fixtures. Live descriptor-backed PE readers remain supported.
This commit is contained in:
morluto committed 2026-10-25 02:28:09 +08:00
1 parent 92f32981da
commit 3f168af2e8
8 files changed
+32 -83

No files matched your search

@@ -14,11 +14,7 @@ import {
type PeCertificates,
} from "../../domain/native/peCertificates.js";
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
import {
decodePeMachine,
peOptionalHeaderMagic,
type PeArchitecture,
} from "../../domain/peMachine.js";
import { peSubjectArchitecture } from "../../domain/peMachine.js";
import { err, ok, type Result } from "../../domain/result.js";
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
@@ -76,7 +72,7 @@ export class PeCertificatesService {
),
);
const value = report.data;
const architecture = subjectArchitecture(value);
const architecture = peSubjectArchitecture(value.machine, value.format);
const locations = [
{ kind: "artifact-path" as const, path: value.artifact.path },
...(value.table === null
@@ -112,17 +108,6 @@ export class PeCertificatesService {
}
}
const subjectArchitecture = (
report: PeCertificates,
): PeArchitecture | undefined => {
const machine = decodePeMachine(report.machine);
if (machine === undefined || machine.nativeOsOverride) return undefined;
const magic = report.format === "pe32-plus" ? 0x20b : 0x10b;
return magic === peOptionalHeaderMagic(machine.architecture)
? machine.architecture
: undefined;
};
const validReport = (
report: PeCertificates,
maxEntries: number,
@@ -14,11 +14,7 @@ import {
type PeImports,
} from "../../domain/native/peImports.js";
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
import {
decodePeMachine,
peOptionalHeaderMagic,
type PeArchitecture,
} from "../../domain/peMachine.js";
import { peSubjectArchitecture } from "../../domain/peMachine.js";
import { err, type Result } from "../../domain/result.js";
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
@@ -72,7 +68,7 @@ export class PeImportsService {
),
);
const value = report.data;
const architecture = subjectArchitecture(value);
const architecture = peSubjectArchitecture(value.machine, value.format);
const locations = [
{ kind: "artifact-path" as const, path: value.artifact.path },
...fileRange(value.import_directory),
@@ -101,15 +97,6 @@ export class PeImportsService {
}
}
const subjectArchitecture = (report: PeImports): PeArchitecture | undefined => {
const machine = decodePeMachine(report.machine);
if (machine === undefined || machine.nativeOsOverride) return undefined;
const magic = report.format === "pe32-plus" ? 0x20b : 0x10b;
return magic === peOptionalHeaderMagic(machine.architecture)
? machine.architecture
: undefined;
};
const fileRange = (
directory: PeImports["import_directory"],
): readonly {
@@ -14,11 +14,7 @@ import {
type PeLoadConfig,
} from "../../domain/native/peLoadConfig.js";
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
import {
decodePeMachine,
peOptionalHeaderMagic,
type PeArchitecture,
} from "../../domain/peMachine.js";
import { peSubjectArchitecture } from "../../domain/peMachine.js";
import { err, type Result } from "../../domain/result.js";
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
@@ -72,7 +68,7 @@ export class PeLoadConfigService {
),
);
const value = report.data;
const architecture = subjectArchitecture(value);
const architecture = peSubjectArchitecture(value.machine, value.format);
const locations = [
{ kind: "artifact-path" as const, path: value.artifact.path },
...fileRange(value.tls?.directory ?? null),
@@ -109,17 +105,6 @@ export class PeLoadConfigService {
}
}
const subjectArchitecture = (
report: PeLoadConfig,
): PeArchitecture | undefined => {
const machine = decodePeMachine(report.machine);
if (machine === undefined || machine.nativeOsOverride) return undefined;
const magic = report.format === "pe32-plus" ? 0x20b : 0x10b;
return magic === peOptionalHeaderMagic(machine.architecture)
? machine.architecture
: undefined;
};
const fileRange = (
directory: { file_offset: number; size: number } | null,
): { kind: "file-offset-range"; start: number; end: number }[] =>
@@ -13,11 +13,7 @@ import {
type PeResourceIdentity,
} from "../../domain/native/peResources.js";
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
import {
decodePeMachine,
peOptionalHeaderMagic,
type PeArchitecture,
} from "../../domain/peMachine.js";
import { peSubjectArchitecture } from "../../domain/peMachine.js";
import { err, ok, type Result } from "../../domain/result.js";
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
@@ -64,7 +60,7 @@ export class PeResourcesService {
),
);
const value = report.data;
const architecture = subjectArchitecture(value);
const architecture = peSubjectArchitecture(value.machine, value.format);
return completeProviderEvidence(
createEvidence(
{
@@ -88,23 +84,6 @@ export class PeResourcesService {
}
}
/**
* Name the subject architecture from the reported COFF machine. The resource
* reader does not inspect the CLI header, so a ReadyToRun OS-override machine
* needs separate proof. An optional-header magic that contradicts the machine
* is observed conflicting evidence. Both stay unknown.
*/
const subjectArchitecture = (
report: PeResources,
): PeArchitecture | undefined => {
const machine = decodePeMachine(report.machine);
if (machine === undefined || machine.nativeOsOverride) return undefined;
const magic = report.format === "pe32-plus" ? 0x20b : 0x10b;
return magic === peOptionalHeaderMagic(machine.architecture)
? machine.architecture
: undefined;
};
/** Check cross-field invariants before provider output becomes public Evidence. */
const validReport = (
report: PeResources,