skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.35k stars 4.85k forks source link

[core] || and && operator issues #1904

Closed redmi111 closed 1 year ago

redmi111 commented 1 year ago
```
public final void onClick(View view) {
    long uptimeMillis = SystemClock.uptimeMillis();
    this.mLastClickTime = uptimeMillis;
    if (uptimeMillis - this.mLastClickTime <= MIN_CLICK_INTERVAL || this.context == null) {
        return;
    }
    onSingleClick(view);
    Vibrator vibrator = (Vibrator) this.context.getSystemService("vibrator");
}

The above code is generated by the JADX in one APK but it was wrong (not functioning).


public final void onClick(View view) {
        long uptimeMillis = SystemClock.uptimeMillis();
        this.mLastClickTime = uptimeMillis;
        if (uptimeMillis - this.mLastClickTime <= MIN_CLICK_INTERVAL  && this.context == null) {
            return;
        }
        onSingleClick(view);
        Vibrator vibrator = (Vibrator) this.context.getSystemService("vibrator");
    }

This is the right one and functioning. 
jpstotz commented 1 year ago

Can you provide the APK file? If code does not work this could also be caused in a bug in the APK you have decompiled. So we have to check Smali code to see if || is correct or &&.

redmi111 commented 1 year ago
public final void onClick(View var1) {
        long uptimeMillis = SystemClock.uptimeMillis();
        long lastClickTime = this.mLastClickTime;
        this.mLastClickTime = uptimeMillis;
        if (uptimeMillis - lastClickTime > 250L && this.context != null) {
            this.onSingleClick(var1);

                    Vibrator var7 = (Vibrator)this.context.getSystemService("vibrator");

            }
        }

    }

    public final void onClick(View view) {
        long uptimeMillis = SystemClock.uptimeMillis();
        this.mLastClickTime = uptimeMillis;
        if (uptimeMillis - this.mLastClickTime <= MIN_CLICK_INTERVAL || this.context == null) {
            return;
        }
        onSingleClick(view);

                Vibrator vibrator = (Vibrator) this.context.getSystemService("vibrator");

        }
    }

I compared the code from fernflower(dex2jar conversion) and JADX (above fern and below jadx) the fernflower version works fine.

https://we.tl/t-VfW6ozaOm5 APK link

Check the remote button click listener inside utils package. I went back and tried JADX v1.0.0 and it decompiles fine on that version

skylot commented 1 year ago

Oh, condition operator is correct here, but jadx moved field getter after field assignment so check in condition became useless :cry: I commit a fix, so code now will be:

        long uptimeMillis = SystemClock.uptimeMillis();
        long j = uptimeMillis - this.mLastClickTime;
        this.mLastClickTime = uptimeMillis;
        if (j <= MIN_CLICK_INTERVAL || this.context == null) {
            return;
        }
        onSingleClick(view);
        ...