leibnitz27 / cfr

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

Help finding option to fix up class/this reference(s) #214

Open analtevs opened 3 years ago

analtevs commented 3 years ago

I'm hunting for option(s) within CFR to clean up this example a bit:

current result:

package a.a.a.a.a.a;
import a.a.a.a.a.c;
public class a implements c {
    private final int a;
    public a(int v) {
        a v2;
        v2.a = v;
    }
    public int a() {
        a v;
        return v.a;
    }
}

desired result:

package a.a.a.a.a.a;
import a.a.a.a.a.c;
public class a implements c {
    private final int a;
    public a(int v) {
        this.a = v;
    }

    public int a() {
        return this.a;
    }
}

I'm sure its feature I've completely missed.

leibnitz27 commented 3 years ago

Hmm - shouldn't need any options for that, the class might have been obfuscated in interesting ways that hide the "this" pointer - would appreciate a look at the class file!

On Fri, 27 Nov 2020, 22:15 analtevs, notifications@github.com wrote:

I'm hunting for option(s) within CFR to clean up this example a bit:

current result:

package a.a.a.a.a.a;import a.a.a.a.a.c;public class a implements c { private final int a; public a(int v) { a v2; v2.a = v; } public int a() { a v; return v.a; } }

desired result:

package a.a.a.a.a.a;import a.a.a.a.a.c;public class a implements c { private final int a; public a(int v) { this.a = v; }

public int a() {
    return this.a;
}

}

I'm sure its feature I've completely missed.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/leibnitz27/cfr/issues/214, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFXCEHYVGATNZSKPVL4VETSSAQIRANCNFSM4UFLDP3Q .

analtevs commented 3 years ago

Here is an example from production that would produce undesirable results. If this isn't enough then I'm happy to provide the entire project through a private channel.

b.class.tar.gz

leibnitz27 commented 3 years ago

Oh haha that's hilarious.

Ok - so what's going on here is that CFR TRIES to be very very very paranoid, and not use untrustworthy metadata.

But there's one bit of metadata that people rely on so much that it will get used if it's not OBVIOUSLY lying - That's the name table.

Because reconstructing variable names, if you don't do it, is something people get very sad about.

This particular class file lies about the name of the this pointer in a way I should, but don't spot!

if you use --usenametable false then all will be well with the world. (for certain small values of 'well').

    public b(a.a.a.b.a a2) {
        this(b.a(), a2);
    }

    public b(EventLoopGroup eventLoopGroup, a.a.a.b.a a2) {
        this.ac = eventLoopGroup;
        this.ad = a2;
    }

Good find, I'll have to increase the paranoia there.