Files
reverse-engineering-anything/src/cli/flutterCommands.ts
T
morluto 49e2eca4f9 feat(flutter)!: give Flutter APK admission per-call apk_limits (#14623)
* feat(flutter)!: give Flutter APK admission per-call apk_limits

identify_flutter_build and inspect_dart_aot refused a large but ordinary
APK at seven fixed allowances (APK snapshot, ZIP metadata, library read,
cumulative extraction, ABI count, library path and snapshot-hash
candidates) with no recovery. They now accept apk_limits (CLI
--apk-limits JSON) with today's values as defaults. Each refusal reports
details.limit naming the apk_limits field, its effective value and range.

The domain owns one bounds object that feeds both the schema and the
reported limit. library_path_bytes is capped by the 16-bit ZIP name
field, and the inspect_dart_aot ABI selector length now follows that
maximum instead of the old 1 KiB default.

BREAKING CHANGE: Flutter size, inventory and candidate refusals report
details.limit instead of a fixed_ceiling refusal, and the inspect_dart_aot
abi selector admits labels up to 65,521 characters.

* fix(flutter): bound library_path_bytes by the decoded ZIP name size

Inventory counts a library path's decoded UTF-8 bytes, and one stored
byte decodes to at most three (a CP437 box-drawing character), so the
maximum is three times the 16-bit stored name length rather than the
stored length itself. The ABI selector keeps its character bound from
the stored name. Recovery tests now assert the reported facts after
raising a limit.
2026-11-25 21:46:58 -05:00

92 lines
3.3 KiB
TypeScript

import type { RequestAnalysisPort } from "../ports/AnalysisProvider.js";
import type {
FlutterRequest,
FlutterOperation,
} from "../domain/flutter/flutterBuildAnalysis.js";
import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import { withEvidenceCallerInputPath } from "../domain/evidence.js";
import { recognizeEvidence } from "../domain/evidenceValidation.js";
import { createFlutterBuildAnalysisService } from "../application/ProviderOperationServices.js";
import { createFlutterBuildAnalysisProvider } from "../composition/flutter.js";
import { FLUTTER_TOOL_CONTRACTS } from "../contracts/flutter/flutterToolContracts.js";
import type { Logger } from "pino";
import type { CliInstance } from "./types.js";
import { contractNamed } from "./contractCliDescription.js";
import {
registerContractCommand,
type ContractCommandContext,
} from "./contractCommand.js";
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
import { bindCliEvidenceCallerPath } from "./cliEvidenceCallerPath.js";
/** Expose the same explicit Flutter requests through one-shot CLI commands. */
export const registerFlutterCommands = (
cli: CliInstance,
logger: Logger,
provider: RequestAnalysisPort<FlutterRequest> = createFlutterBuildAnalysisProvider(),
): void => {
/**
* Run one operation on the APK the caller selected, recording that spelling
* in Evidence, including a result completed before cleanup failed. The
* contract admits a relative path, resolved by the provider from the working
* directory, so the CLI passes it on as spelled.
*/
const run =
(operation: FlutterOperation) =>
(input: { readonly path: string }, { signal }: ContractCommandContext) =>
finishAnalysisCommand(
bindCliEvidenceCallerPath(input.path, () =>
createFlutterBuildAnalysisService(provider).execute(
operation,
input,
{
signal,
},
),
),
{ close: () => provider.close() },
"flutter",
operation,
signal,
undefined,
{
recoverCompletedObservation: (observation) => {
// Only authenticated Evidence is recovered; otherwise the error stands.
const parsed = recognizeEvidence(observation);
return parsed.ok && parsed.value !== undefined
? withEvidenceCallerInputPath(parsed.value, input.path)
: undefined;
},
},
).then(projectCliAnalysisResult);
registerContractCommand(
cli,
logger,
contractNamed(FLUTTER_TOOL_CONTRACTS, "identify_flutter_build"),
{
description:
"Identify a Flutter build's Dart snapshot hash and engine facts by pure APK parsing",
positionals: ["path"],
jsonText: ["apk_limits"],
},
run("identify_flutter_build"),
);
registerContractCommand(
cli,
logger,
contractNamed(FLUTTER_TOOL_CONTRACTS, "inspect_dart_aot"),
{
description:
"Inspect one ABI's Dart AOT snapshot: sections, headers, and the string pool",
positionals: ["path"],
jsonText: ["pool_policy", "apk_limits"],
omit: {
detail:
"The CLI returns complete Evidence; a summary needs a session that retains it for inspect_analysis_view",
},
},
run("inspect_dart_aot"),
);
};