Skip to content
New issue

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

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

Already on GitHub? # to your account

Array zero #1583

Closed
timscriptov opened this issue Jul 24, 2022 · 7 comments
Closed

Array zero #1583

timscriptov opened this issue Jul 24, 2022 · 7 comments

Comments

@timscriptov
Copy link

timscriptov commented Jul 24, 2022

Decompile array error

Orig:

<array name=name">
<item>0</item>
</array>

Decompile:

<array name=name">
<item>@null</item>
</array>

It code = NulPointerException

@jpstotz
Copy link
Collaborator

jpstotz commented Jul 30, 2022

@timscriptov Can you provide a sample APK that causes this error on decompile? That would be really helpful to identify the cause.

@timscriptov
Copy link
Author

@jpstotz
Copy link
Collaborator

jpstotz commented Jul 30, 2022

Thanks, I was able to reproduce this issue, e.g. in res/values/arrays.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <array name="a_audio_modes">
        <item>MODE_NORMAL</item>
        <item>MODE_IN_COMMUNICATION</item>
        <item>MODE_IN_CALL</item>
    </array>
    <array name="a_rx_freqs1">
        <item>@null</item>
        <item>1</item>
        <item>2</item>
        <item>3</item>
        <item>4</item>
        <item>5</item>
        <item>6</item>
        <item>7</item>
        <item>8</item>
        <item>9</item>
    </array>

The same apk file decompiled with apktool creates a correct entry:

   <string-array name="a_rx_freqs1">
        <item>0</item>
        <item>1</item>

It seems like Jadx intentionally replaces 0 by @null, but I don't know why:
https://github.com/skylot/jadx/blob/master/jadx-core/src/main/java/jadx/core/xmlgen/ResXmlGen.java#L173

May be we have to blacklist/whitelist certain typeName value? For attr the current code already prevents replacement.

Testing the code with some APKs I found out that most the replacements applied to typeName="style" elements.

@skylot
Copy link
Owner

skylot commented Jul 30, 2022

@jpstotz do be honest, I also don't know why it's done this way, it was added in very old PR #201.
So if anyone knows how to correctly fix this, PR is welcome 👍🏽

@skylot skylot added bug need help Core Issues in jadx-core module resources labels Jul 30, 2022
@skylot skylot added this to the TBD milestone Jul 30, 2022
@jpstotz
Copy link
Collaborator

jpstotz commented Jul 30, 2022

@skylot Looking into the code of apktool I see three references of "@null":

In ResReferenceValue.java ResFlagsAttr.java and ResEnumAttr.java.

So my guess at the moment that we should consider at this point value.getRawValue().getDataType().
In my tests for @null replacements that seem to be reasonable I usually saw TYPE_REFERENCE as dataType value. But the array case this issue is about it was TYPE_STRING.

I will try to load more APKs to better understand when a replacement is currently applied and if it makes sense.

@MrIkso
Copy link
Contributor

MrIkso commented Jul 31, 2022

In my tests for @null replacements that seem to be reasonable I usually saw TYPE_REFERENCE as dataType value

Yes, it's true

skylot pushed a commit that referenced this issue Jul 31, 2022
@skylot
Copy link
Owner

skylot commented Jul 31, 2022

Fixed in PR #1594 by @jpstotz
Can anyone verify that issue is resolved?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

4 participants