* feat(apktool): decode Android resource tables through a caller-supplied launcher Add an Apktool family with two operations over the caller's apktool launcher (REA_APKTOOL_COMMAND, absolute, or apktool on PATH): - inspect_apktool_client: resolved launcher, selection source, and version; decodes nothing. - decode_android_resources: apktool d --no-src in a provider-owned workspace that is removed before the result returns. Projects the decoded AndroidManifest.xml (bounded at 512 KiB), apktool.yml version and SDK facts exactly as printed, string resources verbatim (default or one locale, bounded at 2000 entries, nested-markup entries counted as unparsed), available string locales, and the decoded file count with a hard cap. The target APK is digested with SHA-256 before decoding so Evidence binds the observation to the exact input. Smali production is skipped by design: Java-source recovery belongs to the JADX family. Workspace cleanup happens before results return; an unremovable workspace is named in the limitations instead of abandoned. Verified against apktool 2.7.0-dirty (Debian packaging) on Linux with OpenJDK 25 against a signed aapt2-built probe APK with two resource locales: launcher version, on-disk digest agreement, metadata projection, manifest package agreement, and both string tables (default and de). Parser goldens come from the same decode. READMEs carry the new 'Android resources' row in every supported language. * fix(apktool): own snapshots and bound decoded resource reads * docs(apktool): describe owned resources and bounded projection --------- Co-authored-by: REA Contributor <contributor@rea.tools> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import { z } from "incur";
|
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js";
|
|
import type { ApktoolResourceAnalysisPort } from "../application/apktool/ApktoolResourceAnalysisPort.js";
|
|
import { createApktoolResourceAnalysisProvider } from "../composition/apktool.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import type { ApktoolOperation } from "../domain/apktool/apktoolResourceAnalysis.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.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: ApktoolResourceAnalysisPort = createApktoolResourceAnalysisProvider(
|
|
environment,
|
|
),
|
|
): void => {
|
|
const service = new ApktoolResourceAnalysisService(provider);
|
|
const execute = (name: string, operation: ApktoolOperation, input: unknown) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, name, async () => {
|
|
const result = await service.execute(operation, input, { signal });
|
|
try {
|
|
await provider.close();
|
|
} catch (cause) {
|
|
if (cause instanceof AnalysisError)
|
|
return projectAnalysisError(cause);
|
|
throw cause;
|
|
}
|
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
|
}),
|
|
);
|
|
|
|
cli.command(CLI_COMMANDS.inspectApktoolClient, {
|
|
description:
|
|
"Inspect the caller-selected apktool launcher without decoding anything",
|
|
args: z.object({}),
|
|
run: () =>
|
|
execute(CLI_COMMANDS.inspectApktoolClient, "inspect_apktool_client", {}),
|
|
});
|
|
cli.command(CLI_COMMANDS.decodeAndroidResources, {
|
|
description:
|
|
"Decode one APK's manifest, metadata, and string resources with apktool",
|
|
args: z.object({
|
|
path: z.string().min(1).describe("Local APK file to decode"),
|
|
}),
|
|
options: z.object({
|
|
locale: z
|
|
.string()
|
|
.min(2)
|
|
.max(16)
|
|
.regex(
|
|
/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/u,
|
|
"Locale must look like de or pt-BR",
|
|
)
|
|
.optional()
|
|
.describe(
|
|
"Project strings from res/values-<locale> instead of the default",
|
|
),
|
|
"no-strings": z
|
|
.boolean()
|
|
.default(false)
|
|
.describe("Skip projecting string resources"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
execute(CLI_COMMANDS.decodeAndroidResources, "decode_android_resources", {
|
|
path: args.path,
|
|
include_strings: !options["no-strings"],
|
|
...(options.locale === undefined ? {} : { locale: options.locale }),
|
|
}),
|
|
});
|
|
};
|