fix(dotnet): downgrade truncated CIL identity and coverage
This commit is contained in:
@@ -226,11 +226,49 @@ describe("managed PE/CLI static provider", () => {
|
||||
expect(result.methods.items[0]?.body).toMatchObject({
|
||||
status: "malformed",
|
||||
il_size: 2,
|
||||
normalized_il_sha256: null,
|
||||
decoded_instruction_count: 0,
|
||||
issue: "Unsupported CIL opcode 0x24 at IL offset 0",
|
||||
});
|
||||
});
|
||||
|
||||
it("marks instruction-limited CIL as partial without assigning normalized identity", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const result = inspectManagedMembersBytes(bytes, target(bytes), {
|
||||
...memberLimits,
|
||||
maxMethodInstructions: 1,
|
||||
});
|
||||
const il = bytes.subarray(0x0a01, 0x0a0d);
|
||||
|
||||
expect(result.metadata.status).toBe("complete");
|
||||
expect(result.methods.items[0]?.body).toMatchObject({
|
||||
status: "partial",
|
||||
il_size: 12,
|
||||
il_sha256: createHash("sha256").update(il).digest("hex"),
|
||||
normalized_il_sha256: null,
|
||||
instruction_count: 1,
|
||||
decoded_instruction_count: 1,
|
||||
truncated_instructions: 1,
|
||||
issue:
|
||||
"Instruction decode reached max_method_instructions 1 before the end of the method body",
|
||||
});
|
||||
expect(result.coverage).toEqual({
|
||||
state: "partial",
|
||||
issues: [
|
||||
{
|
||||
code: "limit-exceeded",
|
||||
scope: "method.0x06000001.body.instructions",
|
||||
offset: 0x0a00,
|
||||
detail:
|
||||
"Instruction decode reached max_method_instructions 1 before the end of the method body",
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.limitations.join(" ")).toContain(
|
||||
"has no normalized CIL identity",
|
||||
);
|
||||
});
|
||||
|
||||
it("inspects metadata members, signatures, CIL hashes, call edges, and field anchors", () => {
|
||||
const bytes = buildManagedPeFixture();
|
||||
const result = inspectManagedMembersBytes(
|
||||
|
||||
@@ -111,6 +111,33 @@ describe("managed member comparison", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not match identical instruction-limited method prefixes", () => {
|
||||
const limited = { ...memberLimits, maxMethodInstructions: 1 };
|
||||
const left = inspect(
|
||||
buildManagedPeFixture(),
|
||||
"/tmp/left-partial.dll",
|
||||
limited,
|
||||
);
|
||||
const right = inspect(
|
||||
buildManagedPeFixture(),
|
||||
"/tmp/right-partial.dll",
|
||||
limited,
|
||||
);
|
||||
const result = compareManagedMembers(
|
||||
{ evidenceId: left.evidence.evidence_id, result: left.result },
|
||||
{ evidenceId: right.evidence.evidence_id, result: right.result },
|
||||
comparisonLimits,
|
||||
);
|
||||
|
||||
expect(result.matching.exact_il_signature).toBe(0);
|
||||
expect(result.matching.structural_method_shape).toBe(0);
|
||||
expect(result.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
left_status: "partial",
|
||||
right_status: "partial",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not guess ambiguous field signature matches", () => {
|
||||
const left = inspect(buildManagedPeFixture(), "/tmp/left.dll");
|
||||
const leftField = left.result.fields.items[0];
|
||||
@@ -201,7 +228,11 @@ describe("managed member comparison", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const inspect = (bytes: Buffer, path: string) => {
|
||||
const inspect = (
|
||||
bytes: Buffer,
|
||||
path: string,
|
||||
limits: typeof memberLimits = memberLimits,
|
||||
) => {
|
||||
const target: BinaryTarget = {
|
||||
path,
|
||||
sha256: hash(bytes),
|
||||
@@ -209,7 +240,7 @@ const inspect = (bytes: Buffer, path: string) => {
|
||||
format: "pe",
|
||||
architecture: "x86",
|
||||
};
|
||||
const result = inspectManagedMembersBytes(bytes, target, memberLimits);
|
||||
const result = inspectManagedMembersBytes(bytes, target, limits);
|
||||
return {
|
||||
result,
|
||||
evidence: createEvidence(target, MANAGED_STATIC_PROVIDER, {
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
importManagedReconstruction,
|
||||
managedReconstructionImportInputSchema,
|
||||
} from "../src/domain/managedReconstruction.js";
|
||||
import { managedMemberInspectionSchema } from "../src/domain/managedArtifact.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
|
||||
const exampleInput = () =>
|
||||
managedReconstructionImportInputSchema.parse(
|
||||
@@ -97,6 +99,58 @@ describe("managed decompiler reconstruction import", () => {
|
||||
).toThrow(/does not match/u);
|
||||
});
|
||||
|
||||
it("rejects reconstruction locks for partial CIL without normalized identity", () => {
|
||||
const input = exampleInput();
|
||||
const observed = managedMemberInspectionSchema.parse(
|
||||
input.static_members.normalized_result,
|
||||
);
|
||||
const method = observed.methods.items[0];
|
||||
if (method === undefined) throw new Error("missing observed method");
|
||||
const partial = {
|
||||
...observed,
|
||||
methods: {
|
||||
...observed.methods,
|
||||
items: [
|
||||
{
|
||||
...method,
|
||||
body: {
|
||||
...method.body,
|
||||
status: "partial" as const,
|
||||
normalized_il_sha256: null,
|
||||
truncated_instructions: 1,
|
||||
issue: "instruction limit reached",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
coverage: { state: "partial" as const, issues: [] },
|
||||
};
|
||||
const partialEvidence = createEvidence(
|
||||
undefined,
|
||||
input.static_members.provider,
|
||||
{
|
||||
operation: "inspect_managed_members",
|
||||
parameters: {},
|
||||
result: partial,
|
||||
rawResult: null,
|
||||
limitations: partial.limitations,
|
||||
},
|
||||
);
|
||||
|
||||
expect(() =>
|
||||
importManagedReconstruction({
|
||||
...input,
|
||||
static_members: partialEvidence,
|
||||
methods: [
|
||||
{
|
||||
...exampleMethod(),
|
||||
normalized_il_sha256: null,
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toThrow(/does not match/u);
|
||||
});
|
||||
|
||||
it("wraps imported reconstruction in Evidence v2", () => {
|
||||
const evidence = importManagedReconstructionEvidence(exampleInput());
|
||||
|
||||
|
||||
@@ -146,6 +146,35 @@ 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 mkdtemp(join(tmpdir(), "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, {
|
||||
...memberLimits,
|
||||
maxMethodInstructions: 1,
|
||||
});
|
||||
const authority = await authorityFor(directory, executablePath, true);
|
||||
const result = await planManagedRuntimeCorrelationEvidence(
|
||||
{
|
||||
policy: { enabled: true, roots: [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 disabledPolicy: ManagedRuntimePolicy = {
|
||||
@@ -210,7 +239,11 @@ const inputFor = (
|
||||
},
|
||||
});
|
||||
|
||||
const inspect = (bytes: Buffer, path: string) => {
|
||||
const inspect = (
|
||||
bytes: Buffer,
|
||||
path: string,
|
||||
limits: typeof memberLimits = memberLimits,
|
||||
) => {
|
||||
const target: BinaryTarget = {
|
||||
path,
|
||||
sha256: hash(bytes),
|
||||
@@ -218,7 +251,7 @@ const inspect = (bytes: Buffer, path: string) => {
|
||||
format: "pe",
|
||||
architecture: "x86",
|
||||
};
|
||||
const result = inspectManagedMembersBytes(bytes, target, memberLimits);
|
||||
const result = inspectManagedMembersBytes(bytes, target, limits);
|
||||
const method = result.methods.items[0];
|
||||
if (method === undefined) throw new Error("fixture has no method");
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user