Skip to content

Comments

fix: avoid assumptions about res dir#4067

Merged
IgorEisberg merged 3 commits intomainfrom
fix-res-dir
Jan 14, 2026
Merged

fix: avoid assumptions about res dir#4067
IgorEisberg merged 3 commits intomainfrom
fix-res-dir

Conversation

@IgorEisberg
Copy link
Collaborator

Fixes: #3507
Fixes: #3615
Fixes: #3810

Background:
When building, res folder is the only recognized folder for resources. That is unambiguous.
That isn't true when decoding. While assets and lib are reserved names by the system, there is no requirement that file resources are all under res in an APK - they can be anywhere (even in assets and lib) and obfuscators exploit it.
The only arbiter of what is a file resource and what isn't is resources.arsc.
We already handle filtering file resources under assets and lib (only possible by an obfuscator) when decoding with resources, but we were still assuming that res/R/r were guaranteed to contain file resources only. This caused misc files in res folder to be dropped when they appeared in JARs like framework.jar, which doesn't have a resources.arsc, and thus no file resources either.

Solution:
Make no assumptions about the location of file resources at all. Paths of file resources can only be determined when decoding with resources by trusting resources.arsc. Anything that wasn't referenced in resources.arsc is inherently unknown and goes to the unknown folder to be repacked as-is.

Note:
When decoding without resources, resources.arsc is not parsed and no file resource paths are established, thus all "potential resources folders" (res, R, r or whatever) end up in unknown and will be repacked as-is.
The advantage: We no longer need to explicitly hardcode "potential resources folders" in Apktool. We trust resources.arsc only.

Extra:
Tweaked the appropriate test for this change.
Tweaked Directory to use varargs instead of explicit array for more utility.
Cleaned an unused import and some old code that isn't used anymore.

Tested on a full ROM rebuild. No diffs except framework.jar that is now decoded properly.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issues where Apktool made incorrect assumptions about resource directory locations during decoding. Previously, directories named res, R, or r were assumed to contain only file resources, which caused problems when these directories appeared in JARs without a resources.arsc file (like framework.jar).

Changes:

  • Removed hardcoded assumptions about resource directory names (RESOURCES_DIRNAMES)
  • Modified behavior to trust only resources.arsc as the source of truth for file resources
  • Refactored Directory interface to use varargs for improved utility
  • Updated test expectations to reflect new behavior where unrecognized resource directories go to unknown folder

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
brut.j.dir/src/main/java/brut/directory/Directory.java Changed method signatures to use varargs instead of explicit arrays
brut.j.dir/src/main/java/brut/directory/AbstractDirectory.java Implemented varargs methods by reordering single and multi-argument implementations
brut.apktool/apktool-lib/src/test/java/brut/androlib/AndResGuardTest.java Updated test to expect r folder contents in unknown directory when decoding without resources
brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/data/StyledString.java Removed unused import
brut.apktool/apktool-lib/src/main/java/brut/androlib/res/decoder/ResFileDecoder.java Simplified logic by removing special-case handling and always mapping input to output filenames
brut.apktool/apktool-lib/src/main/java/brut/androlib/meta/ApkInfo.java Removed RESOURCES_DIRNAMES constant and its usage in STANDARD_FILENAMES_PATTERN
brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java Removed copying of RESOURCES_DIRNAMES directories in raw resource mode
brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkBuilder.java Refactored build logic with improved file freshness checking and consolidated resource building methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@IgorEisberg IgorEisberg merged commit 7169d20 into main Jan 14, 2026
18 checks passed
@IgorEisberg IgorEisberg deleted the fix-res-dir branch January 14, 2026 12:53
iBotPeaches added a commit to iBotPeaches/apktool.org that referenced this pull request Jan 14, 2026
Copilot AI pushed a commit to EduardoA3677/Apktool that referenced this pull request Feb 4, 2026
EduardoA3677 pushed a commit to EduardoA3677/Apktool that referenced this pull request Feb 4, 2026
* Initial plan

* fix: tighten span tag parsing (iBotPeaches#4061)

* fix: avoid assumptions about res dir (iBotPeaches#4067)

* refactor: nested dex + replace --only-main-classes with -a/--all-src (iBotPeaches#4069)

* refactor: source and tests (iBotPeaches#4071)

* chore: promote -a/--all-src to a common option (iBotPeaches#4072)

* build(deps): bump com.android.tools:r8 from 8.13.17 to 8.13.19 (iBotPeaches#4064)

Bumps com.android.tools:r8 from 8.13.17 to 8.13.19.

---
updated-dependencies:
- dependency-name: com.android.tools:r8
  dependency-version: 8.13.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* minor: TextUtils hotfix (iBotPeaches#4079)

* refactor: new BinaryXmlResourceParser, ResXmlSerializer and more (iBotPeaches#4077)

* build: migrate to modern maven publish (iBotPeaches#4073)

* build: migrate to modern maven publish

* build: move to v0.36

* build: use v33 for Java 11 min

* build: skip maven on unsupported Java versions

* chore: configure codeql manually

* build: defer maven publishing till jdk11

* chore: move publising to own file

* build(deps): bump gradle/actions from 5.0.0 to 5.0.1 (iBotPeaches#4080)

Bumps [gradle/actions](https://github.com/gradle/actions) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/gradle/actions/releases)
- [Commits](gradle/actions@v5...v5.0.1)

---
updated-dependencies:
- dependency-name: gradle/actions
  dependency-version: 5.0.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: ensure proper locale in ResPrimitive (iBotPeaches#4084)

Signed-off-by: Salvo Giangreco <giangrecosalvo9@gmail.com>

* feat: support for API 36.1 (Baklava) (iBotPeaches#4082)

* feat: staged aliases support (iBotPeaches#4085)

* fix: framework parse performed twice (iBotPeaches#4086)

* fix: framework parse performed twice

* fix up dynamic references with calling pkgId

* Fix merge conflict markers in SmaliDecoder.java

* Fix compilation errors in SmaliDecoder and AaptInvoker

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Salvo Giangreco <giangrecosalvo9@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Igor Eisberg <8811086+IgorEisberg@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Connor Tumbleson <iBotPeaches@users.noreply.github.com>
Co-authored-by: Salvo Giangreco <giangrecosalvo9@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] recompiled framework.jar is not correct [BUG] Ignores res folder of framework.jar [BUG] Recompiling system jars produces strange jars

2 participants