fix(managed): resolve member ownership through pointer tables (#1886)
Co-authored-by: LouisChen <3361008+chqcjq@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import { managedDecodeBudget } from "./ManagedDecodeBudget.js";
|
||||
import {
|
||||
memberListIndexSize,
|
||||
memberListRowLookup,
|
||||
memberListTable,
|
||||
} from "./ManagedMemberPointers.js";
|
||||
|
||||
import type {
|
||||
ManagedArtifactInspection,
|
||||
@@ -17,7 +22,7 @@ import {
|
||||
readMetadataGuid,
|
||||
readMetadataString,
|
||||
} from "./ManagedMetadataHeaps.js";
|
||||
import { managedFailure } from "./ManagedReaderFailure.js";
|
||||
import { managedFailure, readManagedValue } from "./ManagedReaderFailure.js";
|
||||
import type { ManagedResourceDirectory } from "./ManagedMetadataInventory.js";
|
||||
|
||||
type ModuleIdentity = NonNullable<ManagedArtifactInspection["module"]>;
|
||||
@@ -242,21 +247,24 @@ const declaringTypeForMethod = (
|
||||
heapExtent: number,
|
||||
): string | null => {
|
||||
const types = layout.table(2);
|
||||
const methods = layout.table(6);
|
||||
const methods = memberListTable(layout, 6);
|
||||
if (types === undefined || methods === undefined) return null;
|
||||
if (methodRow < 1 || methodRow > (layout.table(6)?.rowCount ?? 0))
|
||||
return null;
|
||||
const position = memberListRowLookup(bytes, layout, 6)(methodRow);
|
||||
for (let row = 1; row <= types.rowCount; row += 1) {
|
||||
const cursor = metadataRowCursor(bytes, layout, 2, row);
|
||||
cursor.readUInt32();
|
||||
const nameIndex = cursor.readIndex(layout.stringIndexSize);
|
||||
const namespaceIndex = cursor.readIndex(layout.stringIndexSize);
|
||||
cursor.readIndex(layout.codedIndexSize("TypeDefOrRef"));
|
||||
cursor.readIndex(layout.tableIndexSize(4));
|
||||
const methodStart = cursor.readIndex(layout.tableIndexSize(6));
|
||||
cursor.readIndex(memberListIndexSize(layout, 4));
|
||||
const methodStart = cursor.readIndex(memberListIndexSize(layout, 6));
|
||||
const methodEnd =
|
||||
row === types.rowCount
|
||||
? methods.rowCount + 1
|
||||
: methodListForType(bytes, layout, row + 1);
|
||||
if (methodRow < methodStart || methodRow >= methodEnd) continue;
|
||||
if (position < methodStart || position >= methodEnd) continue;
|
||||
const name = readMetadataString(bytes, layout, nameIndex, heapExtent);
|
||||
const namespace = readMetadataString(
|
||||
bytes,
|
||||
@@ -279,8 +287,8 @@ const methodListForType = (
|
||||
cursor.readIndex(layout.stringIndexSize);
|
||||
cursor.readIndex(layout.stringIndexSize);
|
||||
cursor.readIndex(layout.codedIndexSize("TypeDefOrRef"));
|
||||
cursor.readIndex(layout.tableIndexSize(4));
|
||||
return cursor.readIndex(layout.tableIndexSize(6));
|
||||
cursor.readIndex(memberListIndexSize(layout, 4));
|
||||
return cursor.readIndex(memberListIndexSize(layout, 6));
|
||||
};
|
||||
|
||||
const attributeTypeName = (
|
||||
@@ -377,6 +385,7 @@ export const readCustomAttribute = (
|
||||
layout: ManagedMetadataLayout,
|
||||
row: number,
|
||||
heapExtent: number,
|
||||
issues: ManagedParseIssue[],
|
||||
): CustomAttribute => {
|
||||
const cursor = metadataRowCursor(bytes, layout, 12, row);
|
||||
const parentRaw = cursor.readIndex(
|
||||
@@ -432,7 +441,11 @@ export const readCustomAttribute = (
|
||||
: `CustomAttribute constructor coded index 0x${typeRaw.toString(16)} is invalid: ${typeReason}`,
|
||||
typeOffset,
|
||||
);
|
||||
const typeName = attributeTypeName(bytes, layout, typeRaw, heapExtent);
|
||||
const typeName =
|
||||
readManagedValue(
|
||||
() => attributeTypeName(bytes, layout, typeRaw, heapExtent),
|
||||
issues,
|
||||
) ?? null;
|
||||
return {
|
||||
parent_token: parent,
|
||||
constructor_token: metadataCodedToken(
|
||||
|
||||
Reference in New Issue
Block a user