jadx icon indicating copy to clipboard operation
jadx copied to clipboard

[feature] Can Jadx avoid inlined assignments in complicated expressions

Open DecompExplorer opened this issue 2 years ago • 1 comments

Describe your idea

Description:

Hi, I've found that Jadx sometimes generates inlined assignments in expression. Although they makes the code look more concise when the expressions are relatively straightforward, they sometimes hinder the code understandability and confuse the code readers when they appear in complicated expressions. Can Jadx alleviate it? Thank you so much.

The following code snippet is from org/apache/commons/codec/language/Soundex.java in the project commons-codec(commit: fe6dbee7524a5aa4160751155be2e8c975f66c68) :

    private char getMappingCode(final String str, final int index) {
        // map() throws IllegalArgumentException
        final char mappedChar = this.map(str.charAt(index));
        // HW rule check
        if (index > 1 && mappedChar != '0') {
            final char hwChar = str.charAt(index - 1);
            if ('H' == hwChar || 'W' == hwChar) {
                final char preHWChar = str.charAt(index - 2);
                final char firstCode = this.map(preHWChar);
                if (firstCode == mappedChar || 'H' == preHWChar || 'W' == preHWChar) {
                    return 0;
                }
            }
        }
        return mappedChar;
    }

The corresponding code generated by Jadx:

    private char getMappingCode(String str, int index) {
        char hwChar;
        char mappedChar = map(str.charAt(index));
        if (index > 1 && mappedChar != '0' && ('H' == (hwChar = str.charAt(index - 1)) || 'W' == hwChar)) {
            char preHWChar = str.charAt(index - 2);
            char firstCode = map(preHWChar);
            if (firstCode == mappedChar || 'H' == preHWChar || 'W' == preHWChar) {
                return (char) 0;
            }
        }
        return mappedChar;
    }

In this case, variable hwChar is instantiated through a rather complex manner using charAt invocation. Subsequently, although 'H' and 'W' are both compared to hwChar, they exhibit disparate formats and easily confuse developers.

The corresponding .class file can be found here

project url: https://github.com/apache/commons-codec.git commit: fe6dbee7524a5aa4160751155be2e8c975f66c68

JDK version: openjdk 17.0.5

Jadx version: jadx-dev
commit: e723c245eebee961cb1a75068e667e0c7c9d2920

DecompExplorer avatar Jan 03 '24 12:01 DecompExplorer

Hi, I was just curious if there have been any updates or advancements recently?

DecompExplorer avatar May 13 '24 08:05 DecompExplorer