java-deobfuscator / deobfuscator

The real deal
https://javadeobfuscator.com
Apache License 2.0
1.56k stars 290 forks source link

Useless boolean conditions in the deobfused code #336

Closed Valyrox closed 3 years ago

Valyrox commented 5 years ago

Hello, I have no problem with the decompilation but I would like to know if there is a transformer to remove from code these useless boolean conditions (see code below) that are present everywhere in the code and in all classes. I can remove them by hand but it would take a lot of time.

public static final boolean ‌ ‍     ‍‍;

    public static Field getFieldByNameNoST(final Class<?> clazz, final String s) {
        final boolean ‌ ‍     ‍‍ = ReflectionsUtil.‌ ‍     ‍‍;
        if (!‌ ‍     ‍‍) {
            try {
                if (!‌ ‍     ‍‍) {
                    Field field;
                    if (clazz.getDeclaredField(s) != null) {
                        if (‌ ‍     ‍‍) {
                            return null;
                        }
                        field = clazz.getDeclaredField(s);
                        if (‌ ‍     ‍‍) {
                            throw null;
                        }
                    }
                    else {
                        field = clazz.getSuperclass().getDeclaredField(s);
                    }
                    final Field field2 = field;
                    field2.setAccessible(true);
                    return field2;
                }
            }
            catch (Exception ex) {
                if (!‌ ‍     ‍‍ && !‌ ‍     ‍‍) {
                    return null;
                }
            }
        }
        return null;
    }

Same (screenshot): https://i.gyazo.com/382043570b9a83bf1062edefaabf0843.png

@ThisTestUser I already use your fork. Can you give me some tips for making a transformer that would remove that kind of useless condition?

Thank you.

awesomennguy commented 5 years ago

Use field normalizer.

ThisTestUser commented 5 years ago

The implantation actually wouldn't be that hard if you understand the logic to remove it.

To start the transformer, you would go through every method of every class (classNodes()). The fake jump code always starts with GETSTATIC-ISTORE, so you'll have to check for that pattern in the code. Then, you'll have to check for ILOAD-IFNE patterns. If they exist (make sure the iload var is the same as the one in istore), remove them.

Janmm14 commented 5 years ago

or just replace the getstatic with iload_0 and use krakatau for decompilation

Valyrox commented 5 years ago

Okay, thank you all!

@ThisTestUser can I contact you privately? Thank you.

ItzSomebody commented 3 years ago

Closing since this is old plus I'm pretty sure the deobfuscator basically shreds this ever since ThisTestUser added the radon transformers.