Skip to content

armgit / rea

Public Imported from GitHub
0

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

fix(apktool)!: select numeric regions using Android b+ qualifiers

morluto29910d16b98f
diff --git a/docs/apktool-resource-analysis.md b/docs/apktool-resource-analysis.md
index 86f92420e..a2feff216 100644
--- a/docs/apktool-resource-analysis.md
+++ b/docs/apktool-resource-analysis.md
@@ -72,8 +72,10 @@ Equivalent MCP methods are `inspect_apktool_client` and
primary `locale` (project `res/values-<locale>/strings.xml` instead of the default
table), `locales` (repeatable array of additional localized string tables to project
from the same single decode pass), and `include_strings` (default true). Regional locales such as `pt-BR`
-select Android's `values-pt-rBR`; Android qualifiers such as `pt-rBR` and
-`b+zh+Hans+CN` may also be supplied directly.
+select Android's `values-pt-rBR`. A three-digit region such as `es-419`
+selects `values-b+es+419`; `es-r419` is rejected because Android's legacy
+`-r` form requires a two-letter region. Android qualifiers such as `pt-rBR`
+and `b+zh+Hans+CN` may also be supplied directly.
Set `string_tables_only: true` (CLI `--string-tables-only`) to return string
entries only inside `string_tables`, including when selecting a single table.
diff --git a/src/apktool/ApktoolStringTables.test.ts b/src/apktool/ApktoolStringTables.test.ts
index c77b0891d..969fc95bf 100644
--- a/src/apktool/ApktoolStringTables.test.ts
+++ b/src/apktool/ApktoolStringTables.test.ts
@@ -46,7 +46,7 @@ it("charges table-only output without reserving a duplicate primary copy", async
expect(outcome.value.coverage).toBe("complete");
});
-describe("physical Apktool string facts", () => {
+describe("Apktool locale alias table selection", () => {
it.each([false, true])(
"reads one physical table for two caller-selected aliases (table-only: %s)",
async (tablesOnly) => {
@@ -79,6 +79,42 @@ describe("physical Apktool string facts", () => {
},
);
+ it.each([
+ ["es-419", "b+es+419"],
+ ["en-001", "b+en+001"],
+ ["ar-015", "b+ar+015"],
+ ])(
+ "reads the three-digit region %s from the b+ table Apktool writes",
+ async (locale, table) => {
+ const paths: string[] = [];
+ const outcome = await projectApktoolStringTables(
+ {
+ async readText(path) {
+ paths.push(path);
+ return textRead(xml(1));
+ },
+ },
+ "decoded",
+ { include_strings: true, locale, locales: [table] },
+ );
+ if (!outcome.ok) throw outcome.error.cause;
+ const result = outcome.value;
+ expect(paths).toEqual([
+ join("decoded", "res", `values-${table}`, "strings.xml"),
+ ]);
+ expect(result.tables.map((entry) => entry.locale)).toEqual([
+ locale,
+ table,
+ ]);
+ expect(result.tables.map((entry) => entry.status)).toEqual([
+ "present",
+ "present",
+ ]);
+ },
+ );
+});
+
+describe("physical Apktool string facts", () => {
it("counts complete source entries beyond the retained table prefix", async () => {
const outcome = await projectApktoolStringTables(
{
diff --git a/src/domain/apktool/apktoolResourceAnalysis.test.ts b/src/domain/apktool/apktoolResourceAnalysis.test.ts
index 20acd6df8..4a0fb2e08 100644
--- a/src/domain/apktool/apktoolResourceAnalysis.test.ts
+++ b/src/domain/apktool/apktoolResourceAnalysis.test.ts
@@ -8,7 +8,9 @@ import {
it.each([
"de",
"pt-rBR",
- "en-r419",
+ "b+es+419",
+ "b+en+001",
+ "b+ar+015",
"b+sr+Latn",
"b+zh+Hans+CN",
"b+sr+Latn+RS+REVISED",
@@ -31,6 +33,7 @@ it.each([
"v21",
"pt-BR",
"en-419",
+ "en-r419",
"unknown_CONFIGURATION",
"",
])(
@@ -45,7 +48,10 @@ it.each([
it.each([
["pt-BR", "pt-rBR"],
- ["en-419", "en-r419"],
+ ["en-419", "b+en+419"],
+ ["en-001", "b+en+001"],
+ ["ar-015", "b+ar+015"],
+ ["fil-419", "b+fil+419"],
["pt-rBR", "pt-rBR"],
["b+zh+Hans+CN", "b+zh+Hans+CN"],
])(
@@ -56,6 +62,10 @@ it.each([
);
it.each([
+ "en-r419",
+ "es-r419",
+ "en-r001",
+ "ar-r015",
"b+fil+Latn+419+ABCDEFGH+US",
"b+sr+Latn+RS+REVISED-v21",
"../values-fr",
diff --git a/src/domain/apktool/apktoolResourceAnalysis.ts b/src/domain/apktool/apktoolResourceAnalysis.ts
index 39a236c49..59e8624f0 100644
--- a/src/domain/apktool/apktoolResourceAnalysis.ts
+++ b/src/domain/apktool/apktoolResourceAnalysis.ts
@@ -26,9 +26,10 @@ const localeQualifierSchema = z
.string()
.min(2)
.max(MAX_ANDROID_LOCALE_SUFFIX)
+ // Legacy -r regions use two letters; numeric aliases select b+ tables.
.regex(
- /^(?:[a-z]{2,3}(?:-(?:r?[A-Z]{2}|r?[0-9]{3}))?|b\+[a-z]{2,3}(?:\+[A-Za-z0-9]{2,8})*)$/u,
- "Locale must look like de, pt-BR, pt-rBR, or b+zh+Hans+CN",
+ /^(?:[a-z]{2,3}(?:-(?:r?[A-Z]{2}|[0-9]{3}))?|b\+[a-z]{2,3}(?:\+[A-Za-z0-9]{2,8})*)$/u,
+ "Locale must look like de, pt-BR, pt-rBR, es-419, or b+zh+Hans+CN",
)
.refine(
(value) => !ANDROID_NON_LOCALE_QUALIFIERS.has(value.toLowerCase()),
@@ -40,7 +41,9 @@ export const androidLocaleQualifierSchema = localeQualifierSchema;
/** Normalize an admitted request alias at the locale-selection owner. */
export const androidLocaleDirectorySuffix = (locale: string): string =>
- locale.replace(/^([a-z]{2,3})-([A-Z]{2}|[0-9]{3})$/u, "$1-r$2");
+ locale
+ .replace(/^([a-z]{2,3})-([A-Z]{2})$/u, "$1-r$2")
+ .replace(/^([a-z]{2,3})-([0-9]{3})$/u, "b+$1+$2");
/** Exact selectable table names are distinct from whole resource configurations. */
export const classifyAndroidStringsTable = (
diff --git a/tests/boundary/cli/apktoolLocaleOption.test.ts b/tests/boundary/cli/apktoolLocaleOption.test.ts
index 6b1088842..941b786cb 100644
--- a/tests/boundary/cli/apktoolLocaleOption.test.ts
+++ b/tests/boundary/cli/apktoolLocaleOption.test.ts
@@ -55,6 +55,9 @@ const OWNER_ADMITTED_LOCALES = [
"pt-rBR",
"zh-rCN",
"en-419",
+ "es-419",
+ "en-001",
+ "ar-015",
"b+zh+Hans+CN",
"b+sr+Latn+RS+REVISED",
"b+fil+Latn+419+ABCDEFGH",
@@ -127,18 +130,25 @@ it("forwards repeated --locales to project multiple localized tables", async ()
]);
});
-it("still refuses a locale the apktool input owner refuses", async () => {
- const result = await invoke([
- "decode-android-resources",
- "/targets/app.apk",
- "--locale",
- "not a locale",
- "--json",
- ]);
+it.each(["not a locale", "en-r419", "es-r419"])(
+ "refuses the invalid locale %s before invoking Apktool",
+ async (locale) => {
+ const result = await invoke([
+ "decode-android-resources",
+ "/targets/app.apk",
+ "--locale",
+ locale,
+ "--json",
+ ]);
- expect(result.exitCode).not.toBe(0);
- expect(result.requests).toEqual([]);
-});
+ expect(result.exitCode).not.toBe(0);
+ expect(result.requests).toEqual([]);
+ expect(JSON.parse(result.stdout)).toMatchObject({
+ code: "VALIDATION_ERROR",
+ fieldErrors: [expect.objectContaining({ path: "locale" })],
+ });
+ },
+);
it("forwards --no-strings with --locale preserving caller options", async () => {
const result = await invoke([
diff --git a/tests/boundary/mcp/apktoolMcp.test.ts b/tests/boundary/mcp/apktoolMcp.test.ts
index f3894782a..11da03944 100644
--- a/tests/boundary/mcp/apktoolMcp.test.ts
+++ b/tests/boundary/mcp/apktoolMcp.test.ts
@@ -4,6 +4,7 @@ import { expect, it, onTestFinished } from "vitest";
import type { ApktoolResourceAnalysisPort } from "../../../src/application/apktool/ApktoolResourceAnalysisPort.js";
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
+import type { ApktoolRequest } from "../../../src/domain/apktool/apktoolResourceAnalysis.js";
import { ok } from "../../../src/domain/result.js";
import { createServer } from "../../../src/server/createServer.js";
import { createTestBinarySession } from "../../fixtures/binarySession.js";
@@ -62,8 +63,10 @@ const results: Readonly<Record<string, unknown>> = {
};
it("advertises exact valid Apktool schemas and records inline evidence through MCP", async () => {
- const requestedLocales: (string | undefined)[] = [];
- const tableOnlySelections: (boolean | undefined)[] = [];
+ const requests: Extract<
+ ApktoolRequest,
+ { operation: "decode_android_resources" }
+ >["input"][] = [];
const provider: ApktoolResourceAnalysisPort = {
async inspectAvailability() {
return { status: "available", code: null, reason: null, diagnostics: {} };
@@ -71,8 +74,7 @@ it("advertises exact valid Apktool schemas and records inline evidence through M
async close() {},
async execute(request) {
if (request.operation === "decode_android_resources") {
- requestedLocales.push(request.input.locale);
- tableOnlySelections.push(request.input.string_tables_only);
+ requests.push(request.input);
}
return ok(createAnalysisExecution(results[request.operation], identity));
},
@@ -105,7 +107,13 @@ it("advertises exact valid Apktool schemas and records inline evidence through M
(tool) => tool.name === "decode_android_resources",
)?.inputSchema.properties?.locale;
expect(localeSchema).toMatchObject({ maxLength: 23 });
- for (const locale of ["b+sr+Latn+RS+REVISED", "b+fil+Latn+419+ABCDEFGH"]) {
+ const selectedLocales = [
+ "b+sr+Latn+RS+REVISED",
+ "b+fil+Latn+419+ABCDEFGH",
+ "es-419",
+ "b+es+419",
+ ];
+ for (const locale of selectedLocales) {
const reply = await client.callTool({
name: "decode_android_resources",
arguments: { path: "/targets/probe.apk", locale },
@@ -115,10 +123,14 @@ it("advertises exact valid Apktool schemas and records inline evidence through M
locale,
});
}
- expect(requestedLocales).toEqual([
- "b+sr+Latn+RS+REVISED",
- "b+fil+Latn+419+ABCDEFGH",
- ]);
+ expect(requests.map((request) => request.locale)).toEqual(selectedLocales);
+
+ const invalidLocale = await client.callTool({
+ name: "decode_android_resources",
+ arguments: { path: "/targets/probe.apk", locale: "es-r419" },
+ });
+ expect(invalidLocale.isError).toBe(true);
+ expect(requests).toHaveLength(selectedLocales.length);
const decoded = await client.callTool({
name: "decode_android_resources",
@@ -152,5 +164,8 @@ it("advertises exact valid Apktool schemas and records inline evidence through M
locales: ["de"],
string_tables_only: true,
});
- expect(tableOnlySelections).toEqual([undefined, undefined, undefined, true]);
+ expect(requests.at(-1)).toMatchObject({
+ locales: ["de"],
+ string_tables_only: true,
+ });
});