fix(managed): distinguish metadata handles from member accesses (#607)

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Mizrahi Celekli
2026-10-05 14:09:31 -04:00
committed by GitHub
parent adc07f5eaa
commit c73742f300
2 changed files with 28 additions and 0 deletions
+1
View File
@@ -182,6 +182,7 @@ export const edges = (
const fieldAccesses: ManagedFieldAccess[] = [];
for (const method of methods) {
for (const anchor of method.body.anchors) {
if (anchor.opcode === "ldtoken") continue;
if (anchor.operand_kind === "method" && anchor.operand !== null) {
const named =
methodCore.get(anchor.operand)?.name ??
+27
View File
@@ -0,0 +1,27 @@
import { expect, it } from "vitest";
import { inspectManagedMembersBytes } from "./ManagedMemberInspector.js";
import {
buildManagedPeFixture,
managedPeFixtureTarget,
} from "./ManagedPe.fixture.js";
it("retains metadata handles without reporting calls or field accesses", () => {
const il = Buffer.from([
0xd0, 0x01, 0, 0, 0x06, 0x26, 0xd0, 0x01, 0, 0, 0x04, 0x26, 0x28, 0x01, 0,
0, 0x0a, 0x7b, 0x01, 0, 0, 0x04, 0x26, 0x2a,
]);
const bytes = buildManagedPeFixture({
ilBody: Buffer.concat([Buffer.from([(il.length << 2) | 2]), il]),
});
const result = inspectManagedMembersBytes(
bytes,
managedPeFixtureTarget(bytes),
);
expect(
result.methods[0]?.body.anchors.map((anchor) => anchor.opcode),
).toEqual(["ldtoken", "ldtoken", "call", "ldfld"]);
expect(result.call_edges.map((edge) => edge.opcode)).toEqual(["call"]);
expect(result.field_accesses.map((access) => access.opcode)).toEqual([
"ldfld",
]);
});