Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(cli): preserve APK locale-list schema bounds

morlutof1edf0da0c6c
diff --git a/src/cli/apktoolCommands.ts b/src/cli/apktoolCommands.ts
index b3a58d878..d870d918d 100644
--- a/src/cli/apktoolCommands.ts
+++ b/src/cli/apktoolCommands.ts
@@ -54,12 +54,8 @@ export const registerApktoolCommands = (
// `b+zh+Hans+CN` form at the CLI boundary.
options: z.object({
locale: apktoolInputSchemas.decode_android_resources.shape.locale,
- locales: z
- .array(
- apktoolInputSchemas.decode_android_resources.shape.locale.unwrap(),
- )
- .optional()
- .describe(
+ locales:
+ apktoolInputSchemas.decode_android_resources.shape.locales.describe(
"Repeat to project multiple localized string tables, e.g. --locales de --locales pt-BR",
),
strings: z
diff --git a/tests/boundary/cli/cliInputSchemaRequired.test.ts b/tests/boundary/cli/cliInputSchemaRequired.test.ts
index efd72f10d..1bf778b7a 100644
--- a/tests/boundary/cli/cliInputSchemaRequired.test.ts
+++ b/tests/boundary/cli/cliInputSchemaRequired.test.ts
@@ -4,6 +4,10 @@ import { describe, expect, it } from "vitest";
import { createCli } from "../../../src/cli.js";
import { createCliInventory } from "../../../scripts/lib/catalog-cli.mjs";
+import {
+ apktoolInputSchemas,
+ MAX_SELECTED_LOCALES,
+} from "../../../src/domain/apktool/apktoolResourceAnalysis.js";
type CliInstance = ReturnType<typeof createCli>;
type CommandMap = NonNullable<ReturnType<typeof Cli.toCommands.get>>;
@@ -201,6 +205,40 @@ describe("web module CLI advertised input schema", () => {
});
});
+describe("Apktool locale selection input schema", () => {
+ it("preserves the owner's array bounds through CLI advertisement and parsing", async () => {
+ const cli = createCli({});
+ const advertised = await advertisedSchema(cli, "decode-android-resources");
+ expect(advertised.options?.properties?.locales).toMatchObject({
+ type: "array",
+ minItems: 1,
+ maxItems: MAX_SELECTED_LOCALES,
+ });
+ const parser = parserSchema(cli, "decode-android-resources", "options");
+ const ajv = new Ajv2020({ strict: false });
+ const validate = ajv.compile({
+ ...advertised.options,
+ $schema: "https://json-schema.org/draft/2020-12/schema",
+ });
+ for (const locales of [
+ undefined,
+ [],
+ ["de"],
+ Array<string>(MAX_SELECTED_LOCALES).fill("de"),
+ Array<string>(MAX_SELECTED_LOCALES + 1).fill("de"),
+ ["not a locale"],
+ ]) {
+ const input = locales === undefined ? {} : { locales };
+ const expected = apktoolInputSchemas.decode_android_resources.safeParse({
+ path: "/targets/app.apk",
+ ...input,
+ }).success;
+ expect(parser?.safeParse(input).success).toBe(expected);
+ expect(validate(input)).toBe(expected);
+ }
+ });
+});
+
describe("reference-source outline-depth input schema", () => {
it("aligns advertised bounds with the parser's accepted values", async () => {
const cli = createCli({});