leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
1.93k stars 249 forks source link

CFR may reverse the execution order of expression parameters of a method invocation #306

Open AIRTEspresso opened 2 years ago

AIRTEspresso commented 2 years ago

CFR version

CFR version: 0.152

Compiler

Java openJDK, version: 11.0.13

Description

Here is the third case that the code generated by CFR gave different execution results compared with the source code. It is a little similar with the first issue I submitted, but it occurred in the expression parameters of method invocations: in the source code, the invocation 'vMeth()' has two expression parameters, i.e., 'iFld1--' and '(int)(lArr[(iFld1 >>> 1)% N]^= - 13L)'. However, in the decompiled code, the second expression '(int)(lArr[(iFld1 >>> 1)% N]^= - 13L)' runs first and then 'iFld1--'. It makes a difference since 'iFld1--' changes the value of 'iFld1'. The total case is available at error example and I hope it can be helpful.

Example

The source code:

    int N = 400;
    int iFld1 = 221;
    void vMeth(int i3 , int i4){
        System.out.println("i4:" + i4);
    }
    void mainTest(){
        this.iFld1 = 540298370;
        long lArr[]= new long[N];
        init(lArr , 39L);
        vMeth(iFld1-- ,(int)(lArr[(iFld1 >>> 1)% N]^= - 13L));
        System.out.println("Test.iFld1= " + iFld1);
    }

The code decompiled by CFR:

    int N = 400;
    int iFld1 = 221;
    void vMeth(int n, int n2) {
        System.out.println("i4:" + n2);
    }
    void mainTest() {
        this.iFld1 = 540298370;
        long[] lArray = new long[this.N];
        this.init(lArray, 39L);
        int n = (this.iFld1 >>> 1) % this.N;
        long l = lArray[n] ^ 0xFFFFFFFFFFFFFFF3L;
        lArray[n] = l;
        this.vMeth(this.iFld1--, (int)l);
        System.out.println("Test.iFld1= " + this.iFld1);
    }