111 lines
3.5 KiB
TypeScript
111 lines
3.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { inspectManagedMembersBytes } from "./ManagedMemberInspector.js";
|
|
import { inspectManagedNativeBoundariesBytes } from "./ManagedNativeBoundaryInspector.js";
|
|
import {
|
|
buildManagedPeFixture,
|
|
buildNativePeFixture,
|
|
managedPeFixtureTarget,
|
|
MANAGED_MEMBER_FIXTURE_LIMITS,
|
|
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
|
|
} from "./ManagedPe.fixture.js";
|
|
|
|
describe("managed native boundaries", () => {
|
|
it("inspects managed/native PInvoke declarations without verifying native exports", () => {
|
|
const bytes = buildManagedPeFixture({
|
|
pinvoke: {
|
|
moduleName: "user32.dll",
|
|
importName: "MessageBoxW",
|
|
mappingFlags: 0x0345,
|
|
},
|
|
readyToRun: true,
|
|
});
|
|
const result = inspectManagedNativeBoundariesBytes(
|
|
bytes,
|
|
managedPeFixtureTarget(bytes),
|
|
MANAGED_NATIVE_BOUNDARY_FIXTURE_LIMITS,
|
|
);
|
|
|
|
expect(result.cli_native).toMatchObject({
|
|
il_only: true,
|
|
ready_to_run_signature: true,
|
|
managed_native_header_rva: 0x2700,
|
|
managed_native_header_size: 4,
|
|
});
|
|
expect(result.module_refs).toEqual([
|
|
{
|
|
token: "0x1a000001",
|
|
row_offset: expect.any(Number),
|
|
name: "user32.dll",
|
|
},
|
|
]);
|
|
expect(result.pinvoke_imports).toEqual([
|
|
expect.objectContaining({
|
|
token: "0x1c000001",
|
|
member_token: "0x06000001",
|
|
member_kind: "method",
|
|
member_name: "Main",
|
|
import_name: "MessageBoxW",
|
|
import_scope_token: "0x1a000001",
|
|
import_scope_name: "user32.dll",
|
|
no_mangle: true,
|
|
char_set: "unicode",
|
|
call_convention: "stdcall",
|
|
supports_last_error: true,
|
|
verification: "managed-declaration-only",
|
|
}),
|
|
]);
|
|
expect(result.native_implementations).toEqual([
|
|
expect.objectContaining({
|
|
token: "0x06000001",
|
|
name: "Main",
|
|
pinvoke_declared: true,
|
|
boundary_kind: "pinvoke",
|
|
body_interpretation: "native-or-runtime",
|
|
}),
|
|
]);
|
|
expect(result.summary).toMatchObject({
|
|
module_ref_count: 1,
|
|
pinvoke_import_count: 1,
|
|
native_implementation_count: 1,
|
|
ready_to_run: true,
|
|
mixed_mode_or_native_header: true,
|
|
});
|
|
expect(result.limitations).toContain(
|
|
"P/Invoke rows prove managed import declarations only; this inspection does not verify that a native library, export, thunk, or provider-qualified function exists.",
|
|
);
|
|
});
|
|
|
|
it("returns complete member inventories inline and reports unavailable metadata", () => {
|
|
const bytes = buildManagedPeFixture();
|
|
const paged = inspectManagedMembersBytes(
|
|
bytes,
|
|
managedPeFixtureTarget(bytes),
|
|
MANAGED_MEMBER_FIXTURE_LIMITS,
|
|
);
|
|
expect(paged.methods).toHaveLength(1);
|
|
|
|
const nativeBytes = buildNativePeFixture();
|
|
const native = inspectManagedMembersBytes(
|
|
nativeBytes,
|
|
managedPeFixtureTarget(nativeBytes),
|
|
MANAGED_MEMBER_FIXTURE_LIMITS,
|
|
);
|
|
expect(native.metadata.status).toBe("absent");
|
|
expect(native.coverage.state).toBe("unavailable");
|
|
|
|
const malformedBytes = buildManagedPeFixture({
|
|
corruptMetadataSignature: true,
|
|
});
|
|
const malformed = inspectManagedMembersBytes(
|
|
malformedBytes,
|
|
managedPeFixtureTarget(malformedBytes),
|
|
MANAGED_MEMBER_FIXTURE_LIMITS,
|
|
);
|
|
expect(malformed.metadata.status).toBe("malformed");
|
|
expect(malformed.coverage.issues).toEqual([
|
|
expect.objectContaining({ code: "invalid-metadata-root" }),
|
|
]);
|
|
});
|
|
});
|