Files
rea/src/cli/apktoolCommands.ts
T
morluto 0eb19a395e fix(limits)!: let apktool and assetutil take producer_limits.output_bytes and type Android and process capture refusals (#14624)
* fix(limits)!: let apktool and assetutil take producer_limits.output_bytes and type Android and process capture refusals

decode_android_resources and inspect_asset_catalog refused larger apktool or
assetutil output with a fixed capture ceiling. Both now accept
producer_limits.output_bytes (defaults 4 MiB and 64 MiB) and report
details.limit for it. assetutil's budget covers each stream and the JSON
retained across catalogs, capped at 128 MiB for the in-process decode.

capture_process's retained-frame refusal reports details.limit for
limits.output_bytes, and a JADX JVM heap failure is marked as measured
exhaustion. The lipo field-retention allowance is reclassified as derived from
the native command output capture, and the JADX external DEX representation
allowance as protocol (a fraction of the bridge's local MCP frame).

BREAKING CHANGE: apktool and assetutil output refusals report details.limit for
producer_limits.output_bytes instead of a fixed_ceiling refusal.

* test(apktool): decode raised output after the default refuses it, and check deadlines leave the output budget unchanged

* fix(resources): keep a file-size refusal's observed size through failure rebuilds
2026-11-26 06:26:51 +00:00

85 lines
3.0 KiB
TypeScript

import type { RequestAnalysisPort } from "../ports/AnalysisProvider.js";
import type {
ApktoolRequest,
ApktoolOperation,
} from "../domain/apktool/apktoolResourceAnalysis.js";
import { PRODUCER_LIMITS_HELP } from "./producerLimitsOption.js";
import { createApktoolResourceAnalysisService } from "../application/ProviderOperationServices.js";
import { createApktoolResourceAnalysisProvider } from "../composition/apktool.js";
import { APKTOOL_TOOL_CONTRACTS } from "../contracts/apktool/apktoolToolContracts.js";
import type { Logger } from "pino";
import { contractNamed } from "./contractCliDescription.js";
import { registerContractCommand } from "./contractCommand.js";
import {
analyzeWithService,
type EvidenceInspectionService,
} from "./contractCommandRunners.js";
import { finishCliEvidenceCommand } from "./cliEvidenceCallerPath.js";
import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
import type { CliInstance } from "./types.js";
/** Expose the same explicit Apktool requests through one-shot CLI commands. */
export const registerApktoolCommands = (
cli: CliInstance,
logger: Logger,
environment: Readonly<Record<string, string | undefined>>,
provider: RequestAnalysisPort<ApktoolRequest> = createApktoolResourceAnalysisProvider(
environment,
),
): void => {
const service = createApktoolResourceAnalysisService(provider);
const run =
(operation: ApktoolOperation) => (): EvidenceInspectionService => ({
inspect: (input, { signal }) =>
service.execute(operation, input, { signal }),
close: () => provider.close(),
});
registerContractCommand(
cli,
logger,
contractNamed(APKTOOL_TOOL_CONTRACTS, "inspect_apktool_client"),
{
description:
"Inspect the caller-selected apktool launcher without decoding anything",
},
analyzeWithService(run("inspect_apktool_client"), "apktool"),
);
registerContractCommand(
cli,
logger,
contractNamed(APKTOOL_TOOL_CONTRACTS, "decode_android_resources"),
{
description:
"Decode one APK's manifest, metadata, and string resources with apktool",
// The contract admits a relative path, resolved by the provider from
// the working directory, so the CLI passes it on as spelled.
positionals: ["path"],
jsonText: ["producer_limits"],
fields: {
producer_limits: { description: PRODUCER_LIMITS_HELP },
include_strings: {
name: "strings",
description:
"Include string resources; use --no-strings to skip projecting them",
},
locales: {
description:
"Repeat to project multiple localized string tables, e.g. --locales de --locales pt-BR",
},
},
},
(input, { operation, signal }) => {
const owned = run("decode_android_resources")();
return finishCliEvidenceCommand(
input.path,
() => owned.inspect(input, { signal }),
owned,
"apktool",
operation,
signal,
).then(projectCliAnalysisResult);
},
);
};