Col-E / Recaf

The modern Java bytecode editor
https://recaf.coley.software
MIT License
5.91k stars 457 forks source link

Illegal named methods or variable names #274

Closed MizzMaster closed 3 years ago

MizzMaster commented 3 years ago

You know that there are words that we cant use while declaring a method or a variable. BUT FU***NG OBFUSCATORS CAN! I spent more than 30 hours dealing with bugs. I got mad, sorry.

If an obfuscator rename a variable with an illegal(unicode or reserved keywords), this causes Recaf suck while parsing decompiled code. If an variable name gets invisible, that means it is unicode, but if a method name gets unparseable, it means you cant even change it's name using table mode.

In my jar, there are 2 methods named "do" and "if" and maybe a lot more. I don't know if it is your job to fix this but it causes your program to cant even rename this illegal method. If you say that is not my job, i will open an issue on "Java Deobfuscator" repo.

Btw, you can run CFR with -renameillegalidents to prevent unicode bug.

andylizi commented 3 years ago

1.x versions of Recaf allowed changing all CFR options. It'd be nice if this can be supported again. Some reflection (e.g. on here) can be used to avoid the tedious work of keeping all the options up-to-date.

--renameillegalidents would solve the problem in this case.

MizzMaster commented 3 years ago

Does --renameillegalidents change the ones that use "reserved keywords"?

andylizi commented 3 years ago

$ cfr --help renameillegalidents

Rename identifiers which are not valid java identifiers. Note - this WILL break reflection based access, so is not automatically enabled.

Yes.

MizzMaster commented 3 years ago

I hope this does not break Recaf

MizzMaster commented 3 years ago

CFR just decompiles and gives us text based representation. Not all the time perfect and not all the time same, i was trying to rename that illegal metod in Recaf but i couldnt

So, CFR doesnt change the actual name, it just changes while showing you up

MizzMaster commented 3 years ago

And i forgot to mention, I was trying to rename it on "Table Mode", but when i press enter, it does nothing

andylizi commented 3 years ago

~If you just want to rename stuff, the Table view will surely work?~

Or not, I guess.


By the way, I've always find the decompile view not very helpful because any obfuscation can easily break the parser, and if that failed, the whole page is reduced to a fancy textbox. Proper IDEs and language servers have the ability to parse partial source, but I imagine that'd be hard to implement.

Col-E commented 3 years ago

Yeah, decompile mode is not intended for obfuscated code. This is stated in the docs: https://www.coley.software/Recaf/doc-edit-mode-decompile.html

I wish it could be better suited but all I can do is implement JavaParser, which is very strict and doesn't allow for small mistakes in the decompiled code. Its understandable why it is that way, but it is unfortunate.

CFR renaming is cool but would break how decompile mode context actions work.

You should change the default mode to table otherwise. Which shows fields and methods properly. If renaming doesn't work can you provide what is necessary for minimally reproducing the issue?

MizzMaster commented 3 years ago

I tried to reproduce this issue by writing a new class from scratch, it didn't happen anywhere. But I took the .class file from the jar that I was working on, and loaded it on Recaf, I couldn't rename variables using Table Mode.

If it is possible, can you give me a link that I can send this class file to you? (Maybe it's not suitable for guidelines)

Actually, if this issue coming from JUST because obfuscation, I can open an issue on Java Deobfuscator to fix that by renaming the illegal idents, or maybe there is already a transformer to do that, whatever, this caused Recaf to cant rename.

Before I sent this post, I checked if I can edit the name on assembler, I could. But i dont know if it is renamed in other classes

Col-E commented 3 years ago

Put it into a zip and drag and drop it in a comment here or dm me on discord

MizzMaster commented 3 years ago

IllegalClass.zip

Col-E commented 3 years ago

Ah the renaming failure is because they put junk data into the signature attribute and ASM crashes.

Col-E commented 3 years ago

2.8.0 should allow you to rename these things :)

It may still have some trouble with whitespace.... that's a tougher problem.

Col-E commented 3 years ago

Closing as the specific problem has been resolved.

As mentioned, whitespace names and other tricky things are on a different level.