mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 17:44:27 +00:00
* fix(managed)!: report an unsupported signature as partial metadata, not malformed The refusal path already treats `unsupported-signature` as a valid form outside decoder coverage, but `managedMetadataFailureStatus` still called it malformed. One predicate, `isManagedCoverageGap`, now owns that split for both the refusal and the inventory status. Value retention no longer reads the inventory status: one value's unsupported signature is still retained locally, while a budget or an unsupported metadata layout still stops the whole read. BREAKING CHANGE: when a managed reader stops on `unsupported-signature`, `metadata.status` is `partial` (was `malformed`) in managed artifact, member and native-boundary inspection, and the artifact `classification.status` is `managed` (was `malformed`). The field names and enum members are unchanged. * fix(il2cpp)!: refuse a reused or non-MethodDef token as malformed metadata `invalid-method-token` covered two facts. A MethodDef row reused within one image, or a token that is not a nonzero MethodDef row, is in the metadata's own records; a row past the module's method pointers is a disagreement between two files that both parse. The metadata reader now checks each image's tokens while reading link facts and raises `invalid-method-definition-token`, which the provider already refuses as a malformed target at the metadata's path. The linker keeps `invalid-method-token` for the cross-file range check only and drops its own duplicate scan. BREAKING CHANGE: a duplicate or non-MethodDef method token found while linking is `unsupported_target` with `details.path` the metadata file, `details.format` `il2cpp-metadata`, `details.format_failure` `malformed` and `details.reason` starting `invalid-method-definition-token:` (was an `invalid_request` link conflict naming `path` and `binary_path` with reason `invalid-method-token`). A token past the module's method pointers keeps the conflict and the `invalid-method-token` reason.
118 lines
3.5 KiB
TypeScript
118 lines
3.5 KiB
TypeScript
import type { BinaryReader } from "../domain/binaryContainer.js";
|
|
/** Stable machine-readable reason for each rejected input. */
|
|
export const IL2CPP_METADATA_FAILURE_REASONS = {
|
|
unsupported: ["unrecognized-magic", "unsupported-version"],
|
|
corrupt: [
|
|
"truncated-header",
|
|
"unexpected-header-size",
|
|
"section-out-of-bounds",
|
|
"section-overlap",
|
|
"record-size-mismatch",
|
|
"type-index-width",
|
|
"index-out-of-range",
|
|
"nested-type-conflict",
|
|
"declaring-type-mismatch",
|
|
"image-range-overlap",
|
|
"invalid-string",
|
|
"invalid-method-definition-token",
|
|
],
|
|
} as const;
|
|
export type Il2cppMetadataFailureReason =
|
|
(typeof IL2CPP_METADATA_FAILURE_REASONS)[keyof typeof IL2CPP_METADATA_FAILURE_REASONS][number];
|
|
|
|
/** The ParseFailure format of an IL2CPP `global-metadata.dat`. */
|
|
export const IL2CPP_METADATA_FORMAT = "il2cpp-metadata";
|
|
|
|
const metadataFailure = (
|
|
reason: Il2cppMetadataFailureReason,
|
|
detail: string,
|
|
): ParseFailure & {
|
|
readonly kind: "malformed" | "truncated" | "unsupported";
|
|
} =>
|
|
(IL2CPP_METADATA_FAILURE_REASONS.unsupported as readonly string[]).includes(
|
|
reason,
|
|
)
|
|
? {
|
|
kind: "unsupported",
|
|
format: IL2CPP_METADATA_FORMAT,
|
|
detail,
|
|
undecodedContent: false,
|
|
}
|
|
: {
|
|
kind: reason === "truncated-header" ? "truncated" : "malformed",
|
|
format: IL2CPP_METADATA_FORMAT,
|
|
detail,
|
|
};
|
|
|
|
/**
|
|
* Distinguish inputs outside decoder coverage from damaged metadata. The
|
|
* stable `reason` names the IL2CPP rule the bytes broke.
|
|
*/
|
|
export class Il2cppMetadataFormatFailure extends ParseFailureError<
|
|
"malformed" | "truncated" | "unsupported"
|
|
> {
|
|
constructor(
|
|
readonly reason: Il2cppMetadataFailureReason,
|
|
message: string,
|
|
options?: ErrorOptions,
|
|
) {
|
|
super(metadataFailure(reason, `${reason}: ${message}`), options);
|
|
this.name = "Il2cppMetadataFormatFailure";
|
|
}
|
|
}
|
|
|
|
/** Validate a section against a known serialized record width once. */
|
|
export const checkedSectionCount = (
|
|
section: Il2cppMetadataSection,
|
|
recordBytes: number,
|
|
): number => {
|
|
if (section.size % recordBytes !== 0)
|
|
throw new Il2cppMetadataFormatFailure(
|
|
"record-size-mismatch",
|
|
`section ${section.name} size ${section.size} is not a whole multiple of its ${recordBytes}-byte records`,
|
|
);
|
|
const count = section.size / recordBytes;
|
|
if (section.count !== null && count !== section.count)
|
|
throw new Il2cppMetadataFormatFailure(
|
|
"record-size-mismatch",
|
|
`section ${section.name} size ${section.size} does not hold ${section.count} ${recordBytes}-byte records`,
|
|
);
|
|
return count;
|
|
};
|
|
|
|
export const checkRange = (
|
|
label: string,
|
|
start: number,
|
|
length: number,
|
|
total: number,
|
|
) => {
|
|
if (length === 0 && start >= -1 && start <= total) return;
|
|
if (start < 0 || start + length > total)
|
|
throw new Il2cppMetadataFormatFailure(
|
|
"index-out-of-range",
|
|
`${label} range [${start}, ${start + length}) is outside the ${total} available entries`,
|
|
);
|
|
};
|
|
|
|
/** Read a serialized index; the all-ones value of narrow widths means -1. */
|
|
export const readIndex = (
|
|
reader: BinaryReader,
|
|
offset: number,
|
|
width: 1 | 2 | 4,
|
|
) => {
|
|
if (width === 1) {
|
|
const value = reader.u8(offset);
|
|
return value === 0xff ? -1 : value;
|
|
}
|
|
if (width === 2) {
|
|
const value = reader.u16(offset);
|
|
return value === 0xffff ? -1 : value;
|
|
}
|
|
return reader.i32(offset);
|
|
};
|
|
import type { Il2cppMetadataSection } from "../domain/il2cpp/il2cppMetadata.js";
|
|
import {
|
|
ParseFailureError,
|
|
type ParseFailure,
|
|
} from "../domain/parseFailure.js";
|