Apktool
Apktool copied to clipboard
[BUG] extra space added to resource value when using --use-aapt2
Information
- Apktool Version (
apktool -version) - 2.5.0 - Operating System (Mac, Linux, Windows) - Mac
- APK From? (Playstore, ROM, Other) - custom made
- there is a fix in
private String checkIfStringIsNumeric(String val)that adds "\ " to large integer values in xml. - the original issue seems to have been specifically for manifest metadata, but was added to all xml.
- using apktool with aapt1 does as was intended, and changes the value "\ 1000000000" to "1000000000".
- using apktool with aapt2 does not work as intended, and changes the value "\ 1000000000" to " 1000000000"
- the attached app tries to read the value and parse it as an integer, and crashes due to the extra space in the value.
- is there some way in apktool's code, in
checkIfStringIsNumeric, to know if it is currently running in aapt2, so that at least as some sort of workaround, it won't add the "\ "?
Stacktrace/Logcat
08-25 09:56:48.957 19389 19389 E AndroidRuntime: Caused by: java.lang.NumberFormatException: For input string: " 1000000000"
08-25 09:56:48.957 19389 19389 E AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:604)
08-25 09:56:48.957 19389 19389 E AndroidRuntime: at java.lang.Integer.parseInt(Integer.java:650)
08-25 09:56:48.957 19389 19389 E AndroidRuntime: at com.itay.apktooltest.MainActivity$MyLayout.<init>(MainActivity.java:27)```
### Steps to Reproduce
1. `apktool d ~/app-debug.apk -o ~/apktool_output --use-aapt2`
2. `apktool b ~/apktool_output -o ~/apktool.apk --use-aapt2`
### Frameworks
If this APK is from an OEM ROM (Samsung, HTC, LG). Please attach framework files
(`.apks` that live in `/system/framework` or `/system/priv-app`)
### APK
If this APK can be freely shared, please upload/attach a link to it.
[app-debug.apk.zip](https://github.com/iBotPeaches/Apktool/files/7044395/app-debug.apk.zip)
### Questions to ask before submission
1. Have you tried `apktool d`, `apktool b` without changing anything? the app works when using apktool without --use-aapt2
2. If you are trying to install a modified apk, did you resign it? yes
3. Are you using the latest apktool version? 2.5.0
this relates to: https://github.com/iBotPeaches/Apktool/issues/767
i am not even sure that the same aapt issue that was seen in the metadata also affects other xml properties. i added an xml custom property with a value of 1000000000000. run apktool d & b, signed and run the app. the property was read as it should without truncation.
this leads me to believe the addition of "\ " should be limited to the metadata, and should also be limited to aapt 1. moreover, the current solution also adds the "\ " to numbers lower than INT_MAX (and doesn't handle negative numbers at all).
also relates to https://github.com/iBotPeaches/Apktool/pull/2612 seems a change was added to master to handle the "\ " addition for the manifest specifically, but was not removed from the other XMLs. i am not completely sure, but since aapt2 doesn't remove the space added by apktool, this means that apktool will actually change values inside the app. i believe that for aapt2, the metadata should not be changed at all. but i am not that familiar with all the findings.
Stumbled upon this commit while digging AOSP and remembered this spacing ticket - https://github.com/iBotPeaches/platform_frameworks_base/commit/1d358ff5bb59f56ab19aa31d6afcf82c46b7c7bc
Unfortunately as I re-read this ticket, it isn't related.
I then looked into original issue and it seems we need to know if we are using aapt2/aapt1 during that chunk of code. So need to rethink some organization to get that known to that chunk of code.