cfr icon indicating copy to clipboard operation
cfr copied to clipboard

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

Open analtevs opened this issue 4 years ago • 3 comments

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.

analtevs avatar Nov 27 '20 22:11 analtevs

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, [email protected] 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 .

leibnitz27 avatar Nov 28 '20 15:11 leibnitz27

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

analtevs avatar Nov 29 '20 01:11 analtevs

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.

leibnitz27 avatar Nov 29 '20 10:11 leibnitz27