skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.73k stars 4.88k forks source link

[core] Use of static fields instead of enum constants #2 #926

Closed bagipro closed 3 years ago

bagipro commented 4 years ago

Class com.google.zxing.qrcode.decoder.ErrorCorrectionLevel

package com.google.zxing.qrcode.decoder;

/* JADX INFO: Failed to restore enum class, 'enum' modifier removed */
public final class ErrorCorrectionLevel extends java.lang.Enum<com.google.zxing.qrcode.decoder.ErrorCorrectionLevel> {
    private static final /* synthetic */ com.google.zxing.qrcode.decoder.ErrorCorrectionLevel[] $VALUES;
    private static final com.google.zxing.qrcode.decoder.ErrorCorrectionLevel[] FOR_BITS;

    /* renamed from: H */
    public static final com.google.zxing.qrcode.decoder.ErrorCorrectionLevel f976H = new com.google.zxing.qrcode.decoder.ErrorCorrectionLevel("H", 3, 2);

    /* renamed from: L */
    public static final com.google.zxing.qrcode.decoder.ErrorCorrectionLevel f977L = new com.google.zxing.qrcode.decoder.ErrorCorrectionLevel("L", 0, 1);

APK: https://drive.google.com/file/d/1ICfL4A22K-KhVkw5RwvWdLJA8111iYvG/view?usp=sharing

bagipro commented 4 years ago

Hey @skylot! I see a lot of such bugs. May you please check this one?

skylot commented 4 years ago

@sergey-wowwow this case fixed. But notice that other cases may have a different pattern, and not yet covered.

bagipro commented 4 years ago

Thanks @skylot! But there is one more issue

APK: https://drive.google.com/file/d/1XlE3s-W5H5N5RfjP_1wGtdBwk6ycYGD8/view?usp=sharing

Class androidx.constraintlayout.solver.SolverVariable

    /* renamed from: androidx.constraintlayout.solver.SolverVariable$1 */
    static /* synthetic */ class C01871 {
        static final /* synthetic */ int[] $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type = new int[androidx.constraintlayout.solver.SolverVariable.Type.values().length];

        /* JADX WARNING: Can't wrap try/catch for region: R(12:0|1|2|3|4|5|6|7|8|9|10|12) */
        /* JADX WARNING: Code restructure failed: missing block: B:13:?, code lost:
            return;
         */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0014 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001f */
        /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x002a */
        /* JADX WARNING: Missing exception handler attribute for start block: B:9:0x0035 */
        static {
            $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[androidx.constraintlayout.solver.SolverVariable.Type.UNRESTRICTED.ordinal()] = 1;
            $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[androidx.constraintlayout.solver.SolverVariable.Type.CONSTANT.ordinal()] = 2;
            $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[androidx.constraintlayout.solver.SolverVariable.Type.SLACK.ordinal()] = 3;
            $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[androidx.constraintlayout.solver.SolverVariable.Type.ERROR.ordinal()] = 4;
            $SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[androidx.constraintlayout.solver.SolverVariable.Type.UNKNOWN.ordinal()] = 5;
        }
    }
        int i = androidx.constraintlayout.solver.SolverVariable.C01871.$SwitchMap$androidx$constraintlayout$solver$SolverVariable$Type[type.ordinal()];
        if (i == 1) {

Can those enum constant be also addressed by their names, but not synthetic ints?

skylot commented 4 years ago

Can those enum constant be also addressed by their names, but not synthetic ints?

Sure, usually such arrays used to remap keys to made switch compact (packed-switch insn) and jadx can handle such cases. But here switch was replaced by if-else chain (d8 do it for small switches) so jadx missed that case. I will try to fix it. And thanks for the sample! :smiley:

bagipro commented 3 years ago

The issue is fixed

ghost commented 3 years ago

The following enum pattern is not covered. Class: p000X.EnumC10380bi (X.0bi) APK: Instagram v174.0.0.31.132

package p000X;

import java.util.Collections;
import java.util.Map;

/* JADX INFO: Failed to restore enum class, 'enum' modifier removed */
/* renamed from: X.0bi  reason: invalid class name and case insensitive filesystem */
public final class EnumC10380bi extends Enum {
    public static final Map A01 = Collections.unmodifiableMap(new C10370bh());
    public static final /* synthetic */ EnumC10380bi[] A02;
    public static final EnumC10380bi A03;
    public static final EnumC10380bi A04;
    public static final EnumC10380bi A05;
    public static final EnumC10380bi A06;
    public static final EnumC10380bi A07;
    public static final EnumC10380bi A08;
    public static final EnumC10380bi A09;
    public static final EnumC10380bi A0A;
    public static final EnumC10380bi A0B;
    public static final EnumC10380bi A0C;
    public final int A00;

    static {
        EnumC10380bi r26 = new EnumC10380bi("CONNECT", 0, 1);
        A04 = r26;
        EnumC10380bi r25 = new EnumC10380bi("CONNACK", 1, 2);
        A03 = r25;
        EnumC10380bi r24 = new EnumC10380bi("PUBLISH", 2, 3);
        A08 = r24;
        EnumC10380bi r23 = new EnumC10380bi("PUBACK", 3, 4);
        A07 = r23;
        EnumC10380bi r22 = new EnumC10380bi("PUBREC", 4, 5);
        EnumC10380bi r21 = new EnumC10380bi("PUBREL", 5, 6);
        EnumC10380bi r20 = new EnumC10380bi("PUBCOMP", 6, 7);
        EnumC10380bi r19 = new EnumC10380bi("SUBSCRIBE", 7, 8);
        A0A = r19;
        EnumC10380bi r18 = new EnumC10380bi("SUBACK", 8, 9);
        A09 = r18;
        EnumC10380bi r17 = new EnumC10380bi("UNSUBSCRIBE", 9, 10);
        A0C = r17;
        EnumC10380bi r5 = new EnumC10380bi("UNSUBACK", 10, 11);
        A0B = r5;
        EnumC10380bi r3 = new EnumC10380bi("PINGREQ", 11, 12);
        A05 = r3;
        EnumC10380bi r1 = new EnumC10380bi("PINGRESP", 12, 13);
        A06 = r1;
        A02 = new EnumC10380bi[]{r26, r25, r24, r23, r22, r21, r20, r19, r18, r17, r5, r3, r1, new EnumC10380bi("DISCONNECT", 13, 14)};
    }

    public static EnumC10380bi valueOf(String str) {
        return (EnumC10380bi) Enum.valueOf(EnumC10380bi.class, str);
    }

    public static EnumC10380bi[] values() {
        return (EnumC10380bi[]) A02.clone();
    }

    public EnumC10380bi(String str, int i, int i2) {
        this.A00 = i2;
    }
}
skylot commented 3 years ago

@enriquejr99 thanks for the report. I made a fix for your case. Issue here caused by several removed fields, so corresponding enum values are not saved and can't be used, but still appear in values arrays. For such values I made fake fields and add comment /* Fake field, exist only in values array */ so enum now looks like:

public enum EnumC07570bi {
    CONNECT(1),
    CONNACK(2),
    PUBLISH(3),
    PUBACK(4),
    /* Fake field, exist only in values array */
    PUBREC(5),
    /* Fake field, exist only in values array */
    PUBREL(6),
    /* Fake field, exist only in values array */
    PUBCOMP(7),
    SUBSCRIBE(8),
    SUBACK(9),
    UNSUBSCRIBE(10),
    UNSUBACK(11),
    PINGREQ(12),
    PINGRESP(13),
    /* Fake field, exist only in values array */
    DISCONNECT(14);

    public static final Map A01 = Collections.unmodifiableMap(new C07560bh());
    public final int A00;

    /* access modifiers changed from: public */
    EnumC07570bi(int i) {
        this.A00 = i;
    }
}
ghost commented 3 years ago

Great! Thanks.