refactor(managed): derive inspection from PE CLI extents

This commit is contained in:
morluto
2026-09-29 17:35:41 +08:00
parent 3b64c813cf
commit dfad09e3b5
34 changed files with 192 additions and 626 deletions
@@ -22,7 +22,6 @@ import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberIns
import {
buildManagedPeFixture,
managedPeFixtureTarget,
MANAGED_MEMBER_FIXTURE_LIMITS,
} from "../../../src/dotnet/ManagedPe.fixture.js";
describe("managed runtime correlation planning", () => {
@@ -152,35 +151,6 @@ describe("managed runtime correlation planning", () => {
if (result.ok) return;
expect(result.error._tag).toBe("AnalysisInputError");
});
it("rejects a runtime lock for instruction-limited CIL", async () => {
const directory = await createTestTempDirectory("rea-managed-runtime-");
const artifactPath = join(directory, "fixture.dll");
const executablePath = join(directory, "dotnet");
const bytes = buildManagedPeFixture();
await writeFile(artifactPath, bytes);
await writeFile(executablePath, "#!/bin/sh\n");
const fixture = inspect(bytes, artifactPath, {
...MANAGED_MEMBER_FIXTURE_LIMITS,
maxMethodInstructions: 1,
});
const authority = await authorityFor(directory, executablePath, true);
const result = await planManagedRuntimeCorrelationEvidence(
{
policy: () => enabledPolicy(directory, executablePath),
authority,
},
inputFor(fixture.evidence, fixture.method),
);
expect(fixture.method.body).toMatchObject({
status: "partial",
normalized_il_sha256: null,
});
expect(result.ok).toBe(false);
if (result.ok) return;
expect(result.error._tag).toBe("AnalysisInputError");
});
});
const enabledPolicy = (
@@ -248,13 +218,9 @@ const inputFor = (
},
});
const inspect = (
bytes: Buffer,
path: string,
limits: typeof MANAGED_MEMBER_FIXTURE_LIMITS = MANAGED_MEMBER_FIXTURE_LIMITS,
) => {
const inspect = (bytes: Buffer, path: string) => {
const target = managedPeFixtureTarget(bytes, path);
const result = inspectManagedMembersBytes(bytes, target, limits);
const result = inspectManagedMembersBytes(bytes, target);
const method = result.methods[0];
if (method === undefined) throw new Error("fixture has no method");
return {
@@ -14,9 +14,6 @@ import { inspectManagedNativeBoundariesBytes } from "../../../src/dotnet/Managed
import {
buildManagedPeFixture,
managedPeFixtureTarget,
MANAGED_ARTIFACT_FIXTURE_LIMITS,
MANAGED_MEMBER_FIXTURE_LIMITS,
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
} from "../../../src/dotnet/ManagedPe.fixture.js";
describe("managed application graph projection", () => {
@@ -29,21 +26,9 @@ describe("managed application graph projection", () => {
},
});
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
const managedArtifact = inspectManagedArtifactBytes(
bytes,
binary,
MANAGED_ARTIFACT_FIXTURE_LIMITS,
);
const members = inspectManagedMembersBytes(
bytes,
binary,
MANAGED_MEMBER_FIXTURE_LIMITS,
);
const boundaries = inspectManagedNativeBoundariesBytes(
bytes,
binary,
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
);
const managedArtifact = inspectManagedArtifactBytes(bytes, binary);
const members = inspectManagedMembersBytes(bytes, binary);
const boundaries = inspectManagedNativeBoundariesBytes(bytes, binary);
const artifactEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
operation: "inspect_managed_artifact",
parameters: {},
@@ -185,21 +170,17 @@ describe("managed application graph coverage", () => {
it("preserves partial parser coverage in graph and per-fact coverage", () => {
const bytes = buildManagedPeFixture();
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
const members = inspectManagedMembersBytes(
bytes,
binary,
MANAGED_MEMBER_FIXTURE_LIMITS,
);
const members = inspectManagedMembersBytes(bytes, binary);
const parserPartialMembers = {
...members,
coverage: {
state: "partial" as const,
issues: [
{
code: "limit-exceeded" as const,
scope: "method.0x06000001.body.instructions",
code: "invalid-blob" as const,
scope: "metadata.#Blob",
offset: 0x0a00,
detail: "instruction limit reached",
detail: "Blob content leaves #Blob",
},
],
},