leibnitz27 / cfr

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

If --usenametable not explicitly specified, automatically check whether or not it is useful (do the names collide?) #207

Open mateon1 opened 3 years ago

mateon1 commented 3 years ago

Problem solved by this feature

The current default behavior of CFR is to always use name tables if they exist in the jar, this is problematic for obfuscated jars which intentionally produce garbage name tables.

Feature description

CFR should have an autodetect mode, enabled by default to see whether the name tables make any sense. If a lot of the variable names of locals collide, the name table should not be used.

Considerations

This autodetection feature could be implemented either per-method, per-class, or per-run, but any solution should work. How sensitive should the autodetection be? Anywhere from "all variables have the same name" to "a pair of variable names in a method is the same", but should probably err on the sensitive side. Should the actual contents of the names be part of some heuristic? (i.e. names are all Unicode that requires \uXXXX escapes => probably garbage). If the user explicitly specifies --usenametable true, the autodetection should not run.

Alternatives

Alternatively, automatically add disambiguating suffixes for locals (possibly controled by another option).