Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] UnsupportedOperationException in addResourceFields #1645

Closed
adithya2306 opened this issue Aug 17, 2022 · 4 comments
Closed

[core] UnsupportedOperationException in addResourceFields #1645

adithya2306 opened this issue Aug 17, 2022 · 4 comments
Assignees
Labels
bug Core Issues in jadx-core module

Comments

@adithya2306
Copy link

adithya2306 commented Aug 17, 2022

Adding R class fields names to java code fails when decompiling a system apk from Android 13 (API 33).
Occurs in latest stable version (1.4.3) as well as nightly (1.4.3.63-127f0ecf).

$ jadx SystemUIGoogle.apk
INFO  - loading ...
ERROR - Failed to parse '.arsc' file
java.lang.UnsupportedOperationException: null
        at java.base/java.util.AbstractList.add(AbstractList.java:153)
        at java.base/java.util.AbstractList.add(AbstractList.java:111)
        at jadx.core.utils.android.AndroidResourcesUtils.lambda$addResourceFields$2(AndroidResourcesUtils.java:132)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
        at jadx.core.utils.android.AndroidResourcesUtils.addResourceFields(AndroidResourcesUtils.java:126)
        at jadx.core.utils.android.AndroidResourcesUtils.searchAppResClass(AndroidResourcesUtils.java:52)
        at jadx.core.dex.nodes.RootNode.processResources(RootNode.java:195)
        at jadx.core.dex.nodes.RootNode.loadResources(RootNode.java:175)
        at jadx.api.JadxDecompiler.load(JadxDecompiler.java:122)
        at jadx.cli.JadxCLI.processAndSave(JadxCLI.java:48)
        at jadx.cli.JadxCLI.execute(JadxCLI.java:36)
        at jadx.cli.JadxCLI.main(JadxCLI.java:20)
INFO  - processing ...
ERROR - finished with errors, count: 7 
$ jadx --version
1.4.3.63-127f0ecf
$ java --version
openjdk 11.0.16 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Link to the apk: https://dumps.tadiphone.dev/dumps/google/generic/-/raw/redfin-user-13-TP1A.220624.014-8819323-release-keys/system_ext/priv-app/SystemUIGoogle/SystemUIGoogle.apk

@adithya2306 adithya2306 added bug Core Issues in jadx-core module labels Aug 17, 2022
@jpstotz
Copy link
Collaborator

jpstotz commented Aug 17, 2022

The problem is that ClassNode.fields is initialized using fieldsConsumer.getResult() which can return an Collections.emptyList() which does not allow adding fields.

Changing the call in AndoridresourceUtils.addResourceFields from typeCls.getFields().add(newResField); to typeCls.addField(newResField); would be the first step and then changing ClassNode.addField to first check if the current field list is the empty singleton the second.

The question that I can not answer is: At the moment the ClassNode.fields is identical to the fieldsConsumer list, that means adding an entry to the fields list also adds it to the fieldConsumer. Is this necessary/required or can we simply assign a new list to ClassNode.fields?

I have implemented the mentioned changes here: jpstotz@fdd647d

@skylot
Copy link
Owner

skylot commented Aug 17, 2022

@jpstotz thanks for check and fix!

or can we simply assign a new list to ClassNode.fields

Sure, fieldsConsumer is a temporary object for holding results and should be GC after initial load.

Side note: I don't like using list getter for adding item, I wish java have ImmutableList interface 🙂
And in addition, I even have a weird set of methods like safeAdd to handle adding into empty immutable list. So you may found code like this: 🤣

cls.setDependencies(ListUtils.safeAdd(cls.getDependencies(), outerCls.getTopParentClass()));

@jpstotz
Copy link
Collaborator

jpstotz commented Aug 18, 2022

@skylot The PR is ready that fixes this issue. But while testing the linked APK file I noticed that it causes an StackOverflowError in jadx.api.JavaClass.getTopParentClass (happens automatically when you decompile the code).

skylot pushed a commit that referenced this issue Aug 18, 2022
* fix: UnsupportedOperationException on adding a field

* changed list check and creation similar to safeAdd
@skylot
Copy link
Owner

skylot commented Aug 18, 2022

@jpstotz thank you 👍

it causes an StackOverflowError in jadx.api.JavaClass.getTopParentClass

I commit a fix for this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

3 participants