1065 Commits

Author SHA1 Message Date
oSumAtrIX
8f166d5125
Merge branch 'upstream'
# Conflicts:
#	brut.apktool/apktool-lib/src/main/java/brut/androlib/AaptInvoker.java
#	brut.apktool/apktool-lib/src/main/java/brut/androlib/ApkDecoder.java
#	brut.apktool/apktool-lib/src/main/java/brut/androlib/res/ResourcesDecoder.java
#	brut.apktool/apktool-lib/src/test/java/brut/androlib/decode/MissingDiv9PatchTest.java
#	brut.j.util/src/main/java/brut/util/BrutIO.java
#	brut.j.util/src/main/java/brut/util/OSDetection.java
#	build.gradle.kts
2024-12-17 03:43:46 +01:00
Igor Eisberg
542b66cbd0
refactor: ExtDataInput rework, source layout and formatting (#3738)
* refactor: ExtDataInput rework, source layout and formatting

Refactor ExtDataInput classes: ExtDataInput is now the extended interface,
ExtDataInputStream is an easy-to-use FilterInputStream implementing ExtDataInput
with static creator methods for big-endian and little-endian wrappers.

Refactor AaptManager class: unify aapt-related verifications to one class.

Replace Apache Commons' deprecated CountingInputStream with Google Guava's
equivalent with the same name. Apache's BoundedInputStream is an overkill
for our use case and its constructors are deprecated as well.

Normalize source layout to have a common and somewhat more standard order:
Static fields first, instance fields after, methods last.

Fix some formatting, like empty spaces or extra spaces and exception messages.

Renamed ResXmlPatcher to ResXmlUtils, as it has more purposes than just patching.

Renamed DirUtil to DirUtils, to match other utility classes naming convention.

Moved "properties/apktool.properties" to jar's root, to match smali/baksmali.

Moved Android Framework to "prebuilt", as it is just a prebuilt, looks out of
place among .class files.

@SuppressWarnings removed from Duo as there are quite a few unsafe assignments
of raw Duo[] instances to parameterized Duo<> variables in the project, this is
just Java being the primitive boilerplate it is, no point in fighting it.

No end-user changes.
Tested against a full ROM decompile/recompile, no issues found.

* small tweak

* last refinement

* missed a stream
2024-12-11 10:55:13 -05:00
Connor Tumbleson
858c07143d
fix: set max automatic threads to 8 2024-12-01 13:50:49 -05:00
Connor Tumbleson
f85f9b3b60
feat: support for Android Baklava Developer Preview 1 (#3728) 2024-11-20 05:59:06 -05:00
Sawan Garg
1eb1daf12a
feat: add user, system certificate in existing network security config (#3724)
* add user, system certificate in existing network security config rather than creating a fresh config

* prevent deleting existing network security config to modify the existing one

* modified test case for certificate check.

Rather than comparing exact string, parse and check if user and system certificate exist
2024-11-16 19:32:24 -05:00
Igor Eisberg
c2eab3101c
refactor: tweaks IO handling (#3723)
Use BrutIO where possible to improve and simplify stream handling.
Ensure streams are closed when no longer needed.

Some minor formatting tweaks and naming consistency.

No functionality changes.
2024-11-10 08:56:47 -05:00
Igor Eisberg
e065b26641
fix: avoid trying to parse raw AndroidManifest (#3720)
Recording feature flags moved to ResourcesDecoder to fix
an issue where raw AndroidManifest is attempted to be
parsed even when decoding without resources.

Replaced remaining usages of FileInputStream/FileInputStream
with their NIO equivalents for consistency with rest of code.

Minor redundancy and format tweaks.
2024-11-08 07:35:06 -05:00
Igor Eisberg
b49e77087d
refactor: clean up external pull parser and introduce brut.j.xml (#3709)
* refactor: clean up external pull parser and introduce brut.j.xml

We have no need for an XML pull parser in the project,
it was only used for testing, which is now done with XPath.

The external xpp3 library from org.ogce is obsolete and has
the issue of including javax.xml.namespace.QName which conflicts
with the JRE implementation that exists for a very long time now.
This makes direct usages of QName produce very obscure NPEs that
took me hours to figure out. This patch will allow further
optimization that is WIP.
The external library was replaced by the basic xmlpull API.

The MXSerializer has been cleaned and the features used by apktool
have been integrated into the custom implementation, now part of
a separate module called brut.j.xml.
Writing has been optimized by buffering write operations, inspired
by KXmlSerializer used by Android itself.

A class XmlPullUtils also written that allows copying from a
XmlPullParser into a XmlSerializer with or without an EventHandler.
We use it for AndroidManifestPullStreamDecoder (with EventHandler,
to allow omitting the uses-sdk tag), and for ResXmlPullStreamDecoder
(direct copy, without EventHandler).

saveDocument in ResXmlPatcher was tweaked to output proper output -
a new line after declaration and a new line after root element's
end tag.

TL;DR mostly behind the scene refactor, no end user changes.
2024-10-15 06:54:03 -04:00
Igor Eisberg
7033f4ee2f
feat: support building with compact entries (#3708)
Pretty straightforward change. The motivation is to reproduce the original
structure of the source APK. If it's built with compact resource entries -
then rebuild with compact resource entries.
2024-10-04 09:38:45 -04:00
Igor Eisberg
24541c3943
fix: decoding APK with many compact entries and unknown uses-sdk attrs (#3705)
* fix: decoding APK with many compact entries and unknown uses-sdk attrs

This fixes 2 new issues with a stock APK sourced from an Android 15 ROM.

https://drive.google.com/file/d/1x9udLN4W5I7chyGp1ZY8Cyfhu1vXezU9/view

1) mIn.readShort() for size in readEntryData is incorrect and the size < 0 check is not possible.
   Entry size is stored by AAPT2 as an unsigned short and thus will never be negative.
   Reading it as a signed short will cause negative entry sizes in compactly packed entries in
   very large string pools and will result in a lot of "APKTOOL_DUMMYVAL_" values.

2) sdkInfo isn't stored properly for APKs with unexpected properties in uses-sdk tag.
   As far as I can tell, these attributes serve no purpose and can be ignored.
   In the given APK, additional "android:versionCode" and "android:versionName" attributes appear
   in the uses-sdk tag, purpose unknown and they don't represent the actual version of the app.

   E: uses-sdk (line=26)
     A: http://schemas.android.com/apk/res/android:minSdkVersion(0x0101020c)=35
     A: http://schemas.android.com/apk/res/android:versionCode(0x0101021b)=31
     A: http://schemas.android.com/apk/res/android:versionName(0x0101021c)="3.1"
     A: http://schemas.android.com/apk/res/android:targetSdkVersion(0x01010270)=35

* test: add assertion for issue 3705

---------

Co-authored-by: Connor Tumbleson <connor.tumbleson@gmail.com>
Co-authored-by: Connor Tumbleson <iBotPeaches@users.noreply.github.com>
2024-10-04 08:58:32 -04:00
Igor Eisberg
5c99919d94
new: featureFlags support for SDK 35 apps (#3706)
* new: featureFlags support for SDK 35 apps

This records all featureFlag attrs that were enabled when the APK was originally built.
This is now required by AAPT2 to pass these flags and their enabled/disabled state if
they are used in AndroidManifest.xml.
The flags are recorded to apktool.yml and can be configured, if so desired.
In normal usage, all flags should remain set to true (i.e. enabled).
Sample APK sourced from AOSP Android 15.

https://drive.google.com/file/d/1av7Ih7-YUXi73Hf0E3xlPv-V-nE_sXdt/view

* test: adapt testapp for featureFlag
2024-10-03 17:10:02 -04:00
Igor Eisberg
03a7c67082
clean up tab intendation (#3707) 2024-10-03 13:58:44 -04:00
Igor Eisberg
4de92a23ae
refactor: ApkDecoder & ApkBuilder overhaul (#3699)
* refactor: ApkDecoder & ApkBuilder overhaul

A major rewrite of ApkDecoder and ApkBuilder classes to make them managable.
Removed many instances of redundancy and improved syntaxed and indentation.

Modifying the stock Apktool source to our needs have become too difficult,
so I'm pushing the general (not specific to our needs) changes upstream.

I'd change a lot more, but I wanted to make sure all tests pass as expected,
despite some of them being wierd, outdated or unnecessary.

This also fixes certain files in META-INF being lost during recompile
when the -c/--copy-original option isn't used.

This has been tweaked and tested for several days and I vouch for its stablity.

* style: fix more redundancy

* style: fix more redundancy

* tweak: consistent case-sensitivity for cmd and options

* refactor: tracking unknownFiles via apkInfo is redundant

1) We take advantage of the fact that doNotCompress already tracks uncompressed files,
   including those separated into "unknown".
   With this change the "unknownFiles" is simply ignored, so it's backward-compatible
   with existing decoded APK dirs.
   Tweaked a few tests to match the removal of "unknownFiles".

2) Passing doNotCompress to AAPT is redundant, Apktool extracts the temp APK packed by
   AAPT to build/apk and then repackages it anyway, so it serves no purpose.

* refactor: fix minSdkVersion from baksmali + clean up more redundancy

* Regression: minSdkVersion inferred from baksmali was not stored properly.

* The arsc extension can be generalized for simplicity as seen in AOSP source.
https://cs.android.com/android/platform/superproject/main/+/main:external/deqp/scripts/android/build_apk.py;l=644?q=apk%20pack&ss=android%2Fplatform%2Fsuperproject%2Fmain:external%2F
  Note:
    NO_COMPRESS_EXT_PATTERN only collapses paths to a common extension.
    It does NOT force these extensions to be always uncompressed.
    doNotCompress is the one determining files/extensions that should be uncompressed.
  (no funcionality was changed)

* resourcesAreCompressed in apkInfo is redundant. It was only used in invokeAapt,
  but not ApkBuilder. Its value is also never set by Apktool, only read.
  Like with doNotCompress, passing any kind of compression rules to AAPT is pointless,
  since we don't use the temp APK packed by AAPT directly - it's extracted and repacked
  by ApkBuilder, where doNotCompress already determines whether resources.arsc should
  or should not be compressed in the final APK.
  (no funcionality was changed)

* style: optional args come after required args

* style: optional args come after required args

* style: sdkInfo as a normal field for consistency

* style: some formatting tweaks
2024-10-03 06:52:59 -04:00
Connor Tumbleson
c6bb75e540
API 35 Preview - Vanilla Ice Cream (#3696)
* fix: support API 35 as Vanilla Ice Cream

* feat: update internal framework to API 35 preview (Vanilla Ice Cream)

* chore: SDK_CUR_DEVELOPMENT is 10,000
2024-09-18 07:16:33 -04:00
Connor Tumbleson
6d1017eadf
fix: allow maven to publish without implicit task ordering (#3693) 2024-09-16 20:09:12 -04:00
dependabot[bot]
2ff81eb55f
build(deps): bump com.google.guava:guava from 32.0.1-jre to 33.3.0-jre (#3670)
* build(deps): bump com.google.guava:guava from 32.0.1-jre to 33.3.0-jre

Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.0.1-jre to 33.3.0-jre.
- [Release notes](https://github.com/google/guava/releases)
- [Commits](https://github.com/google/guava/commits)

---
updated-dependencies:
- dependency-name: com.google.guava:guava
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: fix r8 warning on RetainedWith

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Connor Tumbleson <connor.tumbleson@gmail.com>
2024-09-07 14:45:55 -04:00
Connor Tumbleson
c5dbcd6532
feat: update internal framework to API 34 (Vanilla Ice Cream) (#3681) 2024-09-03 06:45:08 -04:00
Connor Tumbleson
62ad27a561
test(aapt2) - add foregroundServiceType test (#3674) 2024-08-20 06:50:46 -04:00
Connor Tumbleson
7ad1c9f9b4
Refresh aapt2 binaries. (#3651)
* docs: align internal docs for modern aapt2 build

* build: update aapt2 with win/linux binaries

* build: update aapt2 with mac binaries
2024-08-01 08:12:29 -04:00
Aleksey
1542fd0387
Fix: add missing stream closing on manifest disassemble (#3634)
* add missing stream closing

* replace custom close with apache
2024-07-08 06:27:28 -04:00
Al Sutton
c294e014e0
Resolve a resource leak where the ZipFile is not closed (#3618)
If th zip entry for resources.arsc is not found an exception is
thrown, but the ZipFile is not closed. Using try-with-resources
means that the ZipFile will always be closed irrespective of how
the code block exits.
2024-06-11 06:42:47 -04:00
Connor Tumbleson
5c1716ffef
Workaround invalid org.xmlpull loader with R8 (#3604)
* build: move to semi-modern xmlpull version

* fix: prevent stripping invalid service loader

* fix: rework the 'release'/'publish' plan
2024-05-17 19:43:30 -04:00
Connor Tumbleson
cc501d05a5
fix: remove enforcement on aligned namespaces (#3587) 2024-05-03 06:41:40 -04:00
Connor Tumbleson
a2df2541e7
fix: properly record compression of non-main classes.dex files (#3584) 2024-04-26 07:19:43 -04:00
Pavel
6436e7c090
Correct wording in CLI usage messages (#3579)
Co-authored-by: ProgerXP <proger.xp@gmail.com>
2024-04-26 05:59:52 -04:00
Connor Tumbleson
e69ecb578d
Reproducible Builds (#3559)
* fix: remove ShadowJar plugin

 - unable to control file dates of archive entries

* refactor: use native Gradle "fatJar" method

* refactor: drop proguard for r8

* fix: wire up R8

* wip: remove fail-fast

* Revert "wip: remove fail-fast"

This reverts commit 5d005bf82e87c89efa5552ee8f8e9c0a569aea0d.

* fix: suppress unused proguard keep messages

* fix: require java11+ for r8
2024-04-07 11:45:55 -04:00
Connor Tumbleson
25826db417
feat: update internal framework to API 34 (Vanilla Ice Cream Preview) (#3537) 2024-04-01 19:51:10 -04:00
Connor Tumbleson
c784f4416e
fix: properly handle stamp-cert-sha256 (#3538) 2024-03-13 20:15:59 -04:00
oSumAtrIX
b0f3957320
Merge upstream 2024-02-14 00:18:03 +01:00
oSumAtrIX
0fd4443db7
build: Revert publishing on Jitpack 2024-02-14 00:08:44 +01:00
Connor Tumbleson
d892f3daf9
fix: remove validation on start/end tag matching (#3513) 2024-02-13 06:03:31 -05:00
Connor Tumbleson
bd82a53663
test: run path traversal test on Windows 2024-01-20 06:37:17 -05:00
Connor Tumbleson
fc8498b1d4 test: run path traversal test on Windows 2024-01-18 21:35:00 -05:00
Connor Tumbleson
0a9ec3427b
chore: correct warnings from Qodana scan (#3491) 2024-01-15 07:26:53 -05:00
Connor Tumbleson
69914eb596
refactor: inline runnable on smali disassemble (#3490) 2024-01-14 11:10:10 -05:00
Connor Tumbleson
93e7d6bdbf
Prevent arbitrary file writes with malicious resource names. (#3484)
* refactor: rename sanitize function

* fix: expose getDir

* fix: safe handling of untrusted resource names

 - fixes: GHSA-2hqv-2xv4-5h5w

* test: sample file for GHSA-2hqv-2xv4-5h5w

* refactor: avoid detection of absolute files for resource check

* chore: enable info mode on gradle

* test: skip test on windows

* chore: debug windows handling

* fix: normalize entry with file separators

* fix: normalize filepath after cleansing

* chore: Android paths are not OS specific

* refactor: use java.nio for path traversal checking

* chore: align path separator on Windows for Zip files

* chore: rework towards basic directory traversal

* chore: remove '--info' on build.yml
2024-01-05 06:28:07 -05:00
Connor Tumbleson
d348c43b24
Prevent arbitrary file writes with malicious resource names. (#3484)
* refactor: rename sanitize function

* fix: expose getDir

* fix: safe handling of untrusted resource names

 - fixes: GHSA-2hqv-2xv4-5h5w

* test: sample file for GHSA-2hqv-2xv4-5h5w

* refactor: avoid detection of absolute files for resource check

* chore: enable info mode on gradle

* test: skip test on windows

* chore: debug windows handling

* fix: normalize entry with file separators

* fix: normalize filepath after cleansing

* chore: Android paths are not OS specific

* refactor: use java.nio for path traversal checking

* chore: align path separator on Windows for Zip files

* chore: rework towards basic directory traversal

* chore: remove '--info' on build.yml
2024-01-02 06:11:03 -05:00
Connor Tumbleson
85f8de87d2
fix: deprecated is lowercase (#3481) 2023-12-26 07:22:45 -05:00
Connor Tumbleson
e56cb4f743
Support for configuring job count. (#3480)
* feat: make jobs configurable

* chore: remove unused method
2023-12-26 07:11:16 -05:00
Cregrant
81aae6936a
Feature: Parallel Building (#3476)
* perf: process smali code in parallel

Note: backsmali can't be properly multithreaded because of the synchronized methods inside

* perf: start backsmali concurrently with a resources decompiler

* perf: speed up apk building by skipping temp archive creation

Now we're not compressing the same data twice

* refactor: extract duplicated code

* refactor: rename methods and inline some comments
2023-12-26 06:20:26 -05:00
Connor Tumbleson
a9eacf657c
test: assert miui aapt1 patch exists (#3462) 2023-12-08 07:29:28 -05:00
Connor Tumbleson
a375717ade
fix: support alignment towards resTable_entry start (#3452) 2023-12-04 05:58:27 -05:00
Connor Tumbleson
72d0bc164d
#3427 - Treat manifest warnings as warnings (#3429)
* feat: treat warnings as warnings during aapt2 build

* test: add invalid fragment to manifest to confirm warning
2023-11-16 06:45:38 -05:00
Connor Tumbleson
bf1041e4fb
test: add test case for android:isAccessibilityTool (#3426)
* test: add test case for android:isAccessibilityTool

* test: augment tests for accessibility service extension
2023-11-16 05:58:38 -05:00
Connor Tumbleson
9e9079d30f
build: patch aapt2 to ignore private resources (unix/win) (#3396)
* build: patch aapt2 to ignore private resources (unix/win)

* build: patch aapt2 private resources (mac)
2023-11-08 06:30:13 -05:00
Connor Tumbleson
eec0288e69
Adapt null resource to be treated as reference instead of empty string. (#3417)
* fix: handle null resolved items as references

* test: add color null test for aapt2
2023-11-03 06:40:32 -04:00
oSumAtrIX
fc4a59fb33
Merge branch 'upstream' 2023-11-03 00:16:28 +01:00
Connor Tumbleson
247735c434
feat: de-dupe attribute names during styles writing (#3404) 2023-10-16 07:15:34 -04:00
Josh Miers
e2a5742b18
use apiLevel instead of forceApi when building the apk (#3399) 2023-10-11 19:44:00 -04:00
Connor Tumbleson
199780103c
refactor: support current position during chunk verbose output (#3395) 2023-10-10 21:23:05 -04:00