mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 09:56:23 +00:00
* feat(errors)!: add the TargetFailure model, its projection table and conformance registry Introduce one domain-owned TargetFailure value whose kind alone derives the public code, category, retryability, recovery and details, for CLI and MCP alike. Selected-file malformed and truncated refusals are the first area on it: AnalysisMalformedTargetError is replaced by AnalysisTargetFailureError, and ParseFailure's byte-structure variants are TargetFailure variants rather than a parallel type. The shared stableArtifactParserFailureCli loop is replaced by a declarative registry (tests/support/targetFailure/readers/*.ts) and one generated suite that runs every registered case through the CLI and MCP. BREAKING CHANGE: selected-file malformed and truncated refusals add details.failure_kind, and a truncated target's remediation now says to re-acquire the complete file instead of choosing another target. Codes are unchanged. Affected operations: every operation that refuses a selected file's malformed or truncated bytes, including the ELF, PE, Mach-O, DWARF, Go, Rust, BEAM, pyc, devicetree, Apple IPS, kernel module, binary hardening, managed PE/CLI and IL2CPP readers. * test(managed): name the target failure error in the merged status test * docs(reference): name the error CSV instead of linking a non-page file * fix(tests): expect the path reason for non-regular dyld inputs #14225 refuses a non-regular dyld input as ArtifactReaderFailure("path"); dylibFileLifetime still expected "format" and fails on main's shard 9. * fix(tests): expect io, invariant and path where #14225 reclassified stableArtifact expected "format" for an impossible descriptor byte count (now io) and an invalid chunk size (now InternalInvariantError); directoryArtifactReaderOpen expected "format" for a non-file entry (now path, the same change as #14238). All three fail on main. * fix(errors)!: raise container reader byte faults as malformed or truncated targets Delete the ambiguous `format` reason from ArtifactReaderFailure and ArtifactOperationError. Each container reader now raises its owner's fact once, through malformedArtifact / truncatedArtifact, with format, offset, field and measured extents. Short reads inside a measured extent are read-coverage integrity failures, path-kind refusals are `path`, foreign or recovery-requiring inputs are `unsupported`, host tool output is `io`, and REA defects are InternalInvariantError. The trace, NTFS journal, release exposure, web capture, native macOS and web artifact adapters project the reader's parsed facts as AnalysisTargetFailureError instead of invalid_request. Inventory malformed, truncated, unsupported and cancelled reasons take their code from the TargetFailure projection table, so a truncated container is unsupported_target with failure_kind "truncated" on both paths. BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact, analyze_javascript_application, inspect_desktop_application, inspect_keyed_archive, inspect_asset_catalog, inspect_nuget_nupkg, trace_dylib_resolution, trace_web_module_imports and trace_web_source_location report damaged container bytes as unsupported_target (details.reason "malformed" or "truncated", with failure_kind and format) instead of artifact_operation_failed with reason "format", and a truncated container as unsupported_target instead of truncated. inspect_playwright_trace, inspect_ntfs_journal, audit_release_exposure, the web capture inspection operations and the caller-selected import and source maps report damaged selected bytes as unsupported_target instead of invalid_request. The `format` reason no longer appears in details.reason. * test(artifacts): expect target failure codes in compiled CLI and MCP suites * fix(errors)!: refuse malformed SQLite, pwntools and EVM inputs as target failures The SQLite engine's `format` reason is renamed to `malformed` at its owner (SQLITE_INSPECTION_REASONS), and its refusal becomes an AnalysisTargetFailureError at the selected path with format "sqlite". The pwntools and EVM worker replies keep their wire reason "format", which their workers define, and the adapters translate it once into a malformed target failure with the profile's format (elf, elf-core, evm-bytecode) instead of an invalid_format argument issue. SQLite joins the target-failure conformance registry. BREAKING CHANGE: inspect_sqlite_database, inspect_binary_layout, inspect_recorded_crash and inspect_evm_interface report a selected file's malformed bytes as unsupported_target with details.failure_kind "malformed", format_failure, format and path, instead of invalid_request with an invalid_format issue on path. * fix(errors): give the integrity kind a schema-valid code and list the reference page artifact_integrity_mismatch's projection schema requires declared and calculated digests, which a TargetFailure of kind integrity does not carry, so the kind now projects artifact_operation_failed with category integrity_mismatch. The model test validates every kind's projection against analysisErrorProjectionSchema. The reference page joins the documentation sidebar. * fix(artifacts): report a short carrier read as a changed file and keep unsupported desktop probes local A Bun or Node SEA short read inside a range already checked against the measured size meant the file changed, not that it was truncated. The carrier range reader and Bun's readExact now raise read-coverage integrity for it, and keep 'outside the file' as the truncated case. DesktopFileInspection records an unsupported managed-metadata probe as a row issue again, so later file checks still run. * test(errors): expect target failure facts in the pwntools and EVM reply suites The literal-replacement scenario now reads the failure's detail instead of an issues[] message, and a malformed reply wrapped by cleanup failure reports category unsupported_target. * test(errors): register PE DOS-signature and truncated IPS refusals and drop their per-command copies The non-MZ PE imports and load-config cases (PE32/PE32+, ZZ and high-bit signatures) and the truncated Apple IPS body move into the conformance registry, which runs them through the CLI and MCP and now also checks that a refusal leaves the selected file unchanged. The per-command tests keep only their valid-image controls. * test(sqlite): drop the malformed-database provider test the conformance registry covers inspect_sqlite_database/not-a-database in the target-failure registry runs the same non-SQLite bytes through the CLI and MCP, asserts the malformed target facts and checks the selected file is unchanged. * feat(errors)!: make failure_kind the identifier and derive code and retry from it Apply the owner review on #14239 to the TargetFailure model: - remove details.format_failure; failure_kind is the only identifier; - give integrity, conflict and io their own codes (target_integrity_mismatch, input_conflict, host_io_failed) and derive inventory malformed, truncated and unsupported codes from the same table; - add a retry hint (none, backoff, after_change) derived from the kind, with io refined by its transient errno fact; retryable stays the unchanged-retry flag and is true exactly for backoff; - rename the limit-cut result code and category truncated to partial; - drop cancelled and resource from the target kinds and spell identifiers in American English (unrecognized); - return a target failure a tool handler throws as a projected isError result instead of letting the SDK flatten it to text. BREAKING CHANGE: details.format_failure is removed (read details.failure_kind). The truncated result code and category are now partial. Target integrity failures report target_integrity_mismatch, host read failures host_io_failed and disagreeing inputs input_conflict. Inventory operations (inventory_artifact, inspect_artifact, extract_artifact and the other inventory callers) report truncated container bytes as unsupported_target. Every target failure carries a top-level retry hint. * test(sqlite): expect a malformed target for non-database bytes in the CLI suite * fix(artifacts): keep changed-file short reads, invalid offsets and EOF declarations apart PyInstaller reads inside the measured size, and .NET bundle manifest refills, now raise read-coverage integrity on a zero-byte read instead of truncated. A .NET bundle field and a Godot PCK directory entry that extend past the file are truncated (with offset and extents) instead of malformed. An absent or invalid ASAR packed offset is malformed; only a valid range past the archive is truncated. The .NET manifest string offset is reported in file coordinates. * fix(pwntools): report a short ELF header as a truncated target The layout and recorded-crash workers raise a distinct truncated reason when the file ends inside the ELF identification or header, and the decoder projects it as failure_kind truncated instead of inferring it from the message. * fix(errors)!: report managed coverage gaps and IL2CPP pair conflicts as target failures Managed readers interpret an issue code once, in managedIssueTargetFailure: a coverage gap is an unsupported target, every other rule violation is a malformed target, and the inventory metadata status is derived from that same fact. managedInspectionTargetFailure now returns only AnalysisTargetFailureError. An IL2CPP binary that parses but does not link to its metadata is a conflict target failure that lists both inputs and blames neither, in place of an invalid_request with two issue entries. Metadata version 108 is an unsupported target. The CLI spells each conflict input's field by the command's option name. BREAKING CHANGE: inspect_managed_artifact, inspect_managed_members, inspect_managed_native_boundaries and the managed comparison operations report unsupported metadata or signature forms as an AnalysisTargetFailureError (failure_kind unsupported, format pe-cli, field, offset) instead of a bare unsupported target. inspect_il2cpp_metadata reports a binary/metadata pair that does not link as code input_conflict with failure_kind conflict and details.inputs, instead of invalid_request with details.issues, and metadata version 108 with failure_kind unsupported. * fix(artifacts): verify the carrier before blaming a short read on the bytes The NTFS $MFT decoder, positional members (FIT, uImage, Bun, Deno) and .NET bundle members now re-verify the source before reporting a short stream as malformed, so a file that changed during the read reports the change. The truncation site builds the model's measured extent. * fix(errors)!: report inventory refusals as target failures of the selected path An inventory, inspection or extraction refused damaged or unsupported container bytes as an ArtifactOperationError whose reason repeated the format owner's kind. It carried no path or retry hint, so the conformance registry could not express container cases. translateArtifactFailure now takes the selected path and returns the reader's TargetFailure as an AnalysisTargetFailureError. The malformed, truncated and unsupported reasons, their classification rows and their presentation branch are deleted from ArtifactOperationError. Readers' unsupported refusals carry their format facts through unsupportedArtifact. Container cases move into the conformance registry, which now opens the target first for session tools such as inspect_artifact. BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact and the bundle readers report a refused container as a target failure of details.path with a top-level retry. details.reason is the owner's description and details.detail is removed. * docs(il2cpp): describe pair conflicts as input_conflict with both inputs * docs(android): name unsupported_target for truncated boot image structures * fix(errors)!: report a target that changed during the read as failure_kind changed Inventory integrity failures whose check means the target moved under the read (container, member and unpacked-entry identity, read coverage, traversal coverage) now take the model's changed projection: code artifact_changed, retry backoff and details.failure_kind changed. A selected target that no longer matches the one the session admitted gets its own admitted-identity check and keeps its reopen recovery. BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact and the other inventory operations report a target that changed during the read as artifact_changed (retryable, failure_kind changed) instead of artifact_operation_failed. Admission-identity refusals report integrity_check admitted-identity instead of container-identity. * test(artifacts): raise the cleanup fixture's decode refusal with its format facts * fix(errors)!: report unsupported and unrecognized targets on the TargetFailure model AnalysisUnsupportedTargetError carried a free-text reason and remediation beside the TargetFailure model, so unsupported refusals had no format, failure_kind or retry hint, and their recovery was prose written at each producer. The class is deleted. Producers raise unsupportedTarget or unrecognizedTarget with the owner's format, and consumers read targetFailureOfKind. The projection table renders the recovery and names the operations the owner lists in related.operations. The foreign-bytes identity loop moves into the conformance registry. BREAKING CHANGE: unsupported and unrecognized targets report failure_kind, format and retry. Their remediation comes from the target-failure table; producer-written remediation sentences are folded into details.reason or replaced by details.related_operations. * test(artifacts): expect admitted-identity for selections replaced before admission A selected source replaced before admission fails the admitted-identity check rather than container-identity since the changed/admitted split. * test(go): name the fixture and result when an MZ carrier is not refused through MCP * style: format the migrated target-failure tests * test(errors): expect the PE readers' native-binary format label for foreign bytes * test(verify): expect target failures for damaged ELF, core and EVM inputs in real-provider verifiers The binary-layout, recorded-crash and EVM verifiers still expected invalid_input for malformed or truncated selected bytes. The pwntools and EVM adapters now report those as unsupported_target with failure_kind; a missing path remains invalid_input. * test(web): expect the partial code for a refused source-map admission The limit-cut code is partial; this Windows-lane test arrived from main with the old truncated spelling. * fix(artifacts): keep refusal facts on DMG verdicts and the selected bundle path hdiutil's "image not recognized" verdict raised the unsupported reason without the owner's facts, so the inventory translation treated it as a reader defect. It now carries an unsupported dmg target failure, and the reader-failure constructor requires facts for every target reason. A bundle resource refusal names the caller's selected bundle path rather than its resolved target. The real-provider verifiers and the Android, source-location acceptance tests expect the model's target-failure categories and codes. * test(errors): assert unsupported refusals' kind and format, and align verifiers and the Electron guide * test(errors): check the MCP target failure as the text clients receive The stdio transport removes the private structured carrier from every isError result, so the conformance suite asserted a field that never reaches clients and failed every case. The projected diagnostic is checked from the JSON text instead. * test(errors): raise main's new unsupported-target fixtures through the model * test(artifacts): expect artifact_changed when selected bytes change after inventory Bundle resources replaced after open and unselected JavaScript sources rewritten after inventory now fail a change check, so they report artifact_changed with retry backoff rather than artifact_operation_failed. * fix(errors): report a session digest mismatch as admitted-identity The digest the session admitted does not change when the same request is repeated, so targetDigestChangedFailure was inviting a backoff retry that fails the same way. It now names admitted-identity, which stays artifact_operation_failed and not retryable, and tells the caller to reopen. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(artifacts): classify unused PyInstaller compressed input as layout zlib stops at the first complete stream, so a declared span that arrives intact but is not fully consumed is trailing junk or a second stream, not a file that changed. A source that ends before that span stays read-coverage. The cached-carrier test replaces the file with a different size so a shared timestamp cannot hide the rewrite. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(applications): expect unsupported_target for a damaged trace stream A trace member whose CRC fails is a malformed zip target. The partial Evidence assertion now checks that code, failure_kind and format. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(artifacts): assert Android refusal kinds and drop the SEA registry case details.reason is the owner's description, so the boot-image refusals assert failure_kind and format. A malformed SEA blob inside an ELF stays an outer-format inventory with a recognition limitation, which the Node SEA reader tests already cover, so it is not an inspect_artifact refusal. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(artifacts): pass the selected path into translated target failures translateArtifactFailure names the caller-selected path on a format refusal. Directory inspection and a retained artifact scope both know that path and now supply it. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(artifacts): charge global pax records against the tar metadata budget Repeated pax global headers were copied into one map without a charge, so each header could stay inside the extended-header allowance while the map grew without a bound. The retained metadata budget is charged for the merged map's keys, values and entries before that map is allocated. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(dylib): expect admitted-identity when the opened target is replaced The session keeps the digest it admitted, so replacing the executable and repeating trace_dylib_resolution is not a retryable container change. Co-authored-by: morluto <morluto@users.noreply.github.com> * style: format the inventory path translation and conformance suite * fix(artifacts): keep the unsupported-target migration in files the inventory merge replaced * test(errors): expect target failures for ZIP inventory refusals and input_conflict for an unlinked IL2CPP pair * test(artifacts): expect a malformed target failure for an ISO 9660 directory cycle * test(web): expect a malformed target failure on the captured source path * test(artifacts): expect a malformed ZIP target failure for a corrupt Zstandard member * test(javascript): read the owner's input facts from details.reason and recovery from the projection * test(iso9660): assert the malformed target failure fields details.reason is the owner's description. The compiled CLI refusal is identified by failure_kind and format. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(errors): assert selection and unsupported view fields A desktop root that is not a directory is a selection failure, so the CLI reports invalid_request. An analysis view the parent cannot supply is unsupported evidence; the tests read failure_kind, format, field and related_operations. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(errors): keep binary plist UID facts on unsupported targets Pass the reader's UnsupportedBinaryPlistUidError failure through instead of rebuilding a bplist refusal that drops field and undecodedContent. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(errors): keep oversized binary plist UID facts on keyed archives Assert the reader projects format, field, and undecoded content from the parser failure instead of a rebuilt bplist refusal. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
1344 lines
48 KiB
TypeScript
1344 lines
48 KiB
TypeScript
import { setImmediate } from "node:timers/promises";
|
|
import { createHash } from "node:crypto";
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { zstdCompressSync } from "node:zlib";
|
|
import { afterEach, expect, it, vi } from "vitest";
|
|
import { withVerifierCleanup } from "../../../scripts/lib/verifier-cleanup.mjs";
|
|
import {
|
|
AnalysisCancelledError,
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisResourceConstraintError,
|
|
AnalysisTargetFailureError,
|
|
} from "../../../src/domain/analysisErrorCore.js";
|
|
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
|
import { Il2cppMetadataProvider } from "../../../src/il2cpp/Il2cppMetadataProvider.js";
|
|
import { inspectIl2cppMetadataV108 } from "../../../src/il2cpp/Il2cppMetadataV108.js";
|
|
import { Il2cppGhidraSeedWriter } from "../../../src/il2cpp/Il2cppGhidraSeedWriter.js";
|
|
import { Il2cppMetadataService } from "../../../src/application/il2cpp/Il2cppMetadataService.js";
|
|
import {
|
|
il2cppMetadataSchema,
|
|
inspectIl2cppMetadataInputSchema,
|
|
} from "../../../src/domain/il2cpp/il2cppMetadata.js";
|
|
import * as zstandard from "../../../src/domain/compression/zstandardExactFrame.js";
|
|
import {
|
|
createElfFixture,
|
|
createIl2cppBinaryFixture,
|
|
FIXTURE_GENERIC_INSTANCES,
|
|
FIXTURE_METHOD_ADDRESSES,
|
|
} from "../../fixtures/il2cpp/binary.js";
|
|
import {
|
|
createIl2cppMetadataFixture,
|
|
createLinkedIl2cppMetadataFixture,
|
|
} from "../../fixtures/il2cpp/metadata.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { phaseGate } from "../../support/lifecycleHarness.js";
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
/** One-shot inspections keep the real reader's cleanup at one test boundary. */
|
|
const inspectMetadata = async (path: string, limit?: number) => {
|
|
const provider = new Il2cppMetadataProvider(limit);
|
|
try {
|
|
return await provider.inspect({ path });
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
};
|
|
|
|
it("identifies which selected IL2CPP file is missing", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-missing-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "missing-binary");
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const missingMetadata = await provider.inspect({ path });
|
|
if (missingMetadata.ok)
|
|
throw new Error("Expected missing metadata failure");
|
|
expect(missingMetadata.error).toMatchObject({
|
|
_tag: "AnalysisInputError",
|
|
issues: [{ path: ["path"], reason: "invalid_value" }],
|
|
});
|
|
|
|
await writeFile(path, createIl2cppMetadataFixture({ version: 31 }).bytes);
|
|
const missingBinary = await provider.inspect({
|
|
path,
|
|
binary_path: binaryPath,
|
|
});
|
|
if (missingBinary.ok) throw new Error("Expected missing binary failure");
|
|
expect(missingBinary.error).toMatchObject({
|
|
_tag: "AnalysisInputError",
|
|
issues: [{ path: ["binary_path"], reason: "invalid_value" }],
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
/** Synthetic v108 header: checks bounded observations, not record-layout compatibility. */
|
|
const version108Header = (stringBytes: Buffer) => {
|
|
const header = Buffer.alloc(500);
|
|
header.writeUInt32LE(0xfab11baf, 0);
|
|
header.writeInt32LE(108, 4);
|
|
let cursor = header.length;
|
|
for (let index = 0; index < 41; index++) {
|
|
const size = index === 2 ? stringBytes.length : 0;
|
|
header.writeInt32LE(cursor, 8 + index * 12);
|
|
header.writeInt32LE(size, 12 + index * 12);
|
|
header.writeInt32LE(size, 16 + index * 12);
|
|
cursor += size;
|
|
}
|
|
return Buffer.concat([header, stringBytes]);
|
|
};
|
|
|
|
it("retains a bounded v108 header and string observation without claiming decoded rows", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-v108-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, version108Header(Buffer.from("Alpha\0Beta\0")));
|
|
const result = await inspectMetadata(path);
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
normalized_result: {
|
|
inventory_status: "not-returned-as-complete",
|
|
version_108_partial_inventory: {
|
|
metadata_version: 108,
|
|
header_bytes: 500,
|
|
coverage: "header-and-bounded-string-sample-only",
|
|
sections: expect.arrayContaining([
|
|
{ name: "stringLiterals", offset: 500, size: 0, count: 0 },
|
|
{ name: "stringLiteralData", offset: 500, size: 0, count: 0 },
|
|
{ name: "strings", offset: 500, size: 11, count: 11 },
|
|
]),
|
|
strings: {
|
|
terminated_count: 2,
|
|
unterminated_tail_bytes: 0,
|
|
sample: [
|
|
{ offset: 0, value: "Alpha", truncated: false },
|
|
{ offset: 6, value: "Beta", truncated: false },
|
|
],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
expect(JSON.stringify(result.error.partialObservation)).not.toContain(
|
|
'"images":[]',
|
|
);
|
|
});
|
|
|
|
it("accepts padding after the assumed v108 header", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-v108-padding-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const bytes = version108Header(Buffer.from("Name\0"));
|
|
const padded = Buffer.concat([
|
|
bytes.subarray(0, 500),
|
|
Buffer.alloc(16),
|
|
bytes.subarray(500),
|
|
]);
|
|
for (let index = 0; index < 41; index++) {
|
|
padded.writeInt32LE(bytes.readInt32LE(8 + index * 12) + 16, 8 + index * 12);
|
|
}
|
|
await writeFile(path, padded);
|
|
const result = await inspectMetadata(path);
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error).toMatchObject({
|
|
_tag: "AnalysisTargetFailureError",
|
|
failure: { kind: "unsupported", format: "il2cpp-metadata" },
|
|
});
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
normalized_result: {
|
|
version_108_partial_inventory: {
|
|
strings: { sample: [{ value: "Name" }] },
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"extends past the file",
|
|
(bytes: Buffer) => {
|
|
bytes.writeInt32LE(bytes.length + 1, 12 + 2 * 12);
|
|
},
|
|
/assumed section strings .* is invalid/,
|
|
],
|
|
[
|
|
"starts inside the header",
|
|
(bytes: Buffer) => {
|
|
bytes.writeInt32LE(499, 8 + 2 * 12);
|
|
},
|
|
/assumed section strings .* is invalid/,
|
|
],
|
|
[
|
|
"overlaps another section",
|
|
(bytes: Buffer) => {
|
|
bytes.writeInt32LE(501, 8 + 3 * 12);
|
|
bytes.writeInt32LE(1, 12 + 3 * 12);
|
|
},
|
|
/assumed sections strings and events overlap at 501/,
|
|
],
|
|
])(
|
|
"retains source evidence when a v108 section %s",
|
|
async (_name, mutate, reason) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-v108-invalid-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const bytes = version108Header(Buffer.from("Name\0"));
|
|
mutate(bytes);
|
|
await expect(inspectIl2cppMetadataV108(bytes)).rejects.toMatchObject({
|
|
reason: "unsupported-version",
|
|
message: expect.stringMatching(reason),
|
|
});
|
|
await writeFile(path, bytes);
|
|
const result = await inspectMetadata(path);
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(result.error).toBeInstanceOf(AnalysisTargetFailureError);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
normalized_result: { artifact: { path, bytes: bytes.length } },
|
|
});
|
|
expect(JSON.stringify(result.error.partialObservation)).not.toContain(
|
|
"version_108_partial_inventory",
|
|
);
|
|
},
|
|
);
|
|
|
|
it("bounds v108 string samples and preserves undecodable bytes and leading BOMs", async () => {
|
|
const repeated = await inspectIl2cppMetadataV108(
|
|
version108Header(Buffer.from("x\0".repeat(20))),
|
|
);
|
|
expect(repeated?.strings.terminated_count).toBe(20);
|
|
expect(repeated?.strings.sample).toHaveLength(16);
|
|
const invalid = await inspectIl2cppMetadataV108(
|
|
version108Header(Buffer.from([0xff, 0])),
|
|
);
|
|
expect(invalid?.strings.sample).toEqual([
|
|
{ offset: 0, value: null, value_base64: "/w==", truncated: false },
|
|
]);
|
|
const bom = await inspectIl2cppMetadataV108(
|
|
version108Header(Buffer.from([0xef, 0xbb, 0xbf, 0x41, 0])),
|
|
);
|
|
expect(bom?.strings.sample).toEqual([
|
|
{ offset: 0, value: "\uFEFFA", value_base64: null, truncated: false },
|
|
]);
|
|
});
|
|
|
|
it("yields during a large v108 string scan and honors cancellation before evidence", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-v108-cancel-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, version108Header(Buffer.alloc(128 * 1024, 65)));
|
|
const controller = new AbortController();
|
|
let batches = 0;
|
|
const provider = new Il2cppMetadataProvider(undefined, async () => {
|
|
batches++;
|
|
controller.abort("cancel v108 scan");
|
|
await setImmediate();
|
|
});
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path },
|
|
{ signal: controller.signal },
|
|
);
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
expect(batches).toBe(1);
|
|
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(JSON.stringify(result.error.partialObservation)).not.toContain(
|
|
"version_108_partial_inventory",
|
|
);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
/** Version 29 file whose methods all share one long name. */
|
|
const sharedNameMetadata = (
|
|
nameBytes: number | Buffer,
|
|
methods: number,
|
|
fill = 0x41,
|
|
) => {
|
|
const encoded = Buffer.isBuffer(nameBytes)
|
|
? nameBytes
|
|
: Buffer.alloc(nameBytes, fill);
|
|
const name = Buffer.concat([encoded, Buffer.from([0])]);
|
|
const records = Buffer.alloc(methods * 32);
|
|
for (let index = 0; index < methods; index += 1)
|
|
records.writeInt32LE(-1, index * 32 + 4);
|
|
const header = Buffer.alloc(256);
|
|
header.writeUInt32LE(0xfab11baf, 0);
|
|
header.writeInt32LE(29, 4);
|
|
let cursor = 256;
|
|
for (let section = 0; section < 31; section += 1) {
|
|
// strings is section 2 and methods is section 5.
|
|
const content = section === 2 ? name : section === 5 ? records : undefined;
|
|
header.writeInt32LE(cursor, 8 + section * 8);
|
|
header.writeInt32LE(content?.length ?? 0, 12 + section * 8);
|
|
cursor += content?.length ?? 0;
|
|
}
|
|
return Buffer.concat([header, name, records]);
|
|
};
|
|
|
|
/** Fixed-width metadata whose literals share one span; no target code is involved. */
|
|
const sharedLiteralMetadata = (literalBytes: Buffer, count: number) => {
|
|
const header = Buffer.alloc(256),
|
|
records = Buffer.alloc(count * 8);
|
|
header.writeUInt32LE(0xfab11baf, 0);
|
|
header.writeInt32LE(29, 4);
|
|
for (let i = 0; i < count; i++)
|
|
records.writeUInt32LE(literalBytes.length, i * 8);
|
|
let cursor = 256;
|
|
for (let section = 0; section < 31; section++) {
|
|
const size =
|
|
section === 0 ? records.length : section === 1 ? literalBytes.length : 0;
|
|
header.writeInt32LE(cursor, 8 + section * 8);
|
|
header.writeInt32LE(size, 12 + section * 8);
|
|
cursor += size;
|
|
}
|
|
return Buffer.concat([header, records, literalBytes]);
|
|
};
|
|
|
|
it("bounds repeated literal output during decoding and reuses one span instead of allocating every repetition", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-literals-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, sharedLiteralMetadata(Buffer.alloc(4096, 65), 20));
|
|
const decode = vi.spyOn(TextDecoder.prototype, "decode");
|
|
const result = await inspectMetadata(path, 12_000);
|
|
if (result.ok) throw new Error("Expanded literals accepted");
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
normalized_result: {
|
|
validated_section_row_counts: { string_literals: 20 },
|
|
},
|
|
});
|
|
expect(
|
|
decode.mock.calls.filter(([bytes]) => bytes?.byteLength === 4096),
|
|
).toHaveLength(1);
|
|
});
|
|
|
|
it("refuses raw literal expansion before decoding and admits invalid UTF-8 only when base64 fits", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-literal-forms-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const decode = vi.spyOn(TextDecoder.prototype, "decode");
|
|
for (const [bytes, limit, expectedDecodes] of [
|
|
[Buffer.alloc(4096, 65), 1024, 0],
|
|
[Buffer.alloc(2048, 255), 2400, 1],
|
|
] as const) {
|
|
decode.mockClear();
|
|
await writeFile(path, sharedLiteralMetadata(bytes, 1));
|
|
const result = await inspectMetadata(path, limit);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok)
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(
|
|
decode.mock.calls.filter(([value]) => value?.byteLength === bytes.length),
|
|
).toHaveLength(expectedDecodes);
|
|
}
|
|
});
|
|
|
|
it("counts an unclaimed parameter table before allocating any member rows", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-member-counts-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const fixture = createIl2cppMetadataFixture({
|
|
wide: { fillerTypes: 0, genericContainers: 0, parameters: 2000 },
|
|
});
|
|
const bytes = Buffer.from(fixture.bytes);
|
|
bytes.writeInt32LE(0x7fffffff, fixture.section("parameters").offset);
|
|
await writeFile(path, bytes);
|
|
const result = await inspectMetadata(path, 4096);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok)
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "shared-name row lower bound",
|
|
bytes: () => sharedNameMetadata(65_536, 1_100),
|
|
limit: undefined,
|
|
},
|
|
{
|
|
name: "JSON escaping",
|
|
bytes: () => sharedNameMetadata(4096, 1, 0x01),
|
|
limit: 8192,
|
|
},
|
|
{
|
|
name: "UTF-8 expansion",
|
|
bytes: () => sharedNameMetadata(Buffer.from("雪".repeat(4096)), 1),
|
|
limit: 8192,
|
|
},
|
|
])(
|
|
"refuses $name before allocating serialized text",
|
|
async ({ bytes, limit }) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-text-budget-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, bytes());
|
|
const stringify = vi.spyOn(JSON, "stringify");
|
|
const result = await inspectMetadata(path, limit);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok)
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(
|
|
stringify.mock.calls.some(
|
|
([value]) =>
|
|
(typeof value === "string" && value.length >= 4096) ||
|
|
(typeof value === "object" && value !== null && "methods" in value),
|
|
),
|
|
).toBe(false);
|
|
},
|
|
);
|
|
|
|
it("admits a report whose escaped names fit the budget exactly", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-fit-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, sharedNameMetadata(4096, 1, 0x01));
|
|
const unbounded = new Il2cppMetadataProvider();
|
|
let bytes: number;
|
|
try {
|
|
const result = await unbounded.inspect({ path });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.methods[0]?.name).toBe("".repeat(4096));
|
|
bytes = Buffer.byteLength(JSON.stringify(result.value));
|
|
} finally {
|
|
await unbounded.close();
|
|
}
|
|
const exact = new Il2cppMetadataProvider(bytes);
|
|
try {
|
|
expect((await exact.inspect({ path })).ok).toBe(true);
|
|
} finally {
|
|
await exact.close();
|
|
}
|
|
});
|
|
|
|
it("keeps observed source facts with a complete-report refusal", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-report-evidence-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const bytes = createIl2cppMetadataFixture().bytes;
|
|
await writeFile(path, bytes);
|
|
const result = await inspectMetadata(path, 256);
|
|
if (result.ok) throw new Error("Expected report allowance refusal");
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
bytes: bytes.length,
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
},
|
|
});
|
|
const projected = projectAnalysisError(result.error);
|
|
expect(projected.retryable).toBe(false);
|
|
expect(projected.code).toBe("resource_constraint");
|
|
expect(projected.remediation.action).toContain(
|
|
"No complete metadata inventory is retained",
|
|
);
|
|
expect(projected.remediation.action).toContain(
|
|
"Source facts already observed stay with this refusal",
|
|
);
|
|
expect(projected.remediation.action).not.toMatch(
|
|
/does not leave a completed report or Evidence record/u,
|
|
);
|
|
expect(projected.remediation.action).not.toMatch(/worker memory/u);
|
|
});
|
|
|
|
it("refuses from row counts before decoding any row", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-counts-");
|
|
const path = join(root, "global-metadata.dat");
|
|
// A broken method name would fail as invalid-string if rows were decoded.
|
|
const fixture = createIl2cppMetadataFixture();
|
|
const bytes = Buffer.from(fixture.bytes);
|
|
bytes.writeInt32LE(0x7fff, fixture.record("methods", 0));
|
|
await writeFile(path, bytes);
|
|
const result = await inspectMetadata(path, 256);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok)
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
});
|
|
|
|
it.each([
|
|
{ requested: "cancel during metadata decoding" },
|
|
new AnalysisResourceConstraintError(
|
|
"caller-selected-reason",
|
|
"memory",
|
|
"Caller cancellation reason",
|
|
{},
|
|
),
|
|
])(
|
|
"accepts cancellation during decoded batches with exact reason %j",
|
|
async (reason) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-cancel-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const bytes = sharedNameMetadata(1, 100_000);
|
|
await writeFile(path, bytes);
|
|
const controller = new AbortController();
|
|
let batches = 0;
|
|
const provider = new Il2cppMetadataProvider(undefined, async () => {
|
|
await setImmediate();
|
|
if (++batches === 3) controller.abort(reason);
|
|
});
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path },
|
|
{ signal: controller.signal },
|
|
);
|
|
if (result.ok) throw new Error("Expected cancellation");
|
|
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(result.error.cause).toBe(reason);
|
|
expect(batches).toBe(3);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
bytes: bytes.length,
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
validated_section_row_counts: {
|
|
images: 0,
|
|
types: 0,
|
|
methods: 100_000,
|
|
},
|
|
},
|
|
});
|
|
const replacement = createIl2cppMetadataFixture();
|
|
await writeFile(path, replacement.bytes);
|
|
const next = await provider.inspect({ path });
|
|
if (!next.ok) throw next.error;
|
|
expect(next.value.artifact.sha256).toBe(
|
|
createHash("sha256").update(replacement.bytes).digest("hex"),
|
|
);
|
|
expect(next.value.methods).toHaveLength(5);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it("bounds concurrent snapshots and retains active decoding until close completes", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-close-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, createIl2cppMetadataFixture().bytes);
|
|
const decoding = phaseGate();
|
|
const provider = new Il2cppMetadataProvider(undefined, () => {
|
|
return decoding.hold();
|
|
});
|
|
const active = provider.inspect({ path });
|
|
let closed = false;
|
|
let closing: Promise<void> | undefined;
|
|
await withVerifierCleanup(async () => {
|
|
await decoding.reached(active, "metadata decoding");
|
|
closing = provider.close().then(() => {
|
|
closed = true;
|
|
});
|
|
const refused = await provider.inspect({ path });
|
|
expect(refused.ok).toBe(false);
|
|
if (!refused.ok) {
|
|
expect(refused.error).toBeInstanceOf(AnalysisCapabilityUnavailableError);
|
|
expect(projectAnalysisError(refused.error)).toMatchObject({
|
|
code: "capability_unavailable",
|
|
retryable: false,
|
|
details: { reason: "IL2CPP metadata reader is closed" },
|
|
});
|
|
expect(
|
|
projectAnalysisError(refused.error).remediation.action,
|
|
).not.toMatch(/retry/i);
|
|
}
|
|
await setImmediate();
|
|
expect(closed).toBe(false);
|
|
decoding.release();
|
|
await closing;
|
|
expect((await active).ok).toBe(true);
|
|
expect(closed).toBe(true);
|
|
const afterClose = await provider.inspect({ path });
|
|
expect(afterClose.ok).toBe(false);
|
|
if (!afterClose.ok) {
|
|
expect(afterClose.error).toBeInstanceOf(
|
|
AnalysisCapabilityUnavailableError,
|
|
);
|
|
expect(projectAnalysisError(afterClose.error).retryable).toBe(false);
|
|
}
|
|
}, [
|
|
decoding.release,
|
|
async () => {
|
|
await closing;
|
|
},
|
|
async () => {
|
|
await active;
|
|
},
|
|
async () => {
|
|
await provider.close();
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("keeps occupied capacity retryable while the reader remains open", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-occupied-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, createIl2cppMetadataFixture().bytes);
|
|
const decoding = phaseGate();
|
|
const provider = new Il2cppMetadataProvider(undefined, () => {
|
|
return decoding.hold();
|
|
});
|
|
const active = provider.inspect({ path });
|
|
await withVerifierCleanup(async () => {
|
|
await decoding.reached(active, "metadata decoding");
|
|
const refused = await provider.inspect({ path });
|
|
expect(refused.ok).toBe(false);
|
|
if (!refused.ok) {
|
|
expect(refused.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(projectAnalysisError(refused.error)).toMatchObject({
|
|
retryable: true,
|
|
details: {
|
|
resource: "capacity",
|
|
reported_limits: { maximum_concurrent_inspections: 1 },
|
|
},
|
|
remediation: {
|
|
action: expect.stringContaining("active IL2CPP metadata inspection"),
|
|
},
|
|
});
|
|
}
|
|
}, [
|
|
decoding.release,
|
|
async () => {
|
|
await active;
|
|
},
|
|
async () => {
|
|
await provider.close();
|
|
},
|
|
]);
|
|
});
|
|
|
|
it.each([false, true])(
|
|
"keeps an independent failure with shared cancellation reason: %s",
|
|
async (sharedReason) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-failure-cancel-");
|
|
const path = join(root, "global-metadata.dat");
|
|
await writeFile(path, createIl2cppMetadataFixture().bytes);
|
|
const controller = new AbortController();
|
|
const failure = Object.assign(
|
|
new Error("independent scheduler I/O failure"),
|
|
{ code: "EIO" },
|
|
);
|
|
const provider = new Il2cppMetadataProvider(undefined, () => {
|
|
controller.abort(sharedReason ? failure : "separate caller cancellation");
|
|
return Promise.reject(failure);
|
|
});
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path },
|
|
{ signal: controller.signal },
|
|
);
|
|
if (result.ok) throw new Error("Expected the independent failure");
|
|
expect(result.error).not.toBeInstanceOf(AnalysisCancelledError);
|
|
expect(result.error.cause).toBe(failure);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it("retains the exact empty source observation without claiming a decoded inventory", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-empty-");
|
|
const path = join(root, "empty.dat");
|
|
await writeFile(path, Buffer.alloc(0));
|
|
const result = await inspectMetadata(path);
|
|
if (result.ok) throw new Error("Expected unsupported empty metadata");
|
|
expect(result.error.message).toContain("unrecognized-magic");
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
bytes: 0,
|
|
sha256: createHash("sha256").digest("hex"),
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("retains the exact source when recognized magic has no complete version", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-short-prefix-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const bytes = Buffer.alloc(7);
|
|
bytes.writeUInt32LE(0xfab11baf, 0);
|
|
await writeFile(path, bytes);
|
|
const result = await inspectMetadata(path);
|
|
|
|
if (result.ok) throw new Error("Expected truncated metadata prefix");
|
|
expect(result.error).toMatchObject({
|
|
_tag: "AnalysisTargetFailureError",
|
|
path,
|
|
failure: {
|
|
kind: "truncated",
|
|
format: "il2cpp-metadata",
|
|
detail: expect.stringMatching(
|
|
/truncated-header:.*metadata version is unknown/u,
|
|
),
|
|
},
|
|
});
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
bytes: bytes.length,
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
},
|
|
});
|
|
});
|
|
|
|
it("keeps the metadata source observation when the selected binary does not link", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-binary-failure-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "GameAssembly.dll");
|
|
const fixture = createLinkedIl2cppMetadataFixture();
|
|
await writeFile(path, fixture.bytes);
|
|
await writeFile(binaryPath, Buffer.from("not a native image"));
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path: binaryPath });
|
|
if (result.ok) throw new Error("Expected the binary to be refused");
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
sha256: createHash("sha256").update(fixture.bytes).digest("hex"),
|
|
bytes: fixture.bytes.length,
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
},
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("accepts cancellation between binary linking batches and keeps the metadata source", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-link-cancel-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "libil2cpp.so");
|
|
const fixture = createLinkedIl2cppMetadataFixture();
|
|
await writeFile(path, fixture.bytes);
|
|
await writeFile(binaryPath, createElfFixture(createIl2cppBinaryFixture()));
|
|
// Yields taken by the metadata decode alone; later ones belong to linking.
|
|
let decodeYields = 0;
|
|
const counting = new Il2cppMetadataProvider(undefined, async () => {
|
|
decodeYields++;
|
|
});
|
|
try {
|
|
expect((await counting.inspect({ path })).ok).toBe(true);
|
|
} finally {
|
|
await counting.close();
|
|
}
|
|
const controller = new AbortController();
|
|
const reason = new Error("stop linking");
|
|
let yields = 0;
|
|
const provider = new Il2cppMetadataProvider(undefined, async () => {
|
|
if (++yields === decodeYields + 2) controller.abort(reason);
|
|
});
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path, binary_path: binaryPath },
|
|
{ signal: controller.signal },
|
|
);
|
|
if (result.ok) throw new Error("Expected cancellation");
|
|
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(yields).toBe(decodeYields + 2);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: { artifact: { path } },
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
/** Add a compressed ELF64 .shstrtab outside the fixture's PT_LOAD. */
|
|
const withCompressedElfNames = (image: Buffer): Buffer => {
|
|
const names = Buffer.from("\0.shstrtab\0");
|
|
const compressionHeader = Buffer.alloc(24);
|
|
compressionHeader.writeUInt32LE(2, 0); // ELFCOMPRESS_ZSTD
|
|
compressionHeader.writeBigUInt64LE(BigInt(names.length), 8);
|
|
compressionHeader.writeBigUInt64LE(1n, 16);
|
|
const payload = Buffer.concat([compressionHeader, zstdCompressSync(names)]);
|
|
const padding = Buffer.alloc((8 - (image.length % 8)) % 8);
|
|
const tableOffset = image.length + padding.length;
|
|
const table = Buffer.alloc(128);
|
|
const namesHeader = table.subarray(64);
|
|
namesHeader.writeUInt32LE(1, 0); // ".shstrtab" offset in names
|
|
namesHeader.writeUInt32LE(3, 4); // SHT_STRTAB
|
|
namesHeader.writeBigUInt64LE(0x800n, 8); // SHF_COMPRESSED
|
|
namesHeader.writeBigUInt64LE(BigInt(tableOffset + table.length), 24);
|
|
namesHeader.writeBigUInt64LE(BigInt(payload.length), 32);
|
|
namesHeader.writeBigUInt64LE(1n, 48);
|
|
const bytes = Buffer.concat([image, padding, table, payload]);
|
|
bytes.writeBigUInt64LE(BigInt(tableOffset), 40);
|
|
bytes.writeUInt16LE(64, 58);
|
|
bytes.writeUInt16LE(2, 60);
|
|
bytes.writeUInt16LE(1, 62);
|
|
return bytes;
|
|
};
|
|
|
|
it("retains selected source evidence when cancelled decoding compressed ELF names", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-elf-names-cancel-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binary_path = join(root, "libil2cpp.so");
|
|
const metadata = createLinkedIl2cppMetadataFixture().bytes;
|
|
const binary = withCompressedElfNames(
|
|
createElfFixture(createIl2cppBinaryFixture()),
|
|
);
|
|
await Promise.all([
|
|
writeFile(path, metadata),
|
|
writeFile(binary_path, binary),
|
|
]);
|
|
|
|
const controller = new AbortController();
|
|
const reason = new Error("cancel while decoding ELF names");
|
|
const decode = zstandard.decodeZstandardFramesCooperative;
|
|
const checkpoint = vi
|
|
.spyOn(zstandard, "decodeZstandardFramesCooperative")
|
|
.mockImplementation((bytes, options, pause) =>
|
|
decode(bytes, options, async () => {
|
|
controller.abort(reason);
|
|
await pause();
|
|
}),
|
|
);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path, binary_path },
|
|
{ signal: controller.signal },
|
|
);
|
|
if (result.ok) throw new Error("Expected cancellation during ELF decoding");
|
|
expect(result.error).toBeInstanceOf(AnalysisCancelledError);
|
|
expect(result.error.cause).toBe(reason);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
normalized_result: {
|
|
artifact: { path },
|
|
selected_binary: {
|
|
path: binary_path,
|
|
identity_status: "observed",
|
|
bytes: binary.length,
|
|
sha256: createHash("sha256").update(binary).digest("hex"),
|
|
},
|
|
inventory_status: "not-returned-as-complete",
|
|
},
|
|
});
|
|
checkpoint.mockRestore();
|
|
const retry = await provider.inspect({ path, binary_path });
|
|
if (!retry.ok) throw retry.error;
|
|
expect(retry.value.binary?.format).toBe("elf");
|
|
expect(retry.value.method_addresses[0]?.address).toBe(
|
|
`0x${FIXTURE_METHOD_ADDRESSES[0].toString(16)}`,
|
|
);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it.each([false, true])(
|
|
"refuses unsupported generic metadata before reading an invalid ELF directory (signal=%s)",
|
|
async (withSignal) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-generic-layout-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binary_path = join(root, "libil2cpp.so");
|
|
const metadata = createLinkedIl2cppMetadataFixture({ version: 39 }).bytes;
|
|
const binary = withCompressedElfNames(
|
|
createElfFixture(createIl2cppBinaryFixture()),
|
|
);
|
|
binary.writeBigUInt64LE(BigInt(binary.length + 8), 40);
|
|
await Promise.all([
|
|
writeFile(path, metadata),
|
|
writeFile(binary_path, binary),
|
|
]);
|
|
const options = withSignal
|
|
? { signal: new AbortController().signal }
|
|
: undefined;
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect(
|
|
{ path, binary_path, generic_instances: true },
|
|
options,
|
|
);
|
|
expect(result).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisTargetFailureError",
|
|
failure: {
|
|
detail: expect.stringContaining(
|
|
"generic method instances are not decoded for metadata version 39",
|
|
),
|
|
},
|
|
},
|
|
});
|
|
const ordinary = await provider.inspect({ path, binary_path }, options);
|
|
expect(ordinary).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "AnalysisTargetFailureError",
|
|
path: binary_path,
|
|
failure: {
|
|
kind: "malformed",
|
|
format: "il2cpp-binary",
|
|
detail: expect.stringMatching(/^malformed-container:/u),
|
|
},
|
|
},
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it("refuses duplicate MethodDef tokens before publishing linked Evidence or Ghidra seeds", async () => {
|
|
const root = await createTestTempDirectory(
|
|
"rea-il2cpp-duplicate-method-token-",
|
|
);
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "GameAssembly.dylib");
|
|
const duplicateSeeds = join(root, "duplicate.tsv");
|
|
const foldedSeeds = join(root, "folded.tsv");
|
|
const fixture = createLinkedIl2cppMetadataFixture({ version: 31 });
|
|
const duplicate = Buffer.from(fixture.bytes);
|
|
const firstTokenAt = fixture.record("methods", 0) + 24;
|
|
const secondTokenAt = fixture.record("methods", 1) + 24;
|
|
duplicate.writeUInt32LE(duplicate.readUInt32LE(firstTokenAt), secondTokenAt);
|
|
await writeFile(path, duplicate);
|
|
await writeFile(binaryPath, createIl2cppBinaryFixture());
|
|
|
|
const service = new Il2cppMetadataService(
|
|
new Il2cppMetadataProvider(),
|
|
new Il2cppGhidraSeedWriter(),
|
|
);
|
|
try {
|
|
const refused = await service.inspectWithGhidraSeeds(
|
|
{ path, binary_path: binaryPath, detail: "complete" },
|
|
{ path: duplicateSeeds },
|
|
);
|
|
if (refused.ok)
|
|
throw new Error("Duplicate MethodDef identity was accepted");
|
|
// The reused row is in the metadata's own records, so the metadata alone
|
|
// is malformed; the binary is not named.
|
|
expect(projectAnalysisError(refused.error)).toMatchObject({
|
|
code: "unsupported_target",
|
|
details: {
|
|
path,
|
|
format: "il2cpp-metadata",
|
|
failure_kind: "malformed",
|
|
reason: expect.stringMatching(/^invalid-method-definition-token:/u),
|
|
},
|
|
});
|
|
expect(projectAnalysisError(refused.error)).not.toHaveProperty("recovery");
|
|
await expect(readFile(duplicateSeeds)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
|
|
const foldedBinary = createIl2cppBinaryFixture();
|
|
foldedBinary.writeBigUInt64LE(foldedBinary.readBigUInt64LE(0x308), 0x300);
|
|
await writeFile(path, fixture.bytes);
|
|
await writeFile(binaryPath, foldedBinary);
|
|
const accepted = await service.inspectWithGhidraSeeds(
|
|
{ path, binary_path: binaryPath, detail: "complete" },
|
|
{ path: foldedSeeds },
|
|
);
|
|
if (!accepted.ok) throw accepted.error;
|
|
const result = il2cppMetadataSchema.parse(accepted.value.normalized_result);
|
|
expect(result.method_addresses[0]?.address).toBe(
|
|
result.method_addresses[1]?.address,
|
|
);
|
|
expect(await readFile(foldedSeeds, "utf8")).toContain("# folded");
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
|
|
it("retains both observed file identities and the selected architecture when native linking fails", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-failed-pair-");
|
|
const path = join(root, "global-metadata.dat"),
|
|
binary_path = join(root, "GameAssembly.dylib");
|
|
const bytes = createIl2cppBinaryFixture({ codeRegistration: false });
|
|
await writeFile(path, createLinkedIl2cppMetadataFixture().bytes);
|
|
await writeFile(binary_path, bytes);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path });
|
|
if (result.ok) throw new Error("Unresolved registration accepted");
|
|
// Both files parse; neither is called malformed. The conflict lists each
|
|
// selecting field and keeps each file's identity.
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "input_conflict",
|
|
retryable: false,
|
|
remediation: {
|
|
action: expect.stringContaining("from the same build"),
|
|
},
|
|
details: {
|
|
failure_kind: "conflict",
|
|
path,
|
|
reason: expect.stringContaining("code-registration-not-found:"),
|
|
inputs: [
|
|
{ field: "path", path },
|
|
{ field: "binary_path", path: binary_path },
|
|
],
|
|
},
|
|
});
|
|
expect(projectAnalysisError(result.error)).not.toHaveProperty("recovery");
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
normalized_result: {
|
|
artifact: {
|
|
path,
|
|
sha256: createHash("sha256")
|
|
.update(createLinkedIl2cppMetadataFixture().bytes)
|
|
.digest("hex"),
|
|
},
|
|
selected_binary: {
|
|
path: binary_path,
|
|
identity_status: "observed",
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
bytes: bytes.length,
|
|
},
|
|
},
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
architecture: "x86-64",
|
|
name: "libil2cpp.so",
|
|
binary: () =>
|
|
createElfFixture(
|
|
createIl2cppBinaryFixture({
|
|
codeRegistration: false,
|
|
codeReference: true,
|
|
}),
|
|
{ machine: 62 },
|
|
),
|
|
named: "RIP-relative LEA/MOV",
|
|
absent: "ADRP+ADD",
|
|
},
|
|
{
|
|
architecture: "arm64",
|
|
name: "GameAssembly.dylib",
|
|
binary: () =>
|
|
createIl2cppBinaryFixture({
|
|
codeRegistration: false,
|
|
adrpAdd: [[0xc00, 0x500]],
|
|
}),
|
|
named: "ADRP+ADD",
|
|
absent: "RIP-relative LEA/MOV",
|
|
},
|
|
])(
|
|
"names the $architecture instruction form behind an inferred module array",
|
|
async ({ name, binary, named, absent }) => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-inferred-form-");
|
|
const path = join(root, "global-metadata.dat"),
|
|
binary_path = join(root, name);
|
|
await writeFile(path, createLinkedIl2cppMetadataFixture().bytes);
|
|
await writeFile(binary_path, binary());
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path });
|
|
if (!result.ok) throw result.error;
|
|
const inferred = result.value.limitations.filter((line) =>
|
|
line.includes("static CodeRegistration pair was not resolved"),
|
|
);
|
|
expect(inferred).toHaveLength(1);
|
|
expect(inferred[0]).toContain(named);
|
|
expect(inferred[0]).not.toContain(absent);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it("states that an inferred type table's count is a run length", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-inferred-types-");
|
|
const path = join(root, "global-metadata.dat"),
|
|
binary_path = join(root, "GameAssembly.dylib");
|
|
// A field typed as type 3 makes the metadata reference the whole
|
|
// four-entry table, as real builds reference most of theirs.
|
|
const fixture = createLinkedIl2cppMetadataFixture();
|
|
const metadata = Buffer.from(fixture.bytes);
|
|
metadata.writeUInt8(3, fixture.section("fields").offset + 4);
|
|
await writeFile(path, metadata);
|
|
await writeFile(
|
|
binary_path,
|
|
createIl2cppBinaryFixture({
|
|
metadataRegistration: false,
|
|
adrpAdd: [[0xc20, 0x900]],
|
|
}),
|
|
);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.binary).toMatchObject({
|
|
types_field: null,
|
|
types_count: 4,
|
|
code_gen_modules_field: expect.any(String),
|
|
});
|
|
const inferred = result.value.limitations.filter((line) =>
|
|
line.includes(
|
|
"No static MetadataRegistration had the type-definition counts",
|
|
),
|
|
);
|
|
expect(inferred).toHaveLength(1);
|
|
expect(inferred[0]).toContain("ADRP+ADD");
|
|
expect(
|
|
result.value.limitations.some((line) =>
|
|
line.includes("static CodeRegistration pair was not resolved"),
|
|
),
|
|
).toBe(false);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("reports generic method instances only when generic_instances is set", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-provider-generic-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "GameAssembly.dylib");
|
|
await writeFile(
|
|
path,
|
|
createIl2cppMetadataFixture({ version: 31, genericOwners: true }).bytes,
|
|
);
|
|
await writeFile(
|
|
binaryPath,
|
|
createIl2cppBinaryFixture({ genericMethods: {} }),
|
|
);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const plain = await provider.inspect({ path, binary_path: binaryPath });
|
|
if (!plain.ok) throw plain.error;
|
|
// Not requested is unknown, not an empty table.
|
|
expect(plain.value.generic_method_instances).toBeNull();
|
|
expect(plain.value.binary?.generic_methods).toBeNull();
|
|
const result = await provider.inspect({
|
|
path,
|
|
binary_path: binaryPath,
|
|
generic_instances: true,
|
|
});
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.binary?.generic_methods).toEqual({
|
|
generic_method_pointers_field: "0x1000005a8",
|
|
generic_method_pointers_count: 3,
|
|
generic_method_table: "0x100000bc0",
|
|
generic_method_table_count: 3,
|
|
generic_method_table_stride: 16,
|
|
method_specs_count: 3,
|
|
generic_insts_count: 2,
|
|
issues: [],
|
|
});
|
|
expect(result.value.generic_method_instances).toEqual(
|
|
FIXTURE_GENERIC_INSTANCES,
|
|
);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("names the metadata, not the binary, when linking reads a malformed metadata name", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-link-metadata-name-");
|
|
const path = join(root, "global-metadata.dat"),
|
|
binaryPath = join(root, "GameAssembly.dylib");
|
|
const fixture = createLinkedIl2cppMetadataFixture({ version: 39 });
|
|
// One generic parameter whose name index points past the string table;
|
|
// only native linking reads it, through a field typed as that parameter.
|
|
const parameterAt = fixture.bytes.length;
|
|
const metadata = Buffer.concat([fixture.bytes, Buffer.alloc(13)]);
|
|
metadata.writeInt32LE(fixture.section("strings").size, parameterAt + 1);
|
|
metadata.writeInt32LE(parameterAt, 8 + 12 * 12);
|
|
metadata.writeInt32LE(13, 8 + 12 * 12 + 4);
|
|
metadata.writeInt32LE(1, 8 + 12 * 12 + 8);
|
|
metadata.writeUInt8(3, fixture.section("fields").offset + 4);
|
|
const binary = Buffer.from(createIl2cppBinaryFixture());
|
|
binary.writeBigUInt64LE(0n, 0x980 + 48);
|
|
binary.writeUInt32LE(0x13 << 16, 0x980 + 48 + 8);
|
|
await writeFile(path, metadata);
|
|
await writeFile(binaryPath, binary);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path: binaryPath });
|
|
if (result.ok) throw new Error("Expected the metadata name to be refused");
|
|
expect(result.error).toMatchObject({
|
|
_tag: "AnalysisTargetFailureError",
|
|
path,
|
|
failure: {
|
|
kind: "malformed",
|
|
format: "il2cpp-metadata",
|
|
detail: expect.stringMatching(/^invalid-string:/u),
|
|
},
|
|
});
|
|
|
|
const corrected = Buffer.from(metadata);
|
|
corrected.writeInt32LE(
|
|
fixture.stringOffset("Player") - fixture.section("strings").offset,
|
|
parameterAt + 1,
|
|
);
|
|
await writeFile(path, corrected);
|
|
expect((await provider.inspect({ path, binary_path: binaryPath })).ok).toBe(
|
|
true,
|
|
);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("refuses generic rows that exceed the report budget and keeps the requested pair", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-generic-budget-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binary_path = join(root, "GameAssembly.dylib");
|
|
await writeFile(
|
|
path,
|
|
createIl2cppMetadataFixture({ version: 31, genericOwners: true }).bytes,
|
|
);
|
|
await writeFile(
|
|
binary_path,
|
|
createIl2cppBinaryFixture({ genericMethods: {} }),
|
|
);
|
|
// Budget the exact plain link: it fits, and the generic rows cannot.
|
|
const plain = new Il2cppMetadataProvider();
|
|
let limit: number;
|
|
try {
|
|
const linked = await plain.inspect({ path, binary_path });
|
|
if (!linked.ok) throw linked.error;
|
|
limit = Buffer.byteLength(JSON.stringify(linked.value)) + 64;
|
|
} finally {
|
|
await plain.close();
|
|
}
|
|
const provider = new Il2cppMetadataProvider(limit);
|
|
try {
|
|
expect((await provider.inspect({ path, binary_path })).ok).toBe(true);
|
|
const result = await provider.inspect({
|
|
path,
|
|
binary_path,
|
|
generic_instances: true,
|
|
});
|
|
if (result.ok) throw new Error("Expected report allowance refusal");
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(result.error.partialObservation).toMatchObject({
|
|
operation: "observe_il2cpp_metadata_source",
|
|
parameters: { binary_path, generic_instances: true },
|
|
normalized_result: { selected_binary: { path: binary_path } },
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("bounds the ELF pointer index by the caller's max_native_index_bytes", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-index-budget-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "libil2cpp.so");
|
|
await writeFile(path, createLinkedIl2cppMetadataFixture().bytes);
|
|
await writeFile(binaryPath, createElfFixture(createIl2cppBinaryFixture()));
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
// One 2 KiB reservation admits a single relocated address; the fixture
|
|
// relocates several, so the selected allowance stops linking.
|
|
const refused = await provider.inspect({
|
|
path,
|
|
binary_path: binaryPath,
|
|
max_native_index_bytes: 2048,
|
|
});
|
|
if (refused.ok) throw new Error("Expected the pointer index refusal");
|
|
expect(refused.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(refused.error).toMatchObject({
|
|
resource: "memory",
|
|
retryable: false,
|
|
fixedAllowance: undefined,
|
|
reportedLimits: {
|
|
boundary: "virtual-pointer-index-bytes",
|
|
maximum: 2048,
|
|
},
|
|
limit: {
|
|
control_kind: "parameter",
|
|
parameter: "max_native_index_bytes",
|
|
effective_value: 2048,
|
|
unit: "bytes",
|
|
minimum: 1,
|
|
maximum: Number.MAX_SAFE_INTEGER,
|
|
default_value: 1024 * 1024 * 1024,
|
|
applies_at: "next_call",
|
|
},
|
|
});
|
|
// The same complete pair links once the caller raises the allowance,
|
|
// and the default admits it without any selection.
|
|
expect(
|
|
(
|
|
await provider.inspect({
|
|
path,
|
|
binary_path: binaryPath,
|
|
max_native_index_bytes: 1024 * 1024,
|
|
})
|
|
).ok,
|
|
).toBe(true);
|
|
expect((await provider.inspect({ path, binary_path: binaryPath })).ok).toBe(
|
|
true,
|
|
);
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|
|
|
|
it("refuses max_native_index_bytes without binary_path", () => {
|
|
const parsed = inspectIl2cppMetadataInputSchema.safeParse({
|
|
path: "/tmp/global-metadata.dat",
|
|
max_native_index_bytes: 4096,
|
|
});
|
|
expect(parsed.success).toBe(false);
|
|
expect(parsed.error?.issues).toEqual([
|
|
expect.objectContaining({ path: ["max_native_index_bytes"] }),
|
|
]);
|
|
});
|
|
|
|
it("reports the exceeded native-link maximum in the public refusal", async () => {
|
|
const root = await createTestTempDirectory("rea-il2cpp-link-limit-");
|
|
const path = join(root, "global-metadata.dat");
|
|
const binaryPath = join(root, "GameAssembly.dylib");
|
|
await writeFile(path, createLinkedIl2cppMetadataFixture().bytes);
|
|
// 80 copies of the two-slot module array exceed the 64 candidate arrays
|
|
// the fallback search compares; x86-64 makes that fallback run.
|
|
const base = createIl2cppBinaryFixture({
|
|
codeRegistration: false,
|
|
codeReference: true,
|
|
});
|
|
const crafted = Buffer.concat([
|
|
base,
|
|
...Array.from({ length: 80 }, () => base.subarray(0x500, 0x510)),
|
|
]);
|
|
crafted.writeBigUInt64LE(BigInt(crafted.length), 64);
|
|
crafted.writeBigUInt64LE(BigInt(crafted.length), 80);
|
|
crafted.writeUInt32LE(0x01000007, 4);
|
|
crafted.writeUInt32LE(3, 8);
|
|
await writeFile(binaryPath, crafted);
|
|
const provider = new Il2cppMetadataProvider();
|
|
try {
|
|
const result = await provider.inspect({ path, binary_path: binaryPath });
|
|
if (result.ok) throw new Error("Expected the link budget refusal");
|
|
expect(result.error).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
expect(result.error).toMatchObject({
|
|
resource: "capacity",
|
|
reportedLimits: {
|
|
boundary: "native-index-capacity",
|
|
maximum: 64,
|
|
},
|
|
fixedAllowance: { limit: 64, unit: "entries" },
|
|
});
|
|
} finally {
|
|
await provider.close();
|
|
}
|
|
});
|