Files
rea/src/cli/il2cppCommands.ts
T
morluto 6ab595cfd6 fix(limits)!: make the IL2CPP pointer index adjustable and require owned refusal limits (#14243)
* fix(limits): make the IL2CPP pointer index adjustable and name ELF note budgets in details.limit

inspect_il2cpp_metadata accepts max_native_index_bytes (default 1 GiB,
needs binary_path) for the estimated ELF virtual pointer index. The index
refusal now carries its own limit name (virtual-pointer-index-bytes) and a
details.limit naming the parameter, its effective value, default and range,
instead of a fixed ceiling with no override. The binary file allowance and
the loader's fixed capacities are unchanged.

inspect_elf_notes and inspect_elf_debug_link refusals for max_file_bytes,
the decoded section-name budget and max_entries now set details.limit. One
domain-owned bounds object per operation feeds both the schema and the limit.

Two guards keep new in-code refusal limits owned:
- scripts/verify/fixed-ceilings.mjs (run by npm run lint) requires every
  fixedAllowanceOptions, fixedProducerInputAllowance,
  artifactFixedLimitFailure or inline fixedAllowance declaration to be
  listed in fixed-ceiling-registry.json with its class (format, protocol,
  representation, derived, forwarding, or pending with an issue) and reason,
  and fails on stale entries.
- The untyped-budget-refusal architecture guard counts refusals whose only
  recovery is an authored remediationAction, with a shrink-only baseline.

Fixes #14175
Part of #14234

BREAKING CHANGE: an inspect_il2cpp_metadata refusal at the ELF pointer index
reports reported_limits.boundary "virtual-pointer-index-bytes" and
details.limit for max_native_index_bytes, and no longer carries a
details.refusal fixed_ceiling.

* fix(limits): track IL2CPP's remaining fixed allowances with the native readers

* fix(limits): run the authored-only refusal count from lint, where TypeScript is installed

The architecture guards run before npm ci in CI and must stay
dependency-free, so the AST-based count moves into fixed-ceilings.mjs with
its own shrink-only baseline and --shrink-baselines.

* fix(limits): register producer and native wrapper ceilings by the allowance they name

fixedProducerInputAllowance names its allowance in its second argument, and
fixedNativeAllowance forwards its first, so the guard now reads each helper's
allowance argument and checks the callers of both.

* fix(limits): delete the authored-only baseline when its last count is removed

reconcileBaselineFile returns delete once no count remains, but the
verifier ignored it and the next run read the file unconditionally, so
--shrink-baselines could not finish. An absent baseline now reads as empty
and shrinking removes the file.

* fix(limits): record the advertised IL2CPP input schema with max_native_index_bytes
2026-11-23 23:37:23 -05:00

121 lines
4.3 KiB
TypeScript

import { z } from "zod";
import type { Logger } from "pino";
import { createIl2cppMetadataService } from "../composition/il2cpp.js";
import { IL2CPP_TOOL_CONTRACTS } from "../contracts/il2cpp/il2cppToolContracts.js";
import { AnalysisInputError } from "../domain/analysisErrorCore.js";
import { localPathStringSchema } from "../domain/localPath.js";
import { err } from "../domain/result.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { contractNamed } from "./contractCliDescription.js";
import { registerContractCommand } from "./contractCommand.js";
import { deliverWithService } from "./contractCommandRunners.js";
import type { CliInstance } from "./types.js";
/**
* Inspection with the CLI-only Ghidra seed output: `--ghidra-seeds` writes
* seeds for the linked methods, and `--seed-base` rebases them.
*/
const il2cppService = (
ghidraSeeds: string | undefined,
seedBase: string | undefined,
) => {
const service = createIl2cppMetadataService();
return {
inspect: (input: unknown, options: { readonly signal: AbortSignal }) => {
if (ghidraSeeds !== undefined)
return service.inspectWithGhidraSeeds(
input,
{
path: absoluteCallerPath(ghidraSeeds),
...(seedBase === undefined ? {} : { base: seedBase }),
},
options,
);
if (seedBase !== undefined)
return Promise.resolve(
err(
new AnalysisInputError("inspect_il2cpp_metadata", undefined, [
{
path: ["seed_base"],
reason: "invalid_value",
message: "--seed-base requires --ghidra-seeds.",
},
]),
),
);
return service.inspect(input, options);
},
close: () => service.close(),
};
};
/** CLI and MCP share inspection; one-shot summaries preserve a complete Evidence file. */
export const registerIl2cppCommands = (
cli: CliInstance,
logger: Logger,
): void => {
registerContractCommand(
cli,
logger,
contractNamed(IL2CPP_TOOL_CONTRACTS, "inspect_il2cpp_metadata"),
{
description:
"Inventory IL2CPP global-metadata.dat names, owners and string literals, optionally linking method addresses from the native binary",
positionals: ["path"],
callerPaths: ["path", "binary_path"],
evidenceDelivery: true,
fields: {
path: {
description:
"Local global-metadata.dat (version 24, 27, 29, 31 or 39)",
},
binary_path: {
name: "binary",
description:
"Matching native binary (Mach-O GameAssembly.dylib, PE GameAssembly.dll or ELF libil2cpp.so) to link method addresses; read only",
},
binary_architecture: {
name: "architecture",
description: "Slice of a universal Mach-O binary",
},
generic_instances: {
description:
"Also link generic method instances (Type<Args>$$Method<Args>) and include them in --ghidra-seeds; needs --binary",
},
max_native_index_bytes: {
description:
"Estimated bytes for an ELF --binary's relocated-pointer index (default 1073741824); raise when linking stops at this allowance; needs --binary",
},
},
cliOptions: {
ghidraSeeds: localPathStringSchema
.optional()
.describe(
"Also write REA_GHIDRA_SEED_FILE function seeds named Type$$Method for every linked method; needs --binary",
),
seedBase: z
.string()
.regex(/^0x[0-9a-fA-F]{1,16}$/u)
.optional()
.describe(
"Address Ghidra loads the binary at; seeds are seed-base + RVA (default: Ghidra's loader default, 0x100000 for an ELF linked at 0, else the link base)",
),
},
cliOptionDependencies: {
ghidraSeeds: ["binary"],
seedBase: ["ghidraSeeds"],
},
},
(input, context) => {
const { ghidraSeeds, seedBase } = context.cliOptions;
// The CLI delivers the summary itself, so the service returns complete
// Evidence; the contract's own default would retain a summary instead.
return deliverWithService(
() => il2cppService(ghidraSeeds, seedBase),
"il2cpp-metadata",
)({ ...input, detail: "complete" }, context);
},
);
};