Skip to content

feat(apktool): share one APK resource decode across selected locale tables (#4777) - #4804

Merged
morluto merged 1 commit into
morluto:mainfrom
abhay-2108:feat/apktool-share-resource-decode-4777
Oct 17, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
abhay-2108:feat/apktool-share-resource-decode-4777

Conversation

@abhay-2108

@abhay-2108 abhay-2108 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Project default and multiple selected localized string tables from one immutable decode pass, eliminating redundant APK snapshotting, SHA-256 digesting, launcher version probing, repeated apktool d --no-src invocations, and workspace filesystem enumerations for multi-locale inspection.

Fixes #4777

Problem and expected behavior

Previously, inspecting multiple string tables (such as default strings and one or more translated locales like de or pt-BR) required separate serial calls to decode_android_resources. Each call created an owned temporary directory, copied and hashed the APK, executed a full apktool d --no-src decode, traversed the decoded workspace to count files and discover available locales, projected a single string table, and removed the workspace. On NewPipe (0.29.1), each decode required ~7.5–11.4s of CPU time and separate workspace lifecycle overhead.

Expected behavior: A caller can specify an array of desired locales via locales (or repeatable --locales <tag> on the CLI) in addition to or instead of the primary locale. REA runs one single decode pass, projects each requested table into a structured string_tables array with typed availability status (present, missing, oversized, malformed, skipped), coverage, and entry counts (null when skipped or unmeasured), while continuing to provide top-level strings and locale for backwards compatibility.

Change and scope

  • Added an optional locales input array to decode_android_resources schema (bounded to 20 locales).
  • Extended the output schema with string_tables: z.array(stringTableSchema).optional() containing per-table facts, typed availability status (present, missing, oversized, malformed, skipped), entry counts (null when skipped, oversized, or unmeasured), and coverage.
  • Updated ApktoolProvider to iterate through all requested locales from the single decoded workspace.
  • Enforced aggregate projection budgets: 32 MiB aggregate XML read budget (AGGREGATE_STRINGS_XML_MAX_BYTES) and 10,000 aggregate string entries budget (MAX_AGGREGATE_STRINGS). Each read receives Math.min(STRINGS_XML_MAX_BYTES, remainingXmlBudget) and tracks bytesRead even on parse failures.
  • Normalized locale directory aliases (pt-BR and pt-rBR both resolve to values-pt-rBR) so aliases reuse already-projected tables without extra disk I/O or charging the budget twice.
  • Preserved strict backwards compatibility for existing single-table and include_strings: false queries (all string tables are skipped when include_strings: false).
  • Separated XML parse failures (malformed) from valid XML containing unsupported/styled markup (present with coverage: "partial").
  • Added typed skipped status for tables skipped after aggregate budget exhaustion, reporting unknown (null) entry counts rather than invented zeros.
  • Preserved cancellation and cleanup invariants: aborted per-table reads are never swallowed as malformed tables; provider-owned workspaces are reliably unlinked in finally, with failed cleanup tracked for retry on provider close.
  • Scope: Existing static local APK decoding only. Zero target execution, process injection, or byte mutation authority. Maintainer scope decision: not applicable (within existing static provider boundary).

Contract and boundary impact

  • Semantic owner and earliest changed stage: Domain schemas in src/domain/apktool/apktoolResourceAnalysis.ts and provider projection in src/apktool/ApktoolProvider.ts.
  • Contribution scope fit and linked maintainer decision: Not applicable (within existing static apktool analysis boundaries; no new provider or mutation authority).
  • CLI and MCP/tool-catalog contract: Added repeatable --locales option to rea decode-android-resources; updated MCP contract description and examples in src/contracts/apktool/apktoolToolContracts.ts. Output schema adds optional string_tables while retaining existing strings and locale fields.
  • Provider, bridge, target-format, or platform compatibility: Cross-platform (Linux/macOS/Windows). No changes to toolchain requirements.
  • Evidence, artifact, provenance, or reconstruction contract: Retains exact Evidence provenance, subject APK digest and byte count, and inline metadata.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): Provider-owned temporary workspace created via mkdtemp and cleaned up in finally. Failed cleanup tracked in #pendingCommandOwners for retry on provider.close().
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: Regenerated and validated with npx turbo run docs:check:built. No uncommitted build artifacts.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • src/apktool/ApktoolDecodeOutput.test.ts: Added tests verifying malformed boolean distinguishing syntax errors from styled/unsupported markup (24 tests pass).
    • src/application/apktool/ApktoolResourceAnalysisService.test.ts: Added tests for invalid locale arrays, bounding caps (> 20 locales), and batched locale forwarding to provider (10 tests pass).
    • tests/boundary/cli/apktoolLocaleOption.test.ts: Added CLI tests for repeatable --locales flags and --no-strings --locale de options forwarding (4 tests pass).
    • tests/boundary/mcp/apktoolMcp.test.ts: Updated MCP boundary tests to verify advertised JSON schemas with string_tables and multi-locale execution (1 test passes).
    • src/apktool/ApktoolProvider.test.ts: Added tests verifying: (1) invocation counter asserts exactly 1 decode occurs, (2) alias deduplication reuses table for pt-BR and pt-rBR, (3) include_strings: false suppresses all string tables, (4) styled markup produces present table with partial coverage and unparsed count.
    • scripts/verify-apktool.mjs: Updated live verifier check to assert exact requested locale identities and status: "present".
  • Base reproduction or other evidence: Observed evidence in issue [Feature] Share one APK resource decode across selected locale-table reads #4777 documented 4 serial decodes taking 7.45/11.40/9.94/11.30s on NewPipe. Batching avoids 3 redundant decode passes.
  • User-visible CLI/MCP output:
    rea decode-android-resources <app.apk> --locales de --locales pt-BR --json outputs string_tables with all requested tables populated from one decode pass.
  • Remaining proof gaps: Real Apktool execution against upstream NewPipe binary was evaluated using recorded timing baselines; actual agent token count depends on caller context.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast — 2 successful, 2 total (typecheck and lint passed).
  • npx turbo run docs:check:built — 6 successful, 6 total (product catalog, skill metadata, package metadata, completion ledger, and third-party license inventory).
  • npx vitest run src/apktool/ApktoolDecodeOutput.test.ts src/application/apktool/ApktoolResourceAnalysisService.test.ts tests/boundary/cli/apktoolLocaleOption.test.ts tests/boundary/mcp/apktoolMcp.test.ts — 39 passed across 4 test suites.

Compatibility, safety, and release

  • Breaking changes or migration steps: None. Fully backward-compatible: existing single-table callers receive their expected strings and locale fields without modification.
  • Real Hopper/Ghidra, browser, or OS coverage: Validated on Windows local development environment with cross-platform Node.js filesystem semantics.
  • Package or release metadata impact: Package metadata validated via generate-package-metadata.mjs --check.
  • Security, privacy, process, or containment review: APK snapshotting to read-only copy (0o400) before decoding preserved. Workspace is created in system temporary directory with strict cleanup.

Author readiness

Human owner: @abhay-2108

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-17T13:18:07.643198Z b70acdc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new blocking issue remains.

Summary

Adds locales so one APK decode can return the primary string table and selected locale tables.

  • One decode supplies the default and selected locale tables.
  • Each locale table reports its status and coverage.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Validated locale request] --> B[Snapshot APK and decode once]
  B --> C[Count files and discover locales]
  C --> D{Include strings?}
  D -->|No| E[Return empty strings and tables]
  D -->|Yes| F[Normalize requested locale directory]
  F --> G{Table cached?}
  G -->|No| H{Read and entry budget remain?}
  H -->|No| I[Return skipped table]
  H -->|Yes| J[Read bounded XML and cache parsed result]
  G -->|Yes| K[Build table within output limit]
  J --> K
  K --> L[Return tables and primary strings]
Loading

Reviews (6) · Last reviewed commit: "feat(apktool): share one APK resource de..." · Reviewed by Greptile

Comment thread src/apktool/ApktoolProvider.ts Resolved
Comment thread src/apktool/ApktoolProvider.ts Resolved
Comment thread src/apktool/ApktoolProvider.ts Resolved
Comment thread src/apktool/ApktoolProvider.ts Resolved
Comment thread src/apktool/ApktoolProvider.ts Resolved
Comment thread scripts/verify-apktool.mjs Resolved
@abhay-2108
abhay-2108 force-pushed the feat/apktool-share-resource-decode-4777 branch from b70acdc to f6ec9d4 Compare October 17, 2026 13:32
Comment thread src/apktool/ApktoolProvider.ts Resolved
morluto added a commit that referenced this pull request Oct 17, 2026
Return tagged string-document parsing failures instead of fabricating one unparsed entry. Preserve XML failure reasons and publish unknown counts with partial coverage; count only examined unsupported entries in validated documents. Migrate every consumer, remove the superseded throwing XML wrapper, and retain completed failure Evidence through cancellation and failed cleanup.

Adapt the document-versus-entry distinction from PR #4804 using the shared Result and XML owner. Multi-table projection and its aggregate bounds remain under review in #4777.

Validation before incoming main rebase: 229 focused tests in 15 files, four baseline controls fail, static/docs checks and two source reviews. Twelve tiny actual MCP workflows and four CLI controls; authored launchers only, no real Apktool/JVM/Windows qualification.

Fixes #4820

Co-authored-by: Abhay Tiwari <[email protected]>
@abhay-2108
abhay-2108 force-pushed the feat/apktool-share-resource-decode-4777 branch 3 times, most recently from a8cfce2 to 6be3356 Compare October 17, 2026 17:47
Comment thread src/apktool/ApktoolProvider.ts Resolved
@abhay-2108
abhay-2108 force-pushed the feat/apktool-share-resource-decode-4777 branch from 6be3356 to e19ec7c Compare October 17, 2026 17:56
Comment thread src/apktool/ApktoolProvider.test.ts Resolved
…ables (morluto#4777)

Project default and multiple selected localized string tables from one
immutable decode pass. Remove the need for repeated APK snapshotting,
digesting, version probing, apktool d invocations, and workspace enumeration.

- Contract: add optional locales array to decode_android_resources input
  schema (bounded to 20 locales) and structured string_tables to output schema
  with per-table status, strings, total_count, unparsed_count, and coverage.
  Preserve legacy strings and locale fields for complete backward compatibility.
- Bounds: enforce 32 MiB aggregate XML read cap and 10,000 aggregate string
  entries cap across batched projections. Handle missing, oversized, and
  malformed tables per-table without failing or losing completed tables.
- Lifecycle: maintain strict descriptor cleanup and provider-owned workspace
  removal in finally, preserving typed cancellation and failure details.
- Adapters: add --locales repeatable option to CLI and update MCP contract.

Validation: 10 service tests, 3 CLI boundary tests, and MCP boundary schema
tests pass. Fast typecheck/lint and turbo docs:check:built pass.
Fixes morluto#4777
@morluto

morluto commented Oct 20, 2026

Copy link
Copy Markdown
Owner

I appreciate how this lets one APK decode answer several locale requests, with per-table status and aggregate limits still visible, @abhay-2108. Keeping the old single-locale response intact makes the new workflow easier to adopt. Welcome to REA.

@morluto morluto added enhancement New feature or request provider: apktool Analysis provider / engine: apktool labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request provider: apktool Analysis provider / engine: apktool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Share one APK resource decode across selected locale-table reads

2 participants