Skip to content

fix(apktool): run Windows batch launchers through cmd.exe - #1777

Merged
morluto merged 1 commit into
mainfrom
fix/apktool-windows-batch-launcher
Oct 11, 2026
Merged

morluto merged 1 commit into
mainfrom
fix/apktool-windows-batch-launcher

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Fixes #1774.

Problem

On Windows, REA_APKTOOL_COMMAND pointed at a .bat/.cmd launcher could never start. These include Chocolatey's apktool.bat and the java -jar wrapper scripts that REA's remediation text recommends. Since the CVE-2024-27980 fix, Node refuses to run batch files without a shell and throws EINVAL. The probe then reported version_unresolved ("did not report a usable version"), which points at the launcher instead of the spawn. The decode run used REA's native Windows spawner with CRT argument quoting, which cmd.exe does not parse safely.

Change

  • New src/process/WindowsBatchCommand.ts: Ghidra's existing conservative batch call, moved out of GhidraLauncher. It builds a ComSpec-validated cmd.exe /d /e:on /v:off /s /c "…" call: no AutoRun, no delayed expansion, every token quoted. Tokens containing " % ^ ! & | < > or newlines are rejected rather than escaped.
  • Ghidra: now calls the shared helper. It keeps its GhidraLaunchError, its P0 wording and its 30,000-character limit. The existing Ghidra batch tests (exact cmd.exe argv, metacharacter rejection, ComSpec selection) pass unchanged.
  • apktool: apktoolInvocation wraps the launcher only when the platform is win32 and the path ends in .bat/.cmd. The --version probe and the apktool d decode both use it, with windowsVerbatimArguments. Native .exe launchers and POSIX run exactly as before.
  • Error reporting: a batch launcher path that cmd.exe would reinterpret now reports launcher_unsupported, which maps to the not_configured rejection code, with remediation. If REA's own decode paths contain those characters, decode returns capability_unavailable naming the cause.
  • Docs: docs/apktool-resource-analysis.md describes the Windows behavior.

Validation

  • New tests in src/apktool/ApktoolConfiguration.test.ts:
    • The exact cmd.exe invocation for a Chocolatey-style apktool.BAT, including a path with spaces.
    • Direct runs for a Windows .exe and a POSIX apktool.cmd name.
    • A metacharacter launcher reported as launcher_unsupported / not_configured before any spawn.
  • npm run test:focused on the apktool module/provider tests, the apktool CLI boundary tests, and the Ghidra launcher module/boundary tests passes (54 passed, 1 Windows-only skip). The provider tests decode with a real launcher stub on macOS.
  • npm run check:fast and npm run docs:check pass.

Not verified: a real Windows host with apktool 3.0.3 and Chocolatey's apktool.bat. I only have macOS here, so the Windows path is covered by argv-construction tests, not by an executed cmd.exe. The issue mentions other providers that use execFileOutput (for example adb). Those still run their launchers directly and are not changed here. A bare apktool resolved from PATH is also unchanged: Windows execFile does not apply PATHEXT, so a PATH-only apktool.bat still needs REA_APKTOOL_COMMAND.

🤖 Generated with Claude Code

On Windows, Node refuses to spawn .bat and .cmd files without a shell
(CVE-2024-27980), so REA_APKTOOL_COMMAND pointing at Chocolatey's
apktool.bat or a java -jar wrapper failed its version probe with EINVAL,
reported as "did not report a usable version".

Move Ghidra's conservative cmd.exe invocation (no AutoRun, no delayed
expansion, every token quoted, interpreter metacharacters rejected) into
src/process/WindowsBatchCommand.ts. Ghidra keeps its error type, wording
and length limit. apktool now uses it for both the version probe and the
decode run when the launcher is a batch file on Windows. A launcher that
cmd.exe would reinterpret reports launcher_unsupported (not_configured)
with remediation instead of version_unresolved.

Fixes #1774

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

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 ✅ Completed 2026-10-11T09:02:56.577127Z e14a3d5 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.

@morluto
morluto merged commit ae95e68 into main Oct 11, 2026
57 of 60 checks passed
@morluto
morluto deleted the fix/apktool-windows-batch-launcher branch October 11, 2026 09:16
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
morluto added a commit that referenced this pull request Oct 13, 2026
* fix(apktool): resolve Windows PATH launchers before invocation

Resolve the default launcher through the selected PATH/PATHEXT before choosing native process creation or the existing conservative cmd.exe wrapper. Reuse the resulting selection and one canonical environment for the version probe and decode.

Follow-up to the release #1693 review of #1777. Source inspected and formatted; tests, builds, check reruns and real Windows Apktool execution were skipped at maintainer request.

* fix(apktool): bound lookup and retain only selected environment

Source inspection and targeted formatting only. Tests, builds, lint, typechecks and provider workloads were not run at the user's explicit request.

* fix(apktool): use supported timeout diagnostics

Retain lookup phase through AnalysisErrorOptions diagnostics while preserving the operation and timeout identity. Source inspection and targeted formatting only; tests, checks, builds and provider workloads were skipped at the user request.

---------

Co-authored-by: morluto <[email protected]>
@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the provider: apktool Analysis provider / engine: apktool label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: apktool Analysis provider / engine: apktool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Windows: apktool launcher probe fails with spawn EINVAL when REA_APKTOOL_COMMAND points to a .cmd/.bat wrapper

2 participants