feat(managed): select declaring types in inspect_managed_members
Select exact declaring types before managed signatures and CIL bodies are decoded, preserving caller choices in CLI/MCP Evidence. Keep unmatched names and selected coverage explicit; comparisons and graphs retain unknowns outside their observed scope. Reuse existing metadata ownership/accounting and advertise unique selections through the actual SDK Schema. Validated with 229 focused tests across 21 files, 11 managed conformance controls, fullstatic/docs checks and real Linux CLI and fresh MCP inspection of two unchanged DLLs. All 118 selected CIL hashes matched original PE-mapped bytes; result/caller-argument parity and unmatched controls passed. Full artifact/native-boundary metadata is complete; whole-assembly members retain the unchanged 64 MiB resource constraint. No target code executes. Refs #1878 Co-authored-by: skared <190618464+skoodster@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com> Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
co-authored by
skared
Claude Opus 5.5
Ysopwnable
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Kaoru0822
parent
f28f338283
commit
a149d183ef
@@ -22,19 +22,25 @@ import {
|
||||
ManagedReaderFailure,
|
||||
uniqueManagedParseIssues,
|
||||
} from "./ManagedReaderFailure.js";
|
||||
import { parseTypes, typeRanges } from "./ManagedMemberInspectorCore.js";
|
||||
import {
|
||||
parseTypes,
|
||||
typeRanges,
|
||||
type TypeRange,
|
||||
} from "./ManagedMemberInspectorCore.js";
|
||||
import {
|
||||
edges,
|
||||
parseExportedTypes,
|
||||
parseFields,
|
||||
parseMemberRefs,
|
||||
parseMethods,
|
||||
type SelectedTypeTokens,
|
||||
} from "./ManagedMemberRows.js";
|
||||
|
||||
const unavailable = (
|
||||
target: BinaryTarget,
|
||||
bytes: Buffer,
|
||||
issue: ManagedParseIssue | null,
|
||||
typeNames: readonly string[] | undefined,
|
||||
): ManagedMemberInspection =>
|
||||
managedMemberInspectionSchema.parse(
|
||||
admitManagedProjection({
|
||||
@@ -67,6 +73,11 @@ const unavailable = (
|
||||
member_refs: [],
|
||||
call_edges: [],
|
||||
field_accesses: [],
|
||||
// Nothing was examined, so no requested name is known to be unmatched.
|
||||
selection:
|
||||
typeNames === undefined
|
||||
? null
|
||||
: { type_names: [...typeNames], unmatched_type_names: [] },
|
||||
coverage: {
|
||||
state: "unavailable",
|
||||
issues: issue === null ? [] : [issue],
|
||||
@@ -105,23 +116,61 @@ const readMemberInventory = (
|
||||
return { layout, inventory };
|
||||
};
|
||||
|
||||
/** Inspect metadata members and method bodies without loading target code. */
|
||||
const selectTypes = (
|
||||
ranges: readonly TypeRange[],
|
||||
typeNames: readonly string[] | undefined,
|
||||
): {
|
||||
readonly tokens: SelectedTypeTokens;
|
||||
readonly selection: ManagedMemberInspection["selection"];
|
||||
readonly unreadableNames: number;
|
||||
} => {
|
||||
if (typeNames === undefined)
|
||||
return { tokens: null, selection: null, unreadableNames: 0 };
|
||||
const requested = new Set(typeNames);
|
||||
const tokens = new Set<string>();
|
||||
const matched = new Set<string>();
|
||||
for (const range of ranges) {
|
||||
if (range.fullName === null || !requested.has(range.fullName)) continue;
|
||||
tokens.add(range.token);
|
||||
matched.add(range.fullName);
|
||||
}
|
||||
return {
|
||||
tokens,
|
||||
unreadableNames: ranges.filter(({ fullName }) => fullName === null).length,
|
||||
selection: {
|
||||
type_names: [...typeNames],
|
||||
unmatched_type_names: typeNames.filter((name) => !matched.has(name)),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Inspect metadata members and method bodies without loading target code.
|
||||
* Selected type names restrict full decoding to members of those exact types.
|
||||
*/
|
||||
export const inspectManagedMembersBytes = (
|
||||
bytes: Buffer,
|
||||
target: BinaryTarget,
|
||||
{ typeNames }: { readonly typeNames?: readonly string[] } = {},
|
||||
): ManagedMemberInspection => {
|
||||
const pe = readManagedPeLayout(bytes);
|
||||
if (pe.cli === null) return unavailable(target, bytes, pe.cliIssue);
|
||||
if (pe.cli === null)
|
||||
return unavailable(target, bytes, pe.cliIssue, typeNames);
|
||||
const issues: ManagedParseIssue[] = [];
|
||||
try {
|
||||
const { layout, inventory } = readMemberInventory(bytes, pe, issues);
|
||||
issues.push(...inventory.issues);
|
||||
const ranges = typeRanges(bytes, layout, issues);
|
||||
const {
|
||||
tokens: selected,
|
||||
selection,
|
||||
unreadableNames,
|
||||
} = selectTypes(ranges, typeNames);
|
||||
const parsedTypes = parseTypes(bytes, layout, ranges);
|
||||
issues.push(...parsedTypes.issues);
|
||||
const exportedTypes = parseExportedTypes(bytes, layout);
|
||||
issues.push(...exportedTypes.issues);
|
||||
const fields = parseFields(bytes, layout, ranges);
|
||||
const fields = parseFields(bytes, layout, ranges, selected);
|
||||
const memberRefs = parseMemberRefs(bytes, layout);
|
||||
issues.push(...memberRefs.issues);
|
||||
const methods = parseMethods({
|
||||
@@ -129,6 +178,7 @@ export const inspectManagedMembersBytes = (
|
||||
layout,
|
||||
pe,
|
||||
ranges,
|
||||
selected,
|
||||
});
|
||||
issues.push(...fields.issues, ...methods.issues);
|
||||
const coverageIssues = uniqueManagedParseIssues(issues);
|
||||
@@ -168,13 +218,17 @@ export const inspectManagedMembersBytes = (
|
||||
requires_artifact_sha256: target.sha256,
|
||||
requires_mvid: inventory.module?.mvid ?? null,
|
||||
},
|
||||
types: parsedTypes.types,
|
||||
types:
|
||||
selected === null
|
||||
? parsedTypes.types
|
||||
: parsedTypes.types.filter((type) => selected.has(type.token)),
|
||||
exported_types: exportedTypes.exportedTypes,
|
||||
fields: fields.fields,
|
||||
methods: methods.methods,
|
||||
member_refs: memberRefs.refs,
|
||||
call_edges: related.callEdges,
|
||||
field_accesses: related.fieldAccesses,
|
||||
selection,
|
||||
coverage: {
|
||||
state:
|
||||
issues.length === 0 && !incompleteMembers
|
||||
@@ -187,6 +241,16 @@ export const inspectManagedMembersBytes = (
|
||||
"CIL instruction anchors are decoded from file-backed method bodies only; no target assembly is loaded or executed.",
|
||||
"Exported types are reported from ExportedType rows as declared; forwarded types are not resolved in their implementing assemblies.",
|
||||
"Member signatures decode ECMA-335 primitive, class, valuetype, generic instantiation, generic variable, pointer, byref, single-dimension and general array, function pointer, custom modifier, and typed reference forms; class and valuetype operands keep their encoded TypeDefOrRefOrSpec values, and unsupported forms such as vararg sentinels retain raw signature hashes.",
|
||||
...(selection === null
|
||||
? []
|
||||
: [
|
||||
"Types, fields, methods, call edges, and field accesses cover only the selected declaring types; coverage describes that selection. Edge targets outside it keep their names but are not described.",
|
||||
]),
|
||||
...(unreadableNames === 0
|
||||
? []
|
||||
: [
|
||||
`${String(unreadableNames)} TypeDef name(s) could not be read; a name in selection.unmatched_type_names may belong to one of them, so its absence is not observed.`,
|
||||
]),
|
||||
],
|
||||
},
|
||||
managedDecodeBudget(layout),
|
||||
@@ -194,7 +258,7 @@ export const inspectManagedMembersBytes = (
|
||||
);
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof ManagedReaderFailure)
|
||||
return unavailable(target, bytes, cause.issue);
|
||||
return unavailable(target, bytes, cause.issue, typeNames);
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user